File: tp_new_cimport.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (86 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (10)
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
78
79
80
81
82
83
84
85
86
PYTHON setup.py build_ext --inplace
PYTHON -c "import tp_new_tests; tp_new_tests.test_all()"
PYTHON -c "import tp_new_tests; tp_new_tests.test_sub()"

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

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

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

######## tp_new_tests.py ########

def test_all():
    test_a()
    test_b()
    test_a_in_b()
    test_sub()

def test_a():
    import a
    assert isinstance(a.tpnew_ExtTypeA(), a.ExtTypeA)
    assert a.tpnew_ExtTypeA().attrA == 123

def test_b():
    import b
    assert isinstance(b.tpnew_ExtTypeB(), b.ExtTypeB)
    assert b.tpnew_ExtTypeB().attrB == 234

def test_a_in_b():
    import a,b
    assert isinstance(b.tpnew_ExtTypeA(), a.ExtTypeA)
    assert b.tpnew_ExtTypeA().attrA == 123

def test_sub():
    import b
    assert isinstance(b.tpnew_SubExtTypeA(), b.SubExtTypeA)
    assert b.tpnew_SubExtTypeA().attrAB == 345
    assert b.tpnew_SubExtTypeA().attrA == 123

######## a.pxd ########

cdef api class ExtTypeA[type ExtTypeA_Type, object ExtTypeAObject]:
    cdef readonly attrA

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

cdef class ExtTypeA:
    def __cinit__(self):
        self.attrA = 123

def tpnew_ExtTypeA():
    return ExtTypeA.__new__(ExtTypeA)

######## b.pxd ########

from a cimport ExtTypeA

cdef class ExtTypeB:
    cdef readonly attrB

cdef class SubExtTypeA(ExtTypeA):
    cdef readonly attrAB

######## b.pyx ########

from a cimport ExtTypeA

cdef class ExtTypeB:
    def __cinit__(self):
        self.attrB = 234

cdef class SubExtTypeA(ExtTypeA):
    def __cinit__(self):
        self.attrAB = 345

def tpnew_ExtTypeA():
    return ExtTypeA.__new__(ExtTypeA)

def tpnew_ExtTypeB():
    return ExtTypeB.__new__(ExtTypeB)

def tpnew_SubExtTypeA():
    return SubExtTypeA.__new__(SubExtTypeA)