summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2020-05-19 09:12:56 +0100
committerGitHub <noreply@github.com>2020-05-19 10:12:56 +0200
commit6d83a741e0d083f07be87aa52970fa2fadf001b6 (patch)
tree4d661e6b8d8c2ee7ab9fa8d131a6bf779e76c4c7
parent2ffcb6a0a9b5145ad985abd23527204477f21788 (diff)
downloadcython-6d83a741e0d083f07be87aa52970fa2fadf001b6.tar.gz
Fixed "test_*_path_exists" + CompilerDirectivesNode (GH-3619)
When test_assert_path_exists or test_fail_if_path_exists was used on a function containing a CompilerDirectivesNode it was inherited by that CompilerDirectivesNode. Therefore you got misleading test failures if the path was in the function but not within that CompilerDirectivesNode.
-rw-r--r--Cython/Compiler/ParseTreeTransforms.py4
-rw-r--r--tests/compile/tree_assertions.pyx20
2 files changed, 24 insertions, 0 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
index 01cc71569..7a068ec04 100644
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -993,6 +993,10 @@ class InterpretCompilerDirectives(CythonTransform):
old_directives = self.directives
new_directives = dict(old_directives)
+ # test_assert_path_exists and test_fail_if_path_exists should not be inherited
+ # otherwise they can produce very misleading test failures
+ new_directives.pop('test_assert_path_exists', None)
+ new_directives.pop('test_fail_if_path_exists', None)
new_directives.update(directives)
if new_directives == old_directives:
diff --git a/tests/compile/tree_assertions.pyx b/tests/compile/tree_assertions.pyx
new file mode 100644
index 000000000..e311bfd25
--- /dev/null
+++ b/tests/compile/tree_assertions.pyx
@@ -0,0 +1,20 @@
+# mode: compile
+
+# This is a sort of meta test - to test the functionality of "test_assert_path_exists"
+
+cimport cython
+
+@cython.test_assert_path_exists("//ReturnStatNode")
+def not_in_inner_compiler_directives():
+ # used to fail because ReturnStatNode wasn't in *this* CompilerDirectivesNode
+ with cython.boundscheck(False):
+ pass
+ return 1 # should pass
+
+@cython.test_assert_path_exists("//ReturnStatNode")
+def in_inner_compiler_directives():
+ # used to fail because ReturnStatNode wasn't in *this* CompilerDirectivesNode
+ with cython.boundscheck(False):
+ return 1
+
+# it's hard to come up with a corresponding test for fail_if_path_exists..