cython

Форк
0
/
cline_in_traceback.srctree 
159 строк · 4.1 Кб
1
PYTHON setup.py build_ext --inplace
2
PYTHON run_all_tests.py
3

4

5
######## setup.py ########
6

7
from Cython.Build.Dependencies import cythonize
8
from setuptools import setup, Extension
9

10
setup(ext_modules = cythonize([
11
        Extension("test_on", ["test_on.pyx"]),
12
        Extension("test_off", ["test_off.pyx"]),
13
        Extension("test_runtime", ["test_runtime.pyx"]),
14
        Extension("test_default", ["test_default.pyx"]),
15
        Extension("test_contradicting_macros", ["test_contradicting_macros.pyx"]),
16
    ],
17
))
18

19
setup(ext_modules = cythonize([
20
        Extension("test_options_on", ["test_options_on.pyx"]),
21
        Extension("test_options_on_overridden", ["test_options_on_overridden.pyx"]),
22
    ],
23
    c_line_in_traceback = True,
24
))
25

26
setup(ext_modules = cythonize([
27
        Extension("test_options_off", ["test_options_off.pyx"]),
28
        Extension("test_options_off_overridden1", ["test_options_off_overridden1.pyx"]),
29
        Extension("test_options_off_overridden2", ["test_options_off_overridden2.pyx"]),
30
    ],
31
    c_line_in_traceback = False,
32
))
33

34

35
####### test_on.pyx ###############
36
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK=1
37

38
include "should_be_on.pxi"
39

40
####### test_off.pyx ###############
41
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK=0
42

43
include "should_be_off.pxi"
44

45
####### test_runtime.pyx ###############
46

47
include "should_be_runtime.pxi"
48

49
####### test_runtime.pyx ##############
50
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK_RUNTIME=1
51

52
include "should_be_runtime.pxi"
53

54
####### test_default.pyx ##############
55

56
include "should_be_off.pxi"
57

58
####### test_options_on.pyx ########
59

60
include "should_be_runtime.pxi"
61

62
####### test_options_off.pyx ########
63

64
include "should_be_off.pxi"
65

66
####### test_options_off_overridden1.pyx #######
67
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK=1
68

69
include "should_be_on.pxi"
70

71
####### test_options_off_overridden2.pyx #######
72
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK_RUNTIME=1
73

74
include "should_be_runtime.pxi"
75

76
####### test_options_on_overridden.pyx #######
77
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK=0
78

79
include "should_be_off.pxi"
80

81
####### test_contradicting_macros.pyx #######
82
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK_RUNTIME=1
83
# distutils: define_macros=CYTHON_CLINE_IN_TRACEBACK=0
84

85
include "should_be_off.pxi"
86

87

88
####### should_be_on.pxi #########
89

90
import helpers
91

92
def run():
93
    try:
94
        raise RuntimeError
95
    except Exception as e:
96
        helpers.validate_cline_in_traceback(e.__traceback__)
97
        
98
####### should_be_off.pxi #########
99

100
import helpers
101

102
def run():
103
    try:
104
        raise RuntimeError
105
    except Exception as e:
106
        helpers.validate_no_cline_in_traceback(e.__traceback__)
107
        
108
####### should_be_runtime.pxi #########
109

110
import helpers
111
import cython_runtime
112

113
def run():
114
    try:
115
        raise RuntimeError
116
    except Exception as e:
117
        helpers.validate_no_cline_in_traceback(e.__traceback__)
118

119
    cython_runtime.cline_in_traceback = True
120
    try:
121
        raise RuntimeError
122
    except Exception as e:
123
        helpers.validate_cline_in_traceback(e.__traceback__)
124

125
    cython_runtime.cline_in_traceback = False
126
    try:
127
        raise RuntimeError
128
    except Exception as e:
129
        helpers.validate_no_cline_in_traceback(e.__traceback__)
130

131

132
####### helpers.py ##############
133

134
import traceback
135
import re
136

137
cline_re = re.compile(r"[(]\w*[.]c:\d*[)]")
138

139
def validate_cline_in_traceback(tb):
140
    formatted = traceback.format_tb(tb)
141
    assert cline_re.search(formatted[0]), formatted
142
    
143
def validate_no_cline_in_traceback(tb):
144
    formatted = traceback.format_tb(tb)
145
    assert not cline_re.search(formatted[0]), formatted
146

147

148
####### run_all_tests.py #########
149

150
import test_on; test_on.run()
151
import test_off; test_off.run()
152
import test_runtime; test_runtime.run()
153
import test_default; test_default.run()
154
import test_options_on; test_options_on.run()
155
import test_options_off; test_options_off.run()
156
import test_options_off_overridden1; test_options_off_overridden1.run()
157
import test_options_off_overridden2; test_options_off_overridden2.run()
158
import test_options_on_overridden; test_options_on_overridden.run()
159
import test_contradicting_macros; test_contradicting_macros.run()
160

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.