cython

Форк
0
/
autotestdict.pyx 
145 строк · 3.0 Кб
1
# cython: autotestdict=True
2
# Directive defaults to True, but not when testing in Py3.4
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.cpdef_method (line 77) ; >>> add_log("cpdef class method")
14
MyCdefClass.method (line 74) ; >>> add_log("cdef class method")
15
MyClass.method (line 63) ; >>> add_log("class method")
16
mycpdeffunc (line 50) ; >>> add_log("cpdef")
17
myfunc (line 40) ; >>> add_log("def")
18
"""
19

20
import sys
21
log = []
22

23
cdef cdeffunc():
24
    """
25
    >>> True
26
    False
27
    """
28
cdeffunc() # make sure it's being used
29

30
def all_tests_run():
31
    assert sorted(log) == sorted([u'cdef class', u'class'] + (
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__) + 7:
37
        # Final per-function doctest executed
38
        all_tests_run()
39

40
def myfunc():
41
    """>>> add_log("def")"""
42
    x = lambda a:1 # no docstring here ...
43

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

47
def nodocstring():
48
    pass
49

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

53

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

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

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

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

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

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

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

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

87
        >>> True
88
        False
89
        """
90

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

95
        >>> True
96
        False
97
        """
98

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

103
        >>> True
104
        False
105
        """
106

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

111
        >>> True
112
        False
113
        """
114

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

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

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

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

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

135
    >>> True
136
    True
137
    """
138

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

143
        >>> True
144
        False
145
        """
146

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

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

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

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