8000 Fix test_find_sources when run under site-packages by JukkaL · Pull Request #10075 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix test_find_sources when run under site-packages #10075

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix test_find_sources when run under site-packages
This was failing during wheel builds because we run the tests after
installation (under `site-packages`), and this confused the module
search logic. Hard code the paths to make this work in any install
location.
  • Loading branch information
JukkaL committed Feb 11, 2021
commit 81c322bd6b1f7da44110d29b5595c0766f9fecd9
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
0