Skip to content

Commit

Permalink
add test to actually reproduce python#5784
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisphilip322 committed Oct 13, 2018
1 parent 9c577e6 commit 146c26b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
alpha_func(2)
"""

C_EXT_PROGRAM = """
from typedpkg_c_ext.foo import speak
from typedpkg_c_ext.hello import helloworld
"""


class NamespaceProgramImportStyle(Enum):
from_import = """\
Expand Down Expand Up @@ -166,12 +171,14 @@ def setUp(self) -> None:
create_namespace_program_source(NamespaceProgramImportStyle.from_import))
self.regular_import_namespace_example_program = ExampleProgram(
create_namespace_program_source(NamespaceProgramImportStyle.from_import))
self.c_ext_example_program = ExampleProgram(C_EXT_PROGRAM)

def tearDown(self) -> None:
self.simple_example_program.cleanup()
self.from_namespace_example_program.cleanup()
self.import_as_namespace_example_program.cleanup()
self.regular_import_namespace_example_program.cleanup()
self.c_ext_example_program.cleanup()

def test_get_pkg_dirs(self) -> None:
"""Check that get_package_dirs works."""
Expand Down Expand Up @@ -302,6 +309,17 @@ def test_nested_and_namespace_regular_import(self) -> None:
venv_dir=venv_dir,
)

def test_c_ext_from_import(self) -> None:
self.c_ext_example_program.init()
with self.virtualenv() as venv:
venv_dir, python_executable = venv
self.install_package('typedpkg_c_ext', python_executable)
self.c_ext_example_program.check_mypy_run(
python_executable,
[],
venv_dir=venv_dir,
)


if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions test-data/packages/typedpkg_c_ext/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Python.h>

// Function 1: A simple 'hello world' function
static PyObject* helloworld(PyObject* self, PyObject* args)
{
printf("Hello World\n");
return Py_None;
}

// Our Module's Function Definition struct
// We require this `NULL` to signal the end of our method
// definition
static PyMethodDef myMethods[] = {
{ "helloworld", helloworld, METH_NOARGS, "Prints Hello World" },
{ NULL, NULL, 0, NULL }
};

// Our Module Definition struct
static struct PyModuleDef myModule = {
PyModuleDef_HEAD_INIT,
"hello",
"Test Module",
-1,
myMethods
};

// Initializes our module using our above struct
PyMODINIT_FUNC PyInit_hello(void)
{
return PyModule_Create(&myModule);
}
12 changes: 12 additions & 0 deletions test-data/packages/typedpkg_c_ext/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup, Extension

setup(
name='typedpkg_c_ext',
version='1.0',
packages=['typedpkg_c_ext'],
ext_modules=[Extension('typedpkg_c_ext.hello', ['hello.c'])],
zip_safe=False,
package_data={
'typedpkg_c_ext': ['py.typed']
},
)
Empty file.
5 changes: 5 additions & 0 deletions test-data/packages/typedpkg_c_ext/typedpkg_c_ext/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import hello


def speak() -> None:
hello.helloworld()
Empty file.

0 comments on commit 146c26b

Please # to comment.