blob: cceb014ac224f2461162cc6f6f498f5bfa817a36 (
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
|
"""
PYTHON run_test.py
"""
######## run_test.py ########
import os
from collections import defaultdict
from os.path import basename, splitext
from Cython.Compiler.Options import CompilationOptions
from Cython.Compiler.Main import compile as cython_compile
from Cython.Compiler.Options import default_options
def validate_file(filename):
module_name = basename(filename)
c_file = splitext(filename)[0] + '.c'
options = CompilationOptions(
default_options,
language_level="3",
evaluate_tree_assertions=True,
)
result = cython_compile(filename, options=options)
return result.num_errors
counts = defaultdict(int)
failed = False
for filename in sorted(os.listdir(".")):
if "run_test" in filename:
continue
print("Testing '%s'" % filename)
num_errors = validate_file(filename)
print(num_errors, filename)
counts[num_errors] += 1
if '_ok' in filename:
if num_errors > 0:
failed = True
print("ERROR: Compilation failed: %s (%s errors)" % (filename, num_errors))
else:
if num_errors == 0:
failed = True
print("ERROR: Expected failure, but compilation succeeded: %s" % filename)
assert counts == {0: 2, 1: 2}, counts
assert not failed
######## assert_ok.py ########
# cython: test_assert_c_code_has = Generated by Cython
# cython: test_assert_c_code_has = CYTHON_HEX_VERSION
######## assert_missing.py ########
# cython: test_assert_c_code_has = Generated by Python
######## fail_if_ok.py ########
# cython: test_fail_if_c_code_has = Generated by Python
######## fail_if_found.py ########
# cython: test_fail_if_c_code_has = Generated by Cython
|