5
######## run_test.py ########
8
from collections import defaultdict
9
from os.path import basename, splitext
11
from Cython.Compiler.Options import CompilationOptions
12
from Cython.Compiler.Main import compile as cython_compile
13
from Cython.Compiler.Options import default_options
16
def validate_file(filename):
17
module_name = basename(filename)
18
c_file = splitext(filename)[0] + '.c'
20
options = CompilationOptions(
23
evaluate_tree_assertions=True,
25
result = cython_compile(filename, options=options)
26
return result.num_errors
29
error_counts = defaultdict(int)
32
for filename in sorted(os.listdir(".")):
33
if "run_test" in filename:
36
print("Testing '%s'" % filename)
37
num_errors = validate_file(filename)
38
print(num_errors, filename)
39
error_counts[num_errors] += 1
44
print("ERROR: Compilation failed: %s (%s errors)" % (filename, num_errors))
48
print("ERROR: Expected failure, but compilation succeeded: %s" % filename)
50
assert error_counts == {0: 3, 1: 6}, error_counts
54
######## assert_ok.py ########
56
# cython: test_assert_c_code_has = Generated by Cython
57
# cython: test_assert_c_code_has = CYTHON_HEX_VERSION
60
######## assert_missing.py ########
62
# cython: test_assert_c_code_has = Generated by Python
65
######## assert_start_end_ok.py ########
67
# cython: test_assert_c_code_has = :/#include "Python.h"/ Generated by Cython
68
# cython: test_assert_c_code_has = /Generated by Cython/:/Code section/ #include "Python.h"
71
######## assert_start_missing.py ########
73
# cython: test_assert_c_code_has = /xx[^x]xx/: Generated by Cython
76
######## assert_end_missing.py ########
78
# cython: test_assert_c_code_has = :/xx[^x]xx/ Generated by Cython
81
######## fail_if_ok.py ########
83
# cython: test_fail_if_c_code_has = Generated by Python
86
######## fail_if_found.py ########
88
# cython: test_fail_if_c_code_has = Generated by Cython
91
######## fail_if_start_missing.py ########
93
# cython: test_fail_if_c_code_has = /xx[^x]xx/: Generated by Python
96
######## fail_if_end_missing.py ########
98
# cython: test_fail_if_c_code_has = :/xx[^x]xx/ Generated by Python