cython

Форк
0
/
annotate_html.pyx 
71 строка · 1.5 Кб
1
# cython: test_assert_c_code_has = Generated by Cython
2
# cython: test_assert_c_code_has = goto __pyx_L0;\n
3

4
"""
5
>>> from codecs import open
6
>>> import os.path as os_path
7
>>> module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
8
>>> assert module_path.endswith('annotate_html')
9
>>> assert os_path.exists(module_path + '.c') or os_path.exists(module_path + '.cpp'), module_path
10
>>> assert os_path.exists(module_path + '.html'), module_path
11

12
>>> with open(module_path + '.html', 'r', 'utf8') as html_file:
13
...     html = html_file.read()
14

15
>>> import re
16
>>> assert re.search('<pre .*def.* .*mixed_test.*</pre>', html)
17
>>> from Cython.Compiler.Annotate import AnnotationCCodeWriter
18
>>> assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html) # per default no complete c code
19
"""
20

21

22
def mixed_test():
23
    """docstring
24
    """
25
    cdef int int1, int2, int3
26
    cdef char *ptr1, *ptr2 = "test", *ptr3 = "toast"
27
    int2 = 10
28
    int3 = 20
29
    obj1 = 1
30
    obj2 = 2
31
    obj3 = 3
32
    int1 = int2 + int3
33
    ptr1 = ptr2 + int3
34
    ptr1 = int2 + ptr3
35
    obj1 = obj2 + int3
36
    return int1, obj1
37

38

39
def add_x_1(int x):
40
    return x + 1
41

42

43
def add_x_1f(x):
44
    return x + 1.0
45

46

47
def add_x_large(x):
48
    return x + 2**30
49

50

51
def add_1_x(x):
52
    return 1 + x
53

54

55
def add_1f_x(double x):
56
    return 1.0 + x
57

58

59
def add_large_x(x):
60
    return 2**30 + x
61

62

63
class PythonClass(object):
64
    def call(self, x):
65
        return add_1_x(x)
66

67

68
cdef class ExtensionType(object):
69
    @classmethod
70
    def new(cls):
71
        return cls()
72

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

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

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

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