cython

Форк
0
/
autotestdict_all.pyx 
144 строки · 3.1 Кб
1
# cython: autotestdict=True, autotestdict.all=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 79) ; >>> add_log("cdef class cmethod")
14
MyCdefClass.cpdef_method (line 76) ; >>> add_log("cpdef class method")
15
MyCdefClass.method (line 73) ; >>> add_log("cdef class method")
16
MyClass.method (line 62) ; >>> add_log("class method")
17
cdeffunc (line 26) ; >>> add_log("cdef")
18
doc_without_test (line 43) ; Some docs
19
mycpdeffunc (line 49) ; >>> add_log("cpdef")
20
myfunc (line 40) ; >>> add_log("def")
21
"""
22

23
import sys
24
log = []
25

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

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

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

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

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

46
def nodocstring():
47
    pass
48

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

52

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

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

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

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

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

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

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

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

86
        >>> True
87
        False
88
        """
89

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

94
        >>> True
95
        False
96
        """
97

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

102
        >>> True
103
        False
104
        """
105

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

110
        >>> True
111
        False
112
        """
113

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

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

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

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

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

134
    >>> True
135
    True
136
    """
137

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

142
        >>> True
143
        False
144
        """
145

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

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

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

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