Commit 411a6354 authored by Stefan Behnel's avatar Stefan Behnel

simpler test

parent 2787ac2a
...@@ -4,53 +4,37 @@ from Cython.TestUtils import TransformTest ...@@ -4,53 +4,37 @@ from Cython.TestUtils import TransformTest
from Cython.Compiler.TreePath import find_first, find_all from Cython.Compiler.TreePath import find_first, find_all
class TestTreePath(TransformTest): class TestTreePath(TransformTest):
_tree = None
def test_node_path(self): def _build_tree(self):
t = self.run_pipeline([], u""" if self._tree is None:
self._tree = self.run_pipeline([], u"""
def decorator(fun): # DefNode def decorator(fun): # DefNode
return fun # ReturnStatNode, NameNode return fun # ReturnStatNode, NameNode
@decorator # NameNode @decorator # NameNode
def decorated(): # DefNode def decorated(): # DefNode
pass pass
""") """)
return self._tree
def test_node_path(self):
t = self._build_tree()
self.assertEquals(2, len(find_all(t, "//DefNode"))) self.assertEquals(2, len(find_all(t, "//DefNode")))
self.assertEquals(2, len(find_all(t, "//NameNode"))) self.assertEquals(2, len(find_all(t, "//NameNode")))
self.assertEquals(1, len(find_all(t, "//ReturnStatNode"))) self.assertEquals(1, len(find_all(t, "//ReturnStatNode")))
self.assertEquals(1, len(find_all(t, "//DefNode//ReturnStatNode"))) self.assertEquals(1, len(find_all(t, "//DefNode//ReturnStatNode")))
def test_node_path_child(self): def test_node_path_child(self):
t = self.run_pipeline([], u""" t = self._build_tree()
def decorator(fun): # DefNode
return fun # ReturnStatNode, NameNode
@decorator # NameNode
def decorated(): # DefNode
pass
""")
self.assertEquals(1, len(find_all(t, "//DefNode/ReturnStatNode/NameNode"))) self.assertEquals(1, len(find_all(t, "//DefNode/ReturnStatNode/NameNode")))
self.assertEquals(1, len(find_all(t, "//ReturnStatNode/NameNode"))) self.assertEquals(1, len(find_all(t, "//ReturnStatNode/NameNode")))
def test_node_path_attribute_exists(self): def test_node_path_attribute_exists(self):
t = self.run_pipeline([], u""" t = self._build_tree()
def decorator(fun):
return fun
@decorator
def decorated():
pass
""")
self.assertEquals(2, len(find_all(t, "//NameNode[@name]"))) self.assertEquals(2, len(find_all(t, "//NameNode[@name]")))
def test_node_path_attribute_string_predicate(self): def test_node_path_attribute_string_predicate(self):
t = self.run_pipeline([], u""" t = self._build_tree()
def decorator(fun):
return fun
@decorator
def decorated():
pass
""")
self.assertEquals(1, len(find_all(t, "//NameNode[@name = 'decorator']"))) self.assertEquals(1, len(find_all(t, "//NameNode[@name = 'decorator']")))
if __name__ == '__main__': if __name__ == '__main__':
......
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