summaryrefslogtreecommitdiff
path: root/tests/run/relativeimport_T542.srctree
blob: 27020174f59abb7222b43a7035fde7b90c9e6e89 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# mode: run
# tag: import

"""
PYTHON setup.py build_ext -i
PYTHON test_relative_import.py
"""

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

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

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


######## test_relative_import.py ########

from relimport.testmod import test_relative, test_absolute
a, bmod, afunc, bfunc = test_relative()

try:
    test_absolute()
except ImportError:
    pass
else:
    import sys
    assert False, "absolute import succeeded: %s" % sorted(sys.modules)

import relimport.a
import relimport.bmod
import relimport.testmod

assert relimport.a == a
assert relimport.bmod == bmod
assert afunc() == 'a', afunc
assert bfunc() == 'b', bfunc


######## relimport/__init__.py ########

######## relimport/a.pyx ########

def afunc(): return 'a'


######## relimport/bmod.pyx ########

def bfunc(): return 'b'


######## relimport/testmod.pyx ########
# cython: language_level=3

from relimport import a as global_a, bmod as global_bmod

from . import *

assert a is global_a, a
assert bmod is global_bmod, bmod

def test_relative():
    from . import a, bmod
    from . import (a, bmod)
    from . import (a, bmod,)
    from .a import afunc
    from .bmod import bfunc

    assert afunc() == 'a', afunc()
    assert bfunc() == 'b', bfunc()

    return a, bmod, afunc, bfunc

def test_absolute():
    import bmod