Permalink
Browse files

add test for absolute imports

  • Loading branch information...
1 parent 335a1b2 commit e914b27b67876afbb7ef2efe22e2454171b5692b @scoder scoder committed Mar 16, 2013
Showing with 60 additions and 0 deletions.
  1. +1 −0 runtests.py
  2. +59 −0 tests/run/absolute_import.srctree
View
@@ -201,6 +201,7 @@ def get_openmp_compiler_flags(language):
'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
@@ -0,0 +1,59 @@
+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

0 comments on commit e914b27

Please sign in to comment.