PEP-8-ified the decorator names for parse tree assertions, added a test case
authorStefan Behnel <scoder@users.berlios.de>
Sun, 4 Oct 2009 15:31:47 +0000 (17:31 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 4 Oct 2009 15:31:47 +0000 (17:31 +0200)
Cython/Compiler/Options.py
Cython/TestUtils.py
tests/errors/tree_assert.pyx [new file with mode: 0644]
tests/run/dictcomp.pyx
tests/run/enumerate_T316.pyx
tests/run/for_in_range_T372.pyx
tests/run/setcomp.pyx

index 9d1423d386445dbbabbb3176d720f3abd8492a80..99b7648558c8bfacf722f4cc1afabcad17ec5df2 100644 (file)
@@ -71,8 +71,8 @@ option_defaults = {
     'doctesthack': False,
 
 # test support
-    'testAssertPathExists' : [],
-    'testFailIfPathExists' : [],
+    'test_assert_path_exists' : [],
+    'test_fail_if_path_exists' : [],
 }
 
 # Override types possibilities above, if needed
@@ -85,8 +85,8 @@ for key, val in option_defaults.items():
 option_scopes = { # defaults to available everywhere
     # 'module', 'function', 'class', 'with statement'
     'doctesthack' : ('module',),
-    'testAssertPathExists' : ('function',),
-    'testFailIfPathExists' : ('function',),
+    'test_assert_path_exists' : ('function',),
+    'test_fail_if_path_exists' : ('function',),
 }
 
 def parse_option_value(name, value):
index a25933c802a818c17087c2c1a9e4aee038813a2f..bdd08a41ef5fca0c71ec262a0555f088fca8aa5d 100644 (file)
@@ -148,20 +148,18 @@ class TreeAssertVisitor(VisitorTransform):
 
     def visit_CompilerDirectivesNode(self, node):
         directives = node.directives
-        if 'testAssertPathExists' in directives:
-            for path in directives['testAssertPathExists']:
+        if 'test_assert_path_exists' in directives:
+            for path in directives['test_assert_path_exists']:
                 if TreePath.find_first(node, path) is None:
                     Errors.error(
                         node.pos,
-                        "Expected path '%s' not found in result tree of node %r" % (
-                        path, node.body))
-        if 'testFailIfPathExists' in directives:
-            for path in directives['testFailIfPathExists']:
+                        "Expected path '%s' not found in result tree" % path)
+        if 'test_fail_if_path_exists' in directives:
+            for path in directives['test_fail_if_path_exists']:
                 if TreePath.find_first(node, path) is not None:
                     Errors.error(
                         node.pos,
-                        "Unexpected path '%s' found in result tree of node %r" %  (
-                        path, node.body))
+                        "Unexpected path '%s' found in result tree" %  path)
         self.visitchildren(node)
         return node
 
diff --git a/tests/errors/tree_assert.pyx b/tests/errors/tree_assert.pyx
new file mode 100644 (file)
index 0000000..ef931b9
--- /dev/null
@@ -0,0 +1,17 @@
+
+cimport cython
+
+@cython.test_fail_if_path_exists("//SimpleCallNode",
+                                 "//NameNode")
+@cython.test_assert_path_exists("//ComprehensionNode",
+                                "//ComprehensionNode//FuncDefNode")
+def test():
+    object()
+
+
+_ERRORS = u"""
+8:0: Expected path '//ComprehensionNode' not found in result tree
+8:0: Expected path '//ComprehensionNode//FuncDefNode' not found in result tree
+8:0: Unexpected path '//NameNode' found in result tree
+8:0: Unexpected path '//SimpleCallNode' found in result tree
+"""
index b874163ed92ebaecfce569ee0e85e2e2b3f4eaba..02a2cbfeecdcaeaba3683d106a3abd13f25932e1 100644 (file)
@@ -22,10 +22,12 @@ def smoketest_dict():
              for x in range(5)
              if x % 2 == 0 }
 
-@cython.testFailIfPathExists("//ComprehensionNode//ComprehensionAppendNode",
-                             "//SimpleCallNode//ComprehensionNode")
-@cython.testAssertPathExists("//ComprehensionNode",
-                             "//ComprehensionNode//DictComprehensionAppendNode")
+@cython.test_fail_if_path_exists(
+    "//ComprehensionNode//ComprehensionAppendNode",
+    "//SimpleCallNode//ComprehensionNode")
+@cython.test_assert_path_exists(
+    "//ComprehensionNode",
+    "//ComprehensionNode//DictComprehensionAppendNode")
 def smoketest_list():
     return dict([ (x+2,x*2)
                   for x in range(5)
index 3380ccad18fabb7840f71729d535c3fcfc726e98..899adb9afc550505f54d334e19d70a25ae719b7d 100644 (file)
@@ -65,24 +65,24 @@ __doc__ = u"""
 
 cimport cython
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def go_py_enumerate():
     for i,k in enumerate(range(1,5)):
         print i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def go_c_enumerate():
     cdef int i,k
     for i,k in enumerate(range(1,5)):
         print i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def go_c_enumerate_step():
     cdef int i,k
     for i,k in enumerate(range(1,7,2)):
         print i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def py_enumerate_dict(dict d):
     cdef int i = 55
     k = 99
@@ -90,7 +90,7 @@ def py_enumerate_dict(dict d):
         print i, k
     print u"::", i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode")
 def py_enumerate_break(*t):
     i,k = 55,99
     for i,k in enumerate(t):
@@ -98,7 +98,7 @@ def py_enumerate_break(*t):
         break
     print u"::", i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode")
 def py_enumerate_return(*t):
     i,k = 55,99
     for i,k in enumerate(t):
@@ -106,7 +106,7 @@ def py_enumerate_return(*t):
         return
     print u"::", i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode")
 def py_enumerate_continue(*t):
     i,k = 55,99
     for i,k in enumerate(t):
@@ -114,7 +114,7 @@ def py_enumerate_continue(*t):
         continue
     print u"::", i, k
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def empty_c_enumerate():
     cdef int i = 55, k = 99
     for i,k in enumerate(range(0)):
@@ -126,12 +126,12 @@ def single_target_enumerate():
     for t in enumerate(range(1,5)):
         print t[0], t[1]
 
-@cython.testFailIfPathExists("//SimpleCallNode//NameNode[@name = 'enumerate']")
+@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
 def multi_enumerate():
     for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))):
         print a,b,c,d
 
-@cython.testFailIfPathExists("//SimpleCallNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode")
 def multi_c_enumerate():
     cdef int a,b,c,d
     for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))):
index 91c60bf44287f5653624e275390a8cfde4d28431..ce2a92d46a62977bd2d0de0a3fdd8f862a9a348a 100644 (file)
@@ -15,8 +15,8 @@ __doc__ = u"""
 
 cimport cython
 
-@cython.testAssertPathExists("//ForFromStatNode")
-@cython.testFailIfPathExists("//ForInStatNode")
+@cython.test_assert_path_exists("//ForFromStatNode")
+@cython.test_fail_if_path_exists("//ForInStatNode")
 def test_modify():
     cdef int i, n = 5
     for i in range(n):
@@ -25,8 +25,8 @@ def test_modify():
     print
     return i,n
 
-@cython.testAssertPathExists("//ForFromStatNode")
-@cython.testFailIfPathExists("//ForInStatNode")
+@cython.test_assert_path_exists("//ForFromStatNode")
+@cython.test_fail_if_path_exists("//ForInStatNode")
 def test_fix():
     cdef int i
     for i in range(5):
@@ -34,8 +34,8 @@ def test_fix():
     print
     return i
 
-@cython.testAssertPathExists("//ForFromStatNode")
-@cython.testFailIfPathExists("//ForInStatNode")
+@cython.test_assert_path_exists("//ForFromStatNode")
+@cython.test_fail_if_path_exists("//ForInStatNode")
 def test_break():
     cdef int i, n = 5
     for i in range(n):
@@ -46,8 +46,8 @@ def test_break():
     print
     return i,n
 
-@cython.testAssertPathExists("//ForFromStatNode")
-@cython.testFailIfPathExists("//ForInStatNode")
+@cython.test_assert_path_exists("//ForFromStatNode")
+@cython.test_fail_if_path_exists("//ForInStatNode")
 def test_return():
     cdef int i, n = 5
     for i in range(n):
index 906686207d2320e424c6d93bec033c075ef90444..38398c104938cff12f9540e72e1cef1a6f115138 100644 (file)
@@ -27,9 +27,9 @@ def smoketest_set():
              for x in range(5)
              if x % 2 == 0 }
 
-@cython.testFailIfPathExists("//SimpleCallNode//ComprehensionNode")
-@cython.testAssertPathExists("//ComprehensionNode",
-                             "//ComprehensionNode//ComprehensionAppendNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode//ComprehensionNode")
+@cython.test_assert_path_exists("//ComprehensionNode",
+                                "//ComprehensionNode//ComprehensionAppendNode")
 def smoketest_list():
     return set([ x*2
                  for x in range(5)