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 87 88 89 90 91 92 93 94 95 96 97 98
|
"""
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
error_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)
error_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 error_counts == {0: 3, 1: 6}, error_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
######## assert_start_end_ok.py ########
# cython: test_assert_c_code_has = :/#include "Python.h"/ Generated by Cython
# cython: test_assert_c_code_has = /Generated by Cython/:/Code section/ #include "Python.h"
######## assert_start_missing.py ########
# cython: test_assert_c_code_has = /xx[^x]xx/: Generated by Cython
######## assert_end_missing.py ########
# cython: test_assert_c_code_has = :/xx[^x]xx/ Generated by Cython
######## 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
######## fail_if_start_missing.py ########
# cython: test_fail_if_c_code_has = /xx[^x]xx/: Generated by Python
######## fail_if_end_missing.py ########
# cython: test_fail_if_c_code_has = :/xx[^x]xx/ Generated by Python
|