cython

Форк
0
/
autotestdict_cdef.pyx 
143 строки · 3.1 Кб
1
# cython: autotestdict=True, autotestdict.cdef=True
2

3
"""
4
Tests autotestdict compiler directive.
5

6
Both module test and individual tests are run; finally,
7
all_tests_run() is executed which does final validation.
8

9
>>> items = list(__test__.items())
10
>>> items.sort()
11
>>> for key, value in items:
12
...     print('%s ; %s' % (key, value))
13
MyCdefClass.cdef_method (line 78) ; >>> add_log("cdef class cmethod")
14
MyCdefClass.cpdef_method (line 75) ; >>> add_log("cpdef class method")
15
MyCdefClass.method (line 72) ; >>> add_log("cdef class method")
16
MyClass.method (line 61) ; >>> add_log("class method")
17
cdeffunc (line 25) ; >>> add_log("cdef")
18
mycpdeffunc (line 48) ; >>> add_log("cpdef")
19
myfunc (line 39) ; >>> add_log("def")
20
"""
21

22
import sys
23
log = []
24

25
cdef cdeffunc():
26
    """>>> add_log("cdef")"""
27
cdeffunc() # make sure it's being used
28

29
def all_tests_run():
30
    assert sorted(log) == sorted([u'cdef', u'cdef class', u'cdef class cmethod', u'class'] + (
31
        2 * [u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'])), sorted(log)
32

33
def add_log(s):
34
    log.append(unicode(s))
35
    if len(log) == len(__test__) + 7:
36
        # Final per-function doctest executed
37
        all_tests_run()
38

39
def myfunc():
40
    """>>> add_log("def")"""
41

42
def doc_without_test():
43
    """Some docs"""
44

45
def nodocstring():
46
    pass
47

48
cpdef mycpdeffunc():
49
    """>>> add_log("cpdef")"""
50

51

52
class MyClass:
53
    """
54
    Needs no hack
55

56
    >>> add_log("class")
57
    >>> True
58
    True
59
    """
60

61
    def method(self):
62
        """>>> add_log("class method")"""
63

64
cdef class MyCdefClass:
65
    """
66
    Needs no hack
67

68
    >>> add_log("cdef class")
69
    >>> True
70
    True
71
    """
72
    def method(self):
73
        """>>> add_log("cdef class method")"""
74

75
    cpdef cpdef_method(self):
76
        """>>> add_log("cpdef class method")"""
77

78
    cdef cdef_method(self):
79
        """>>> add_log("cdef class cmethod")"""
80

81
    def __cinit__(self):
82
        """
83
        Should not be included, as it can't be looked up with getattr
84

85
        >>> True
86
        False
87
        """
88

89
    def __dealloc__(self):
90
        """
91
        Should not be included, as it can't be looked up with getattr
92

93
        >>> True
94
        False
95
        """
96

97
    def __richcmp__(self, other, int op):
98
        """
99
        Should not be included, as it can't be looked up with getattr in Py 2
100

101
        >>> True
102
        False
103
        """
104

105
    def __nonzero__(self):
106
        """
107
        Should not be included, as it can't be looked up with getattr in Py 3.1
108

109
        >>> True
110
        False
111
        """
112

113
    def __len__(self):
114
        """
115
        Should not be included, as it can't be looked up with getattr in Py 3.1
116

117
        >>> sys.version_info < (3, 4)
118
        False
119
        """
120

121
    def __contains__(self, value):
122
        """
123
        Should not be included, as it can't be looked up with getattr in Py 3.1
124

125
        >>> sys.version_info < (3, 4)
126
        False
127
        """
128

129
cdef class MyOtherCdefClass:
130
    """
131
    Needs no hack
132

133
    >>> True
134
    True
135
    """
136

137
    def __bool__(self):
138
        """
139
        Should not be included, as it can't be looked up with getattr in Py 2
140

141
        >>> True
142
        False
143
        """
144

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

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

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

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