Commit e914b27b authored by Stefan Behnel's avatar Stefan Behnel

add test for absolute imports

parent 335a1b21
......@@ -201,6 +201,7 @@ VER_DEP_MODULES = {
'run.yield_from_pep380', # GeneratorExit
'run.generator_frame_cycle', # yield in try-finally
'run.generator_expressions_in_class',
'run.absolute_import',
'run.relativeimport_T542',
'run.relativeimport_star_T542',
'run.initial_file_path', # relative import
......
PYTHON setup.py build_ext --inplace
PYTHON -c "import pkg.my_test_module"
PYTHON -c "import pkg.b; pkg.b.test_reimport()"
PYTHON -c "import pkg.c; pkg.c.test_reimport()"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("**/*.pyx"),
)
######## pkg/__init__.py ########
######## pkg/a_module.pyx ########
######## pkg/my_test_module.pyx ########
import sys
from . import a_module
assert a_module in sys.modules.values(), list(sys.modules)
assert sys.modules['pkg.a_module'] is a_module, list(sys.modules)
######## pkg/b.pyx ########
from __future__ import absolute_import
import sys
try:
import my_test_module
except ImportError:
pass
else:
assert "expected ImportError on absolute import"
import pkg.my_test_module
assert pkg.my_test_module in sys.modules.values(), list(sys.modules)
assert sys.modules['pkg.my_test_module'] is pkg.my_test_module, list(sys.modules)
def test_reimport():
import pkg.my_test_module as mod
assert pkg.my_test_module is mod
######## pkg/c.pyx ########
from __future__ import absolute_import
import sys
from pkg import my_test_module
assert my_test_module in sys.modules.values(), list(sys.modules)
assert sys.modules['pkg.my_test_module'] is my_test_module, list(sys.modules)
def test_reimport():
from pkg import my_test_module as mod
assert my_test_module is mod
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment