From 81c322bd6b1f7da44110d29b5595c0766f9fecd9 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 11 Feb 2021 16:26:55 +0000 Subject: [PATCH 1/3] 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. --- mypy/test/test_find_sources.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mypy/test/test_find_sources.py b/mypy/test/test_find_sources.py index 056ddf13b108..2f223bab0126 100644 --- a/mypy/test/test_find_sources.py +++ b/mypy/test/test_find_sources.py @@ -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 @@ -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)) From a9adb8ce5023079ab5c3b7549a086e64e4eb495f Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 11 Feb 2021 17:05:48 +0000 Subject: [PATCH 2/3] Attempt to fix tests on Window --- mypy/test/test_find_sources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/test/test_find_sources.py b/mypy/test/test_find_sources.py index 2f223bab0126..97c1c513307b 100644 --- a/mypy/test/test_find_sources.py +++ b/mypy/test/test_find_sources.py @@ -13,7 +13,7 @@ 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) + return os.path.join(os.sep, 'fakeroot', f).replace('/', os.sep) class FakeFSCache(FileSystemCache): From fedfeec6d2c13317f6a7f914d5cd99f8a2f04637 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 11 Feb 2021 17:42:46 +0000 Subject: [PATCH 3/3] Try a different approach (no Windows available for debugging right now...) --- mypy/test/test_find_sources.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/mypy/test/test_find_sources.py b/mypy/test/test_find_sources.py index 97c1c513307b..6d66a28f4e2d 100644 --- a/mypy/test/test_find_sources.py +++ b/mypy/test/test_find_sources.py @@ -1,24 +1,20 @@ -from mypy.modulefinder import BuildSource import os import pytest +import shutil +import tempfile import unittest from typing import List, Optional, Set, Tuple + from mypy.find_sources import InvalidSourceList, SourceFinder, create_source_list from mypy.fscache import FileSystemCache from mypy.modulefinder import BuildSource 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).replace('/', os.sep) +from mypy.modulefinder import BuildSource class FakeFSCache(FileSystemCache): def __init__(self, files: Set[str]) -> None: - self.files = {make_abs(f) for f in files} + self.files = {os.path.abspath(f) for f in files} def isfile(self, file: str) -> bool: return file in self.files @@ -56,17 +52,26 @@ 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(make_abs(f))) + return normalise_build_source_list(finder.find_sources_in_dir(os.path.abspath(f))) def find_sources( paths: List[str], options: Options, fscache: FileSystemCache ) -> List[Tuple[str, Optional[str]]]: - paths = [make_abs(p) for p in paths] + paths = [os.path.abspath(p) for p in paths] return normalise_build_source_list(create_source_list(paths, options, fscache)) class SourceFinderSuite(unittest.TestCase): + def setUp(self) -> None: + self.tempdir = tempfile.mkdtemp() + self.oldcwd = os.getcwd() + os.chdir(self.tempdir) + + def tearDown(self) -> None: + os.chdir(self.oldcwd) + shutil.rmtree(self.tempdir) + def test_crawl_no_namespace(self) -> None: options = Options() options.namespace_packages = False