1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
# cython: autotestdict=True
# Directive defaults to True, but not when testing in Py3.4
"""
Tests autotestdict compiler directive.
Both module test and individual tests are run; finally,
all_tests_run() is executed which does final validation.
>>> items = list(__test__.items())
>>> items.sort()
>>> for key, value in items:
... print('%s ; %s' % (key, value))
MyCdefClass.cpdef_method (line 77) ; >>> add_log("cpdef class method")
MyCdefClass.method (line 74) ; >>> add_log("cdef class method")
MyClass.method (line 63) ; >>> add_log("class method")
mycpdeffunc (line 50) ; >>> add_log("cpdef")
myfunc (line 40) ; >>> add_log("def")
"""
import sys
log = []
cdef cdeffunc():
"""
>>> True
False
"""
cdeffunc() # make sure it's being used
def all_tests_run():
assert sorted(log) == sorted([u'cdef class', u'class'] + (
2 * [u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'])), sorted(log)
def add_log(s):
log.append(unicode(s))
if len(log) == len(__test__) + 7:
# Final per-function doctest executed
all_tests_run()
def myfunc():
""">>> add_log("def")"""
x = lambda a:1 # no docstring here ...
def doc_without_test():
"""Some docs"""
def nodocstring():
pass
cpdef mycpdeffunc():
""">>> add_log("cpdef")"""
class MyClass:
"""
Needs no hack
>>> add_log("class")
>>> True
True
"""
def method(self):
""">>> add_log("class method")"""
cdef class MyCdefClass:
"""
Needs no hack
>>> add_log("cdef class")
>>> True
True
"""
def method(self):
""">>> add_log("cdef class method")"""
cpdef cpdef_method(self):
""">>> add_log("cpdef class method")"""
cdef cdef_method(self):
""">>> add_log("cdef class cmethod")"""
def __cinit__(self):
"""
Should not be included, as it can't be looked up with getattr
>>> True
False
"""
def __dealloc__(self):
"""
Should not be included, as it can't be looked up with getattr
>>> True
False
"""
def __richcmp__(self, other, int op):
"""
Should not be included, as it can't be looked up with getattr in Py 2
>>> True
False
"""
def __nonzero__(self):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> True
False
"""
def __len__(self):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> sys.version_info < (3, 4)
False
"""
def __contains__(self, value):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> sys.version_info < (3, 4)
False
"""
cdef class MyOtherCdefClass:
"""
Needs no hack
>>> True
True
"""
def __bool__(self):
"""
Should not be included, as it can't be looked up with getattr in Py 2
>>> True
False
"""
|