-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Move test_stubs and test_samples to pytest #5142
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Self check mypy package""" | ||
import sys | ||
import os.path | ||
from typing import List, Set | ||
|
||
from mypy.test.helpers import Suite, run_mypy | ||
|
||
|
||
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) | ||
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) | ||
|
||
def test_samples(self) -> None: | ||
for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'): | ||
mypy_args = ['--no-strict-optional'] | ||
if f == os.path.join('test-data', 'samples', 'crawl2.py'): | ||
# This test requires 3.5 for async functions | ||
mypy_args.append('--python-version=3.5') | ||
run_mypy(mypy_args + [f]) | ||
|
||
|
||
def find_files(base: str, prefix: str = '', suffix: str = '') -> List[str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps these should be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. It's a temporary hack in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that is true. I think this okay then. |
||
return [os.path.join(root, f) | ||
for root, dirs, files in os.walk(base) | ||
for f in files | ||
if f.startswith(prefix) and f.endswith(suffix)] | ||
|
||
|
||
def file_to_module(file: str) -> str: | ||
rv = os.path.splitext(file)[0].replace(os.sep, '.') | ||
if rv.endswith('.__init__'): | ||
rv = rv[:-len('.__init__')] | ||
return rv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "FIX:" mean? Is it a TODO? Why not do it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you are right. I think I didn't want to change anything