""" 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