Commit 4cefc938 authored by Stefan Behnel's avatar Stefan Behnel

enable doctests in cdef functions/methods, do not rewrap docstrings in...

enable doctests in cdef functions/methods, do not rewrap docstrings in __test__ dict as EncodedString() but keep them as they are
parent dbf774cc
...@@ -53,22 +53,21 @@ class AutoTestDictTransform(ScopeTrackingTransform): ...@@ -53,22 +53,21 @@ class AutoTestDictTransform(ScopeTrackingTransform):
pos = self.testspos pos = self.testspos
keystr = u'%s (line %d)' % (path, testpos[1]) keystr = u'%s (line %d)' % (path, testpos[1])
key = UnicodeNode(pos, value=EncodedString(keystr)) key = UnicodeNode(pos, value=EncodedString(keystr))
value = UnicodeNode(pos, value=EncodedString(doctest)) value = UnicodeNode(pos, value=doctest)
self.tests.append(DictItemNode(pos, key=key, value=value)) self.tests.append(DictItemNode(pos, key=key, value=value))
def visit_FuncDefNode(self, node): def visit_FuncDefNode(self, node):
if not node.doc: if not node.doc:
return node return node
if isinstance(node, CFuncDefNode) and not node.py_func:
# skip non-cpdef cdef functions
return node
pos = self.testspos pos = self.testspos
if self.scope_type == 'module': if self.scope_type == 'module':
path = node.entry.name path = node.entry.name
elif self.scope_type in ('pyclass', 'cclass'): elif self.scope_type in ('pyclass', 'cclass'):
if isinstance(node, CFuncDefNode): if isinstance(node, CFuncDefNode):
name = node.py_func.name if node.py_func is not None:
name = node.py_func.name
else:
name = node.entry.name
else: else:
name = node.name name = node.name
if self.scope_type == 'cclass' and name in self.blacklist: if self.scope_type == 'cclass' and name in self.blacklist:
......
...@@ -12,28 +12,25 @@ all_tests_run() is executed which does final validation. ...@@ -12,28 +12,25 @@ all_tests_run() is executed which does final validation.
>>> items.sort() >>> items.sort()
>>> for key, value in items: >>> for key, value in items:
... print('%s ; %s' % (key, value)) ... print('%s ; %s' % (key, value))
MyCdefClass.cpdef_method (line 79) ; >>> add_log("cpdef class method") MyCdefClass.cdef_method (line 79) ; >>> add_log("cdef class method")
MyCdefClass.method (line 76) ; >>> add_log("cdef class method") MyCdefClass.cpdef_method (line 76) ; >>> add_log("cpdef class method")
MyClass.method (line 65) ; >>> add_log("class method") MyCdefClass.method (line 73) ; >>> add_log("cdef class method")
doc_without_test (line 47) ; Some docs MyClass.method (line 62) ; >>> add_log("class method")
mycpdeffunc (line 53) ; >>> add_log("cpdef") cdeffunc (line 28) ; >>> add_log("cdef")
myfunc (line 44) ; >>> add_log("def") doc_without_test (line 44) ; Some docs
mycpdeffunc (line 50) ; >>> add_log("cpdef")
myfunc (line 41) ; >>> add_log("def")
""" """
log = [] log = []
cdef cdeffunc(): cdef cdeffunc():
""" """>>> add_log("cdef")"""
Please don't include me!
>>> True
False
"""
def all_tests_run(): def all_tests_run():
log.sort() log.sort()
assert log == [u'cdef class', u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'], log assert log == [u'cdef', u'cdef class', u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'], log
def add_log(s): def add_log(s):
log.append(unicode(s)) log.append(unicode(s))
...@@ -79,6 +76,9 @@ cdef class MyCdefClass: ...@@ -79,6 +76,9 @@ cdef class MyCdefClass:
cpdef cpdef_method(self): cpdef cpdef_method(self):
""">>> add_log("cpdef class method")""" """>>> add_log("cpdef class method")"""
cdef cdef_method(self):
""">>> add_log("cdef class method")"""
def __cinit__(self): def __cinit__(self):
""" """
Should not be included, as it can't be looked up with getattr Should not be included, as it can't be looked up with getattr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment