From 0af201c3f4e0e5825524e82578e24d656d231329 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Sun, 2 Apr 2017 09:28:31 -0700 Subject: [PATCH 1/3] Add mypy.test.config.ALLOW_FIXTURES --- mypy/build.py | 6 ++++-- mypy/test/config.py | 3 +++ mypy/test/data.py | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index 51e82e6a85434..29caef2910c7d 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -42,6 +42,7 @@ from mypy.stats import dump_type_stats from mypy.types import Type from mypy.version import __version__ +from mypy.test.config import ALLOW_FIXTURES # We need to know the location of this file to load data, but @@ -142,8 +143,9 @@ def build(sources: List[BuildSource], # debug). This is a test-only feature, so assume our files are laid out # as in the source tree. root_dir = dirname(dirname(__file__)) - lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub')) - else: + if ALLOW_FIXTURES: + lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub')) + if not options.use_builtins_fixtures or not ALLOW_FIXTURES: for source in sources: if source.path: # Include directory of the program file in the module search path. diff --git a/mypy/test/config.py b/mypy/test/config.py index 681f86664d4a4..05a127db1536d 100644 --- a/mypy/test/config.py +++ b/mypy/test/config.py @@ -17,3 +17,6 @@ # This is *within* the tempfile.TemporaryDirectory that is chroot'ed per testcase. # It is also hard-coded in numerous places, so don't change it. test_temp_dir = 'tmp' + +# Set this to False (here in the file, not dynamically!) to disable builtins fixtures in tests +ALLOW_FIXTURES = True diff --git a/mypy/test/data.py b/mypy/test/data.py index a0573d55479c1..343da9ddb4a4e 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -12,6 +12,8 @@ from mypy.myunit import TestCase, SkipTestCaseException +from mypy.test.config import ALLOW_FIXTURES + def parse_test_cases( path: str, @@ -77,7 +79,8 @@ def parse_test_cases( # Python 2 fnam = '__builtin__.pyi' with open(mpath) as f: - files.append((join(base_path, fnam), f.read())) + if ALLOW_FIXTURES: + files.append((join(base_path, fnam), f.read())) elif p[i].id == 'stale': arg = p[i].arg if arg is None: From ec849de91e6f04e4e2d6fc3ff82a0614191a6d21 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Mon, 3 Apr 2017 14:41:16 -0700 Subject: [PATCH 2/3] Disable [file builtins.py] --- mypy/test/data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 343da9ddb4a4e..3e06608cd1c95 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -65,7 +65,8 @@ def parse_test_cases( assert arg is not None file_entry = (join(base_path, arg), '\n'.join(p[i].data)) if p[i].id == 'file': - files.append(file_entry) + if arg != 'builtins.py' or ALLOW_FIXTURES: + files.append(file_entry) elif p[i].id == 'outfile': output_files.append(file_entry) elif p[i].id in ('builtins', 'builtins_py2'): From d6e95295b5c5c570de77278f8591a5474d0027ba Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Thu, 13 Apr 2017 08:18:17 -0700 Subject: [PATCH 3/3] Move ALLOW_FIXTURES from mypy.test.config to mypy.defaults to please python 3.5 --- mypy/build.py | 2 +- mypy/defaults.py | 2 ++ mypy/test/config.py | 3 --- mypy/test/data.py | 2 +- typeshed | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index 29caef2910c7d..9835f2af2057a 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -42,7 +42,7 @@ from mypy.stats import dump_type_stats from mypy.types import Type from mypy.version import __version__ -from mypy.test.config import ALLOW_FIXTURES +from mypy.defaults import ALLOW_FIXTURES # We need to know the location of this file to load data, but diff --git a/mypy/defaults.py b/mypy/defaults.py index b5398f990d11d..d6707925ff8c4 100644 --- a/mypy/defaults.py +++ b/mypy/defaults.py @@ -2,3 +2,5 @@ PYTHON3_VERSION = (3, 6) CACHE_DIR = '.mypy_cache' CONFIG_FILE = 'mypy.ini' +# Set this to False (here in the file, not dynamically!) to disable builtins fixtures in tests +ALLOW_FIXTURES = True diff --git a/mypy/test/config.py b/mypy/test/config.py index 05a127db1536d..681f86664d4a4 100644 --- a/mypy/test/config.py +++ b/mypy/test/config.py @@ -17,6 +17,3 @@ # This is *within* the tempfile.TemporaryDirectory that is chroot'ed per testcase. # It is also hard-coded in numerous places, so don't change it. test_temp_dir = 'tmp' - -# Set this to False (here in the file, not dynamically!) to disable builtins fixtures in tests -ALLOW_FIXTURES = True diff --git a/mypy/test/data.py b/mypy/test/data.py index 3e06608cd1c95..0885af3ca2f10 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -12,7 +12,7 @@ from mypy.myunit import TestCase, SkipTestCaseException -from mypy.test.config import ALLOW_FIXTURES +from mypy.defaults import ALLOW_FIXTURES def parse_test_cases( diff --git a/typeshed b/typeshed index 1ea3d2de5794c..359c8cc313d18 160000 --- a/typeshed +++ b/typeshed @@ -1 +1 @@ -Subproject commit 1ea3d2de5794c2224a1bc086aa471d0097699bf1 +Subproject commit 359c8cc313d18e309a80548c1d4643506302a525