|
6 | 6 | from mypy.test.helpers import Suite, run_mypy
|
7 | 7 |
|
8 | 8 |
|
9 |
| -class SamplesSuite(Suite): |
10 |
| - def test_stubs(self) -> None: |
11 |
| - # We only test each module in the one version mypy prefers to find. |
12 |
| - # TODO: test stubs for other versions, especially Python 2 stubs. |
13 |
| - seen = set() # type: Set[str] |
14 |
| - modules = [] |
15 |
| - # TODO: This should also test Python 2, and pass pyversion accordingly. |
16 |
| - for version in ["2and3", "3", "3.5"]: |
17 |
| - # FIX: remove 'builtins', this directory does not exist |
18 |
| - for stub_type in ['builtins', 'stdlib', 'third_party']: |
19 |
| - stubdir = os.path.join('typeshed', stub_type, version) |
| 9 | +class TypeshedSuite(Suite): |
| 10 | + def check_stubs(self, version: str, *directories: str) -> None: |
| 11 | + if not directories: |
| 12 | + directories = (version,) |
| 13 | + for stub_type in ['stdlib', 'third_party']: |
| 14 | + for dir in directories: |
| 15 | + seen = {'__builtin__'} # we don't want to check __builtin__, as it causes problems |
| 16 | + modules = [] |
| 17 | + stubdir = os.path.join('typeshed', stub_type, dir) |
20 | 18 | for f in find_files(stubdir, suffix='.pyi'):
|
21 | 19 | module = file_to_module(f[len(stubdir) + 1:])
|
22 | 20 | if module not in seen:
|
23 | 21 | seen.add(module)
|
24 | 22 | modules.extend(['-m', module])
|
25 |
| - if modules: |
26 |
| - # these require at least 3.5 otherwise it will fail trying to import zipapp |
27 |
| - run_mypy(['--python-version=3.5'] + modules) |
28 | 23 |
|
| 24 | + if modules: |
| 25 | + run_mypy(['--python-version={}'.format(version)] + modules) |
| 26 | + |
| 27 | + def test_2(self) -> None: |
| 28 | + self.check_stubs("2.7", "2", "2and3") |
| 29 | + |
| 30 | + def test_3(self) -> None: |
| 31 | + sys_ver_str = '.'.join(map(str, sys.version_info[:2])) |
| 32 | + self.check_stubs(sys_ver_str, "3", "2and3") |
| 33 | + |
| 34 | + def test_34(self) -> None: |
| 35 | + self.check_stubs("3.4") |
| 36 | + |
| 37 | + def test_35(self) -> None: |
| 38 | + self.check_stubs("3.5") |
| 39 | + |
| 40 | + def test_36(self) -> None: |
| 41 | + self.check_stubs("3.6") |
| 42 | + |
| 43 | + def test_37(self) -> None: |
| 44 | + self.check_stubs("3.7") |
| 45 | + |
| 46 | + |
| 47 | +class SamplesSuite(Suite): |
29 | 48 | def test_samples(self) -> None:
|
30 | 49 | for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'):
|
31 | 50 | mypy_args = ['--no-strict-optional']
|
|
0 commit comments