Skip to content

Commit

Permalink
Add testpep561 test
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 committed Sep 18, 2021
1 parent 8135bf0 commit 1e891c7
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from setuptools import setup, find_packages
from setuptools import setup

setup(
name='typedpkg_namespace.alpha',
version='1.0.0',
packages=find_packages(),
namespace_packages=['typedpkg_ns'],
zip_safe=False,
package_data={'typedpkg_ns.ns': ['py.typed']}
package_data={'typedpkg_ns.a': ['py.typed']},
packages=['typedpkg_ns.a'],
)
14 changes: 14 additions & 0 deletions test-data/packages/typedpkg_ns_b-stubs/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
This setup file installs packages to test mypy's PEP 561 implementation
"""

from distutils.core import setup

setup(
name='typedpkg_ns_b-stubs',
author="The mypy team",
version='0.1',
namespace_packages=['typedpkg_ns-stubs'],
package_data={'typedpkg_ns-stubs.b': ['__init__.pyi', 'bbb.pyi']},
packages=['typedpkg_ns-stubs.b'],
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def bf(a: bool) -> bool: ...
10 changes: 10 additions & 0 deletions test-data/packages/typedpkg_ns_b/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup

setup(
name='typedpkg_namespace.beta',
version='1.0.0',
namespace_packages=['typedpkg_ns'],
zip_safe=False,
package_data={'typedpkg_ns.b': []},
packages=['typedpkg_ns.b'],
)
2 changes: 2 additions & 0 deletions test-data/packages/typedpkg_ns_b/typedpkg_ns/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# namespace pkg
__import__("pkg_resources").declare_namespace(__name__)
Empty file.
2 changes: 2 additions & 0 deletions test-data/packages/typedpkg_ns_b/typedpkg_ns/b/bbb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def bf(a):
return not a
55 changes: 41 additions & 14 deletions test-data/unit/pep561.test
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ reveal_type(a)
testTypedPkgSimpleEditableEgg.py:5: note: Revealed type is "builtins.tuple[builtins.str]"

[case testTypedPkgNamespaceImportFrom]
# pkgs: typedpkg, typedpkg_ns
# pkgs: typedpkg, typedpkg_ns_a
from typedpkg.pkg.aaa import af
from typedpkg_ns.ns.bbb import bf
from typedpkg_ns.ns.dne import dne
from typedpkg_ns.a.bbb import bf
from typedpkg_ns.a.dne import dne

af("abc")
bf(False)
Expand All @@ -132,16 +132,16 @@ af(False)
bf(2)
dne("abc")
[out]
testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
testTypedPkgNamespaceImportFrom.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testTypedPkgNamespaceImportFrom.py:10: error: Argument 1 to "af" has incompatible type "bool"; expected "str"
testTypedPkgNamespaceImportFrom.py:11: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"

[case testTypedPkgNamespaceImportAs]
# pkgs: typedpkg, typedpkg_ns
# pkgs: typedpkg, typedpkg_ns_a
import typedpkg.pkg.aaa as nm; af = nm.af
import typedpkg_ns.ns.bbb as am; bf = am.bf
from typedpkg_ns.ns.dne import dne
import typedpkg_ns.a.bbb as am; bf = am.bf
from typedpkg_ns.a.dne import dne

af("abc")
bf(False)
Expand All @@ -151,16 +151,16 @@ af(False)
bf(2)
dne("abc")
[out]
testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
testTypedPkgNamespaceImportAs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testTypedPkgNamespaceImportAs.py:10: error: Argument 1 has incompatible type "bool"; expected "str"
testTypedPkgNamespaceImportAs.py:11: error: Argument 1 has incompatible type "int"; expected "bool"

[case testTypedPkgNamespaceRegImport]
# pkgs: typedpkg, typedpkg_ns
# pkgs: typedpkg, typedpkg_ns_a
import typedpkg.pkg.aaa; af = typedpkg.pkg.aaa.af
import typedpkg_ns.ns.bbb; bf = typedpkg_ns.ns.bbb.bf
from typedpkg_ns.ns.dne import dne
import typedpkg_ns.a.bbb; bf = typedpkg_ns.a.bbb.bf
from typedpkg_ns.a.dne import dne

af("abc")
bf(False)
Expand All @@ -171,7 +171,7 @@ bf(2)
dne("abc")

[out]
testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
testTypedPkgNamespaceRegImport.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testTypedPkgNamespaceRegImport.py:10: error: Argument 1 has incompatible type "bool"; expected "str"
testTypedPkgNamespaceRegImport.py:11: error: Argument 1 has incompatible type "int"; expected "bool"
Expand All @@ -188,9 +188,36 @@ import a
a.py:1: error: Unsupported operand types for + ("int" and "str")

[case testTypedPkgNamespaceRegFromImportTwice]
# pkgs: typedpkg_ns
from typedpkg_ns import ns
# pkgs: typedpkg_ns_a
from typedpkg_ns import a
-- dummy should trigger a second iteration
[file dummy.py.2]
[out]
[out2]

[case testNamespacePkgWStubs]
# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs
import typedpkg_ns.a.bbb as a
import typedpkg_ns.b.bbb as b
a.bf(False)
b.bf(False)
a.bf(1)
b.bf(1)
[out]
testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b.bbb": found module but no type hints or library stubs
testNamespacePkgWStubs.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b": found module but no type hints or library stubs
testNamespacePkgWStubs.py:6: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"

[case testNamespacePkgWStubsWithNamespacePackagesFlag]
# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs
# flags: --namespace-packages
import typedpkg_ns.a.bbb as a
import typedpkg_ns.b.bbb as b
a.bf(False)
b.bf(False)
a.bf(1)
b.bf(1)
[out]
testNamespacePkgWStubsWithNamespacePackagesFlag.py:7: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"
testNamespacePkgWStubsWithNamespacePackagesFlag.py:8: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"

0 comments on commit 1e891c7

Please sign in to comment.