10000 Static and run-time tests for stubs by vlasovskikh · Pull Request #917 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Static and run-time tests for stubs #917

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

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Convention for test data which uses APIs defined by Python stubs
Currently we check only for syntax errors in stub files. The idea is to
add test data for static analyzers similar to how it's done in
DefinitelyTyped for TypeScript.
  • Loading branch information
vlasovskikh committed Jan 26, 2017
commit 4e8d414dd14f7282ddbc85a9207dae06f68160d3
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ are important to the project's success.
* [Contact us](#discussion) before starting significant work.
* IMPORTANT: For new libraries, [get permission from the library owner first](#adding-a-new-library).
* Create your stubs [conforming to the coding style](#stub-file-coding-style).
* Add tests for your stubs to `test_data`. These tests are not meant
to be executable. Type checkers analyze them statically.
* Make sure `runtests.sh` passes cleanly on Mypy, pytype, and flake8.
4. [Submit your changes](#submitting-changes):
* Open a pull request
Expand Down
14 changes: 14 additions & 0 deletions test_data/stdlib/2and3/collections_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from collections import namedtuple


def test_collections_namedtuple():
# type: () -> None
Point = namedtuple('Point', 'x y')
p = Point(1, 2)

p._replace(y=3.14)
p._asdict()
p.x, p.y
p[0] + p[1]
p.index(1)
Point._make([('x', 1), ('y', 3.14)])
2 changes: 1 addition & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def libpath(major, minor):
versions.append('2and3')
paths = []
for v in versions:
for top in ['stdlib', 'third_party']:
for top in ['stdlib', 'third_party', 'test_data/stdlib', 'test_data/third_party']:
p = os.path.join(top, v)
if os.path.isdir(p):
paths.append(p)
Expand Down
8 changes: 7 additions & 1 deletion tests/pytype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def pytype_test(args):
print("Cannot run pytd. Did you install pytype?")
return 0, 0

wanted = re.compile(r"stdlib/(2|2\.7|2and3)/.*\.pyi$")
wanted = re.compile(r"stdlib/(2|2\.7|2and3)/.*\.pyi?$")
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this change for?

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 changed it in order to run pytype on tests files which are regular Python files. Since I've disabled running pytype for them, I could revert this change as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

The existing pytype_test.py checks pyi files using the pytd tool. If you want to run against py files, you'll need to run the pytype executable.

Sorry. I should have caught that earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you do run pytype, you may have to run it as TYPESHED_HOME=/some/path/ pytype in order to point it at the typeshed version you're testing.

skipped = re.compile("(%s)$" % "|".join(load_blacklist()))
files = []

Expand All @@ -80,6 +80,12 @@ def pytype_test(args):
if wanted.search(f) and not skipped.search(f):
files.append(f)

for root, _, filenames in os.walk("test_data/stdlib"):
for f in sorted(filenames):
f = os.path.join(root, f)
if wanted.search(f) and not skipped.search(f):
files.append(f)

running_tests = collections.deque()
max_code, runs, errors = 0, 0, 0
print("Running pytype tests...")
Expand Down
0