Skip to content

Commit 0583738

Browse files
Add a mypy self test (#4337)
Co-authored-by: Shantanu <[email protected]> Co-authored-by: hauntsaninja <>
1 parent 820cc11 commit 0583738

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ jobs:
7575
- uses: actions/setup-python@v2
7676
- run: ./tests/mypy_selftest.py
7777

78+
mypy-test-suite:
79+
name: Run the mypy test suite
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v2
83+
- uses: actions/setup-python@v2
84+
- run: ./tests/mypy_test_suite.py
85+
7886
stubtest:
7987
name: Check stubs with stubtest
8088
runs-on: ${{ matrix.os }}

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ There are several tests:
101101
runs tests against [mypy](https://github.com/python/mypy/)
102102
- `tests/pytype_test.py` runs tests against
103103
[pytype](https://github.com/google/pytype/).
104-
- `tests/mypy_selftest.py` runs mypy's test suite using this version of
104+
- `tests/mypy_selftest.py` checks mypy's code base using this version of
105+
typeshed.
106+
- `tests/mypy_test_suite.py` runs mypy's test suite using this version of
105107
typeshed.
106108
- `tests/check_consistent.py` checks certain files in typeshed remain
107109
consistent with each other.
@@ -156,6 +158,13 @@ This test works similarly to `mypy_test.py`, except it uses `pytype`.
156158
This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
157159
Run using: `(.venv3)$ python3 tests/mypy_selftest.py`
158160

161+
This test checks mypy's code base using mypy and typeshed code in this repo.
162+
163+
### mypy_test_suite.py
164+
165+
This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
166+
Run using: `(.venv3)$ python3 tests/mypy_test_suite.py`
167+
159168
This test runs mypy's own test suite using the typeshed code in your repo. This
160169
will sometimes catch issues with incorrectly typed stubs, but is much slower
161170
than the other tests.

tests/mypy_selftest.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
#!/usr/bin/env python3
2-
"""Script to run mypy's test suite against this version of typeshed."""
2+
"""Script to run mypy against its own code base."""
33

44
from pathlib import Path
5-
import shutil
65
import subprocess
76
import sys
87
import tempfile
98

9+
MYPY_VERSION = "0.790"
1010

11-
if __name__ == '__main__':
11+
12+
if __name__ == "__main__":
1213
with tempfile.TemporaryDirectory() as tempdir:
1314
dirpath = Path(tempdir)
14-
subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True)
15-
subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy',
16-
str(dirpath / 'mypy')], check=True)
17-
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r',
18-
str(dirpath / 'mypy/test-requirements.txt')], check=True)
19-
shutil.copytree('stdlib', str(dirpath / 'mypy/mypy/typeshed/stdlib'))
20-
shutil.copytree('third_party', str(dirpath / 'mypy/mypy/typeshed/third_party'))
15+
subprocess.run(
16+
["git", "clone", "--depth", "1", "git://github.com/python/mypy", str(dirpath)],
17+
check=True,
18+
)
2119
try:
22-
subprocess.run(['pytest', '-n12'], cwd=str(dirpath / 'mypy'), check=True)
20+
subprocess.run([sys.executable, "-m", "pip", "install", f"mypy=={MYPY_VERSION}"], check=True)
21+
subprocess.run([sys.executable, "-m", "pip", "install", "-r", dirpath / "test-requirements.txt"], check=True)
22+
subprocess.run(
23+
[
24+
"mypy",
25+
"--config-file",
26+
dirpath / "mypy_self_check.ini",
27+
"--custom-typeshed-dir",
28+
".",
29+
dirpath / "mypy",
30+
dirpath / "mypyc",
31+
],
32+
check=True,
33+
)
2334
except subprocess.CalledProcessError as e:
24-
print('mypy tests failed', file=sys.stderr)
35+
print("mypy self test failed", file=sys.stderr)
2536
sys.exit(e.returncode)
2637
else:
27-
print('mypy tests succeeded', file=sys.stderr)
38+
print("mypy self test succeeded", file=sys.stderr)
2839
sys.exit(0)

tests/mypy_test_suite.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
"""Script to run mypy's test suite against this version of typeshed."""
3+
4+
from pathlib import Path
5+
import shutil
6+
import subprocess
7+
import sys
8+
import tempfile
9+
10+
11+
if __name__ == '__main__':
12+
with tempfile.TemporaryDirectory() as tempdir:
13+
dirpath = Path(tempdir)
14+
subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True)
15+
subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy',
16+
str(dirpath / 'mypy')], check=True)
17+
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r',
18+
str(dirpath / 'mypy/test-requirements.txt')], check=True)
19+
shutil.copytree('stdlib', str(dirpath / 'mypy/mypy/typeshed/stdlib'))
20+
shutil.copytree('third_party', str(dirpath / 'mypy/mypy/typeshed/third_party'))
21+
try:
22+
subprocess.run(['pytest', '-n12'], cwd=str(dirpath / 'mypy'), check=True)
23+
except subprocess.CalledProcessError as e:
24+
print('mypy tests failed', file=sys.stderr)
25+
sys.exit(e.returncode)
26+
else:
27+
print('mypy tests succeeded', file=sys.stderr)
28+
sys.exit(0)

0 commit comments

Comments
 (0)