Commit 3f00253b authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fix doctesthack for cdef functions

parent 4c11531e
from Cython.Compiler.Visitor import VisitorTransform, ScopeTrackingTransform, TreeVisitor
from Nodes import StatListNode, SingleAssignmentNode
from Nodes import StatListNode, SingleAssignmentNode, CFuncDefNode
from ExprNodes import (DictNode, DictItemNode, NameNode, UnicodeNode, NoneNode,
ExprNode, AttributeNode, ModuleRefNode, DocstringRefNode)
from PyrexTypes import py_object_type
......@@ -53,6 +53,10 @@ class DoctestHackTransform(ScopeTrackingTransform):
def visit_FuncDefNode(self, node):
if node.doc:
if isinstance(node, CFuncDefNode) and not node.py_func:
# skip non-cpdef cdef functions
return node
pos = self.testspos
if self.scope_type == 'module':
parent = ModuleRefNode(pos)
......@@ -69,6 +73,8 @@ class DoctestHackTransform(ScopeTrackingTransform):
is_py_attr=True,
is_temp=True)
name = "%s.%s" % (clsname, node.entry.name)
else:
assert False
getfunc = AttributeNode(pos, obj=parent,
attribute=node.entry.name,
type=py_object_type,
......
#cython: doctesthack=True
# Directive defaults to True
"""
Tests doctesthack compiler directive.
......@@ -12,17 +12,25 @@ all_tests_run() is executed which does final validation.
>>> items.sort()
>>> for key, value in items:
... print key, ';', value
MyCdefClass.method (line 67) ; >>> add_log("cdef class method")
MyClass.method (line 57) ; >>> add_log("class method")
doc_without_test (line 39) ; Some docs
mycpdeffunc (line 45) ; >>> add_log("cpdef")
myfunc (line 36) ; >>> add_log("def")
MyCdefClass.method (line 75) ; >>> add_log("cdef class method")
MyClass.method (line 65) ; >>> add_log("class method")
doc_without_test (line 47) ; Some docs
mycpdeffunc (line 53) ; >>> add_log("cpdef")
myfunc (line 44) ; >>> add_log("def")
"""
log = []
cdef cdeffunc():
"""
Please don't include me!
>>> True
False
"""
def all_tests_run():
log.sort()
assert log == [u'cdef class method', u'class method', u'cpdef', u'def'], log
......
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