Skip to content
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ matrix:
include:
- python: "3.6-dev"
env: TEST_CMD="flake8"
- python: "3.6"
env: TEST_CMD="./tests/mypy_selftest.py"
- python: "3.5"
env: TEST_CMD="./tests/mypy_test.py"
- python: "2.7"
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ requests.
## Running the tests

The tests are automatically run by Travis CI on every PR and push to
the repo. There are two separate sets of tests: `tests/mypy_test.py`
the repo. There are several sets of tests: `tests/mypy_test.py`
runs tests against [mypy](https://github.com/python/mypy/), while
`tests/pytype_tests.py` runs tests against
[pytype](https://github.com/google/pytype/).
Expand All @@ -87,8 +87,14 @@ imported but they don't check whether stubs match their implementation
that each set of tests has a blacklist of modules that are not tested
at all. The blacklists also live in the tests directory.

In addition, you can run `tests/mypy_selftest.py` to run 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.

To manually run the mypy tests, you need to have Python 3.5 or higher;
Python 3.6.1 or higher is recommended.

Run:
```
$ python3.6 -m venv .venv3
Expand All @@ -101,6 +107,8 @@ invoking:
```
(.venv3)$ python3 tests/mypy_test.py
...
(.venv3)$ python tests/mypy_selftest.py
...
(.venv3)$ flake8
...
```
Expand Down
27 changes: 27 additions & 0 deletions tests/mypy_selftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/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__':
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is a bit of cargo culting. The point of ifmain is testability. Putting all code in this block doesn't achieve that, you're just losing one level of indentation. I'd just remove it for our simple script. Otherwise, prefer main() functions, they don't create unexpected globals :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

It also helps tools that try to import every file in a tree (e.g., stubgen). I prefer to just always avoid side-effects from importing files.

with tempfile.TemporaryDirectory() as tempdir:
dirpath = Path(tempdir)
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create nice error messages for both.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like that's overengineering. People submitting changes to typeshed can probably read a Python stack trace, and there's a chance we make it harder to find the underlying error if we wrap it in our own error handling.

shutil.copytree('stdlib', str(dirpath / 'mypy/typeshed/stdlib'))
shutil.copytree('third_party', str(dirpath / 'mypy/typeshed/third_party'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Those two guys can also raise shutil.Error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing here.

try:
subprocess.run(['./runtests.py'], cwd=str(dirpath / 'mypy'), check=True)
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)