Skip to content

Add a mypy self test #4337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ jobs:
- uses: actions/setup-python@v2
- run: ./tests/mypy_selftest.py

mypy-test-suite:
name: Run the mypy test suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: ./tests/mypy_test_suite.py

stubtest:
name: Check stubs with stubtest
runs-on: ${{ matrix.os }}
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ There are several tests:
runs tests against [mypy](https://github.com/python/mypy/)
- `tests/pytype_test.py` runs tests against
[pytype](https://github.com/google/pytype/).
- `tests/mypy_selftest.py` runs mypy's test suite using this version of
- `tests/mypy_selftest.py` checks mypy's code base using this version of
typeshed.
- `tests/mypy_test_suite.py` runs mypy's test suite using this version of
typeshed.
- `tests/check_consistent.py` checks certain files in typeshed remain
consistent with each other.
Expand Down Expand Up @@ -156,6 +158,13 @@ This test works similarly to `mypy_test.py`, except it uses `pytype`.
This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
Run using: `(.venv3)$ python3 tests/mypy_selftest.py`

This test checks mypy's code base using mypy and typeshed code in this repo.

### mypy_test_suite.py

This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
Run using: `(.venv3)$ python3 tests/mypy_test_suite.py`

This test runs mypy's own test suite using the typeshed code in your repo. This
will sometimes catch issues with incorrectly typed stubs, but is much slower
than the other tests.
Expand Down
37 changes: 24 additions & 13 deletions tests/mypy_selftest.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
#!/usr/bin/env python3
"""Script to run mypy's test suite against this version of typeshed."""
"""Script to run mypy against its own code base."""

from pathlib import Path
import shutil
import subprocess
import sys
import tempfile

MYPY_VERSION = "0.790"

if __name__ == '__main__':

if __name__ == "__main__":
with tempfile.TemporaryDirectory() as tempdir:
dirpath = Path(tempdir)
subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True)
subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy',
str(dirpath / 'mypy')], check=True)
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r',
str(dirpath / 'mypy/test-requirements.txt')], check=True)
shutil.copytree('stdlib', str(dirpath / 'mypy/mypy/typeshed/stdlib'))
shutil.copytree('third_party', str(dirpath / 'mypy/mypy/typeshed/third_party'))
subprocess.run(
["git", "clone", "--depth", "1", "git://github.com/python/mypy", str(dirpath)],
check=True,
)
try:
subprocess.run(['pytest', '-n12'], cwd=str(dirpath / 'mypy'), check=True)
subprocess.run([sys.executable, "-m", "pip", "install", f"mypy=={MYPY_VERSION}"], check=True)
subprocess.run([sys.executable, "-m", "pip", "install", "-r", dirpath / "test-requirements.txt"], check=True)
subprocess.run(
[
"mypy",
"--config-file",
dirpath / "mypy_self_check.ini",
"--custom-typeshed-dir",
".",
dirpath / "mypy",
dirpath / "mypyc",
],
check=True,
)
except subprocess.CalledProcessError as e:
print('mypy tests failed', file=sys.stderr)
print("mypy self test failed", file=sys.stderr)
sys.exit(e.returncode)
else:
print('mypy tests succeeded', file=sys.stderr)
print("mypy self test succeeded", file=sys.stderr)
sys.exit(0)
28 changes: 28 additions & 0 deletions tests/mypy_test_suite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""Script to run mypy's test suite against this version of typeshed."""

from pathlib import Path
import shutil
import subprocess
import sys
import tempfile


if __name__ == '__main__':
with tempfile.TemporaryDirectory() as tempdir:
dirpath = Path(tempdir)
subprocess.run(['python2.7', '-m', 'pip', 'install', '--user', 'typing'], check=True)
subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy',
str(dirpath / 'mypy')], check=True)
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r',
str(dirpath / 'mypy/test-requirements.txt')], check=True)
shutil.copytree('stdlib', str(dirpath / 'mypy/mypy/typeshed/stdlib'))
shutil.copytree('third_party', str(dirpath / 'mypy/mypy/typeshed/third_party'))
try:
subprocess.run(['pytest', '-n12'], cwd=str(dirpath / 'mypy'), check=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be -n auto?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved this file from the old mypy_selftest.py. I'd consider changes to it out of scope of this PR.

except subprocess.CalledProcessError as e:
print('mypy tests failed', file=sys.stderr)
sys.exit(e.returncode)
else:
print('mypy tests succeeded', file=sys.stderr)
sys.exit(0)