cython

Форк
0
/
c_file_validation.srctree 
98 строк · 2.3 Кб
1
"""
2
PYTHON run_test.py
3
"""
4

5
######## run_test.py ########
6

7
import os
8
from collections import defaultdict
9
from os.path import basename, splitext
10

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
14

15

16
def validate_file(filename):
17
    module_name = basename(filename)
18
    c_file = splitext(filename)[0] + '.c'
19

20
    options = CompilationOptions(
21
        default_options,
22
        language_level="3",
23
        evaluate_tree_assertions=True,
24
    )
25
    result = cython_compile(filename, options=options)
26
    return result.num_errors
27

28

29
error_counts = defaultdict(int)
30
failed = False
31

32
for filename in sorted(os.listdir(".")):
33
    if "run_test" in filename:
34
        continue
35

36
    print("Testing '%s'" % filename)
37
    num_errors = validate_file(filename)
38
    print(num_errors, filename)
39
    error_counts[num_errors] += 1
40

41
    if '_ok' in filename:
42
        if num_errors > 0:
43
            failed = True
44
            print("ERROR: Compilation failed: %s (%s errors)" % (filename, num_errors))
45
    else:
46
        if num_errors == 0:
47
            failed = True
48
            print("ERROR: Expected failure, but compilation succeeded: %s" % filename)
49

50
assert error_counts == {0: 3, 1: 6}, error_counts
51
assert not failed
52

53

54
######## assert_ok.py ########
55

56
# cython: test_assert_c_code_has = Generated by Cython
57
# cython: test_assert_c_code_has = CYTHON_HEX_VERSION
58

59

60
######## assert_missing.py ########
61

62
# cython: test_assert_c_code_has = Generated by Python
63

64

65
######## assert_start_end_ok.py ########
66

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

70

71
######## assert_start_missing.py ########
72

73
# cython: test_assert_c_code_has = /xx[^x]xx/: Generated by Cython
74

75

76
######## assert_end_missing.py ########
77

78
# cython: test_assert_c_code_has = :/xx[^x]xx/ Generated by Cython
79

80

81
######## fail_if_ok.py ########
82

83
# cython: test_fail_if_c_code_has = Generated by Python
84

85

86
######## fail_if_found.py ########
87

88
# cython: test_fail_if_c_code_has = Generated by Cython
89

90

91
######## fail_if_start_missing.py ########
92

93
# cython: test_fail_if_c_code_has = /xx[^x]xx/: Generated by Python
94

95

96
######## fail_if_end_missing.py ########
97

98
# cython: test_fail_if_c_code_has = :/xx[^x]xx/ Generated by Python
99

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

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

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

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