summaryrefslogtreecommitdiff
path: root/tests/run/reimport_from_package.srctree
blob: 027d26de53180d7f67538d8e4fe2261cea2fabde (plain)
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
# mode: run
# tag: pep489

PYTHON setup.py build_ext --inplace
PYTHON -c "import a"

######## setup.py ########

from Cython.Build.Dependencies import cythonize
from distutils.core import setup

setup(
    ext_modules = cythonize("**/*.pyx"),
    )

######## a.pyx ########

import sys
import a
assert a in sys.modules.values(), list(sys.modules)
assert sys.modules['a'] is a, list(sys.modules)

from atest.package import module

######## atest/__init__.py ########

######## atest/package/__init__.py ########

######## atest/package/module.pyx ########

import sys
assert 'atest.package.module' in sys.modules

import a
import atest.package.module as module
assert module in sys.modules.values(), list(sys.modules)
assert sys.modules['atest.package.module'] is module, list(sys.modules)

if sys.version_info >= (3, 5):
    from . import pymodule
    assert module is pymodule.import_without_package()

######## atest/package/pymodule.py ########

from . import module
from ..package import module
import atest.package.module

import a

def import_without_package():
    import os.path
    import sys
    sys.path.insert(0, os.path.dirname(__file__))
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    import module
    import package.module
    assert package.module is module
    return module