1PYTHON setup.py build_ext --inplace
2PYTHON -c "import runner"
3
4######## setup.py ########
5
6from Cython.Build.Dependencies import cythonize
7from distutils.core import setup
8
9setup(ext_modules=cythonize("*.pyx"))
10
11######## notheaptype.pyx ########
12
13cdef class Base:
14    pass
15
16Obj = type(object())
17
18cdef class Foo(Base, Obj):
19    pass
20
21######## wrongbase.pyx ########
22
23cdef class Base:
24    pass
25
26Str = type("")
27
28cdef class X(Base, Str):
29    pass
30
31######## badmro.pyx ########
32
33class Py(object):
34    pass
35
36cdef class X(object, Py):
37    pass
38
39######## nodict.pyx ########
40
41cdef class Base:
42    pass
43
44class Py(object):
45    pass
46
47cdef class X(Base, Py):
48    pass
49
50######## oldstyle.pyx ########
51# cython: language_level=2
52
53cdef class Base:
54    cdef dict __dict__
55
56class OldStyle:
57    pass
58
59cdef class Foo(Base, OldStyle):
60    pass
61
62######## runner.py ########
63
64import sys
65
66try:
67    import notheaptype
68    assert False, "notheaptype"
69except TypeError as msg:
70    assert str(msg) == "base class 'object' is not a heap type"
71
72try:
73    import wrongbase
74    assert False, "wrongbase"
75except TypeError as msg:
76    assert str(msg) == "best base 'str' must be equal to first base 'wrongbase.Base'"
77
78try:
79    import badmro
80    assert False, "badmro"
81except TypeError as msg:
82    assert str(msg).startswith("Cannot create a consistent method resolution")
83
84try:
85    import nodict
86    assert False, "nodict"
87except TypeError as msg:
88    assert str(msg) == "extension type 'nodict.X' has no __dict__ slot, but base type 'Py' has: either add 'cdef dict __dict__' to the extension type or add '__slots__ = [...]' to the base type"
89
90try:
91    # This should work on Python 3 but fail on Python 2
92    import oldstyle
93    assert sys.version_info[0] >= 3, "oldstyle"
94except TypeError as msg:
95    assert str(msg) == "base class 'OldStyle' is an old-style class"
96