absolute_import.srctree 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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