From 5766917636883a758782c2e349bf59ee41584274 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 15 May 2018 08:05:04 -0400 Subject: [PATCH 1/6] Improve stub testing to cover all of typeshed --- runtests.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/runtests.py b/runtests.py index ca2edfc0d1a51..87dac67fb6621 100755 --- a/runtests.py +++ b/runtests.py @@ -177,20 +177,28 @@ def add_pytest(driver: Driver) -> None: def add_stubs(driver: Driver) -> None: - # We only test each module in the one version mypy prefers to find. - # TODO: test stubs for other versions, especially Python 2 stubs. - - modules = {'typing'} - # TODO: This should also test Python 2, and pass pyversion accordingly. - for version in ["2and3", "3", "3.3", "3.4", "3.5"]: - for stub_type in ['builtins', 'stdlib', 'third_party']: - stubdir = join('typeshed', stub_type, version) + def check_stubs(version: str, name: str = None) -> None: + if name is None: + name = version + modules = {'typing', '__builtin__', 'builtins'} + for stub_type in ['stdlib', 'third_party']: + stubdir = join('typeshed', stub_type, name) for f in find_files(stubdir, suffix='.pyi'): module = file_to_module(f[len(stubdir) + 1:]) modules.add(module) - - # these require at least 3.5 otherwise it will fail trying to import zipapp - driver.add_mypy_modules('stubs', sorted(modules), extra_args=['--python-version=3.5']) + modules.remove('__builtin__') + modules.remove('builtins') + if version == "3": + version = "3.3" + driver.add_mypy_modules('stubs Python {}'.format(name), sorted(modules), + extra_args=['--python-version={}'.format(version)]) + + for version in ["3.3", "3.4", "3.5", "3.6", "3.7"]: + check_stubs(version) + sys_ver_str = '.'.join(map(str, sys.version_info[:2])) + check_stubs(sys_ver_str, name="2and3") + check_stubs("2.7", name="2") + check_stubs("3") def add_stdlibsamples(driver: Driver) -> None: From 3255dbf8d617822331790e9d8b2ea2172ebb8536 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 15 May 2018 09:18:32 -0400 Subject: [PATCH 2/6] Add Python 2 checks for 2and3 --- runtests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtests.py b/runtests.py index 87dac67fb6621..234dc0ce9ad1f 100755 --- a/runtests.py +++ b/runtests.py @@ -196,7 +196,8 @@ def check_stubs(version: str, name: str = None) -> None: for version in ["3.3", "3.4", "3.5", "3.6", "3.7"]: check_stubs(version) sys_ver_str = '.'.join(map(str, sys.version_info[:2])) - check_stubs(sys_ver_str, name="2and3") + check_stubs(sys_ver_str, name="2and3-3.x") + check_stubs("2.7", name="2and3-2.7") check_stubs("2.7", name="2") check_stubs("3") From 9a62f80e089cb5fc08d58c0c7244e093ba838e12 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 26 Jun 2018 07:43:26 -0400 Subject: [PATCH 3/6] Check all stubs in typeshed v2 --- mypy/test/testsamples.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mypy/test/testsamples.py b/mypy/test/testsamples.py index bae2a68b48aa5..a793979fc8fd0 100644 --- a/mypy/test/testsamples.py +++ b/mypy/test/testsamples.py @@ -8,23 +8,30 @@ class SamplesSuite(Suite): def test_stubs(self) -> None: - # We only test each module in the one version mypy prefers to find. - # TODO: test stubs for other versions, especially Python 2 stubs. - seen = set() # type: Set[str] - modules = [] - # TODO: This should also test Python 2, and pass pyversion accordingly. - for version in ["2and3", "3", "3.5"]: - # FIX: remove 'builtins', this directory does not exist - for stub_type in ['builtins', 'stdlib', 'third_party']: - stubdir = os.path.join('typeshed', stub_type, version) + def check_stubs(version: str, name: str = None) -> None: + if name is None: + name = version + seen = set() + modules = [] + for stub_type in ['stdlib', 'third_party']: + stubdir = os.path.join('typeshed', stub_type, name) for f in find_files(stubdir, suffix='.pyi'): module = file_to_module(f[len(stubdir) + 1:]) if module not in seen: seen.add(module) modules.extend(['-m', module]) - if modules: - # these require at least 3.5 otherwise it will fail trying to import zipapp - run_mypy(['--python-version=3.5'] + modules) + if version == "3": + version = "3.4" + if modules: + run_mypy(['--python-version={}'.format(version)] + modules) + + for version in ["3.4", "3.5", "3.6", "3.7"]: + check_stubs(version) + sys_ver_str = '.'.join(map(str, sys.version_info[:2])) + check_stubs(sys_ver_str, name="2and3") + check_stubs("2.7", name="2and3") + check_stubs("2.7", name="2") + check_stubs("3") def test_samples(self) -> None: for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'): From 31266e19b5f8eb8790208a179ffbefc4a7257072 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 26 Jun 2018 07:59:57 -0400 Subject: [PATCH 4/6] Even better version --- mypy/test/testsamples.py | 70 +++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/mypy/test/testsamples.py b/mypy/test/testsamples.py index a793979fc8fd0..ee973ab4d310b 100644 --- a/mypy/test/testsamples.py +++ b/mypy/test/testsamples.py @@ -1,38 +1,56 @@ """Self check mypy package""" import sys import os.path -from typing import List, Set +from typing import List, Optional, Set from mypy.test.helpers import Suite, run_mypy +class TypeshedSuite(Suite): + def check_stubs(self, version: str, name: Optional[str] = None) -> None: + if name is None: + name = version + seen = {'__builtin__',} + modules = ['__builtin__'] + for stub_type in ['stdlib', 'third_party']: + stubdir = os.path.join('typeshed', stub_type, name) + for f in find_files(stubdir, suffix='.pyi'): + module = file_to_module(f[len(stubdir) + 1:]) + if module not in seen: + seen.add(module) + modules.extend(['-m', module]) + if version == "3": + version = "3.4" + if modules: + modules.remove('__builtin__') + run_mypy(['--python-version={}'.format(version)] + modules) -class SamplesSuite(Suite): - def test_stubs(self) -> None: - def check_stubs(version: str, name: str = None) -> None: - if name is None: - name = version - seen = set() - modules = [] - for stub_type in ['stdlib', 'third_party']: - stubdir = os.path.join('typeshed', stub_type, name) - for f in find_files(stubdir, suffix='.pyi'): - module = file_to_module(f[len(stubdir) + 1:]) - if module not in seen: - seen.add(module) - modules.extend(['-m', module]) - if version == "3": - version = "3.4" - if modules: - run_mypy(['--python-version={}'.format(version)] + modules) - - for version in ["3.4", "3.5", "3.6", "3.7"]: - check_stubs(version) + def test_2(self) -> None: + self.check_stubs("2.7", name="2") + + def test_2and3_2(self) -> None: + self.check_stubs("2.7", name="2and3") + + def test_2and3_3(self) -> None: sys_ver_str = '.'.join(map(str, sys.version_info[:2])) - check_stubs(sys_ver_str, name="2and3") - check_stubs("2.7", name="2and3") - check_stubs("2.7", name="2") - check_stubs("3") + self.check_stubs(sys_ver_str, name="2and3") + + def test_3(self) -> None: + self.check_stubs("3") + + def test_34(self) -> None: + self.check_stubs("3.4") + def test_35(self) -> None: + self.check_stubs("3.5") + + def test_36(self) -> None: + self.check_stubs("3.6") + + def test_37(self) -> None: + self.check_stubs("3.7") + + +class SamplesSuite(Suite): def test_samples(self) -> None: for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'): mypy_args = ['--no-strict-optional'] From b115f51971fbe546529b507960b89c461d9def0e Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 26 Jun 2018 08:19:51 -0400 Subject: [PATCH 5/6] Fix lint --- mypy/test/testsamples.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mypy/test/testsamples.py b/mypy/test/testsamples.py index ee973ab4d310b..574dd64964cc0 100644 --- a/mypy/test/testsamples.py +++ b/mypy/test/testsamples.py @@ -5,11 +5,12 @@ from mypy.test.helpers import Suite, run_mypy + class TypeshedSuite(Suite): def check_stubs(self, version: str, name: Optional[str] = None) -> None: if name is None: name = version - seen = {'__builtin__',} + seen = {'__builtin__', } modules = ['__builtin__'] for stub_type in ['stdlib', 'third_party']: stubdir = os.path.join('typeshed', stub_type, name) @@ -26,14 +27,14 @@ def check_stubs(self, version: str, name: Optional[str] = None) -> None: def test_2(self) -> None: self.check_stubs("2.7", name="2") - + def test_2and3_2(self) -> None: self.check_stubs("2.7", name="2and3") - + def test_2and3_3(self) -> None: sys_ver_str = '.'.join(map(str, sys.version_info[:2])) self.check_stubs(sys_ver_str, name="2and3") - + def test_3(self) -> None: self.check_stubs("3") @@ -45,7 +46,7 @@ def test_35(self) -> None: def test_36(self) -> None: self.check_stubs("3.6") - + def test_37(self) -> None: self.check_stubs("3.7") From a30dc061c04ac2f38ecd9a5d72345b57939df01b Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 19 Jul 2018 12:48:04 -0700 Subject: [PATCH 6/6] Respond to review --- mypy/test/testsamples.py | 45 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/mypy/test/testsamples.py b/mypy/test/testsamples.py index 574dd64964cc0..efcfd62f4cca7 100644 --- a/mypy/test/testsamples.py +++ b/mypy/test/testsamples.py @@ -1,42 +1,35 @@ """Self check mypy package""" import sys import os.path -from typing import List, Optional, Set +from typing import List, Set from mypy.test.helpers import Suite, run_mypy class TypeshedSuite(Suite): - def check_stubs(self, version: str, name: Optional[str] = None) -> None: - if name is None: - name = version - seen = {'__builtin__', } - modules = ['__builtin__'] + def check_stubs(self, version: str, *directories: str) -> None: + if not directories: + directories = (version,) for stub_type in ['stdlib', 'third_party']: - stubdir = os.path.join('typeshed', stub_type, name) - for f in find_files(stubdir, suffix='.pyi'): - module = file_to_module(f[len(stubdir) + 1:]) - if module not in seen: - seen.add(module) - modules.extend(['-m', module]) - if version == "3": - version = "3.4" - if modules: - modules.remove('__builtin__') - run_mypy(['--python-version={}'.format(version)] + modules) + for dir in directories: + seen = {'__builtin__'} # we don't want to check __builtin__, as it causes problems + modules = [] + stubdir = os.path.join('typeshed', stub_type, dir) + for f in find_files(stubdir, suffix='.pyi'): + module = file_to_module(f[len(stubdir) + 1:]) + if module not in seen: + seen.add(module) + modules.extend(['-m', module]) + + if modules: + run_mypy(['--python-version={}'.format(version)] + modules) def test_2(self) -> None: - self.check_stubs("2.7", name="2") - - def test_2and3_2(self) -> None: - self.check_stubs("2.7", name="2and3") - - def test_2and3_3(self) -> None: - sys_ver_str = '.'.join(map(str, sys.version_info[:2])) - self.check_stubs(sys_ver_str, name="2and3") + self.check_stubs("2.7", "2", "2and3") def test_3(self) -> None: - self.check_stubs("3") + sys_ver_str = '.'.join(map(str, sys.version_info[:2])) + self.check_stubs(sys_ver_str, "3", "2and3") def test_34(self) -> None: self.check_stubs("3.4")