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