Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_find_sources when run under site-packages #10075

Merged
merged 3 commits into from
Feb 11, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
from mypy.options import Options


def make_abs(f: str) -> str:
"""Turn f into an absolute fake path deterministically."""
# We don't want to depend on the current working directory, so no
# os.path.abspath.
return os.path.join(os.sep, 'fakeroot', f)


class FakeFSCache(FileSystemCache):
def __init__(self, files: Set[str]) -> None:
self.files = {os.path.abspath(f) for f in files}
self.files = {make_abs(f) for f in files}

def isfile(self, file: str) -> bool:
return file in self.files
Expand Down Expand Up @@ -49,13 +56,13 @@ def crawl(finder: SourceFinder, f: str) -> Tuple[str, str]:


def find_sources_in_dir(finder: SourceFinder, f: str) -> List[Tuple[str, Optional[str]]]:
return normalise_build_source_list(finder.find_sources_in_dir(os.path.abspath(f)))
return normalise_build_source_list(finder.find_sources_in_dir(make_abs(f)))


def find_sources(
paths: List[str], options: Options, fscache: FileSystemCache
) -> List[Tuple[str, Optional[str]]]:
paths = [os.path.abspath(p) for p in paths]
paths = [make_abs(p) for p in paths]
return normalise_build_source_list(create_source_list(paths, options, fscache))


Expand Down