Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
8b5d1ff0
Commit
8b5d1ff0
authored
Oct 04, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extended TreePath test case, fix predicate evaluation
parent
6059a2ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
Cython/Compiler/Tests/TestTreePath.py
Cython/Compiler/Tests/TestTreePath.py
+31
-0
Cython/Compiler/TreePath.py
Cython/Compiler/TreePath.py
+2
-2
No files found.
Cython/Compiler/Tests/TestTreePath.py
View file @
8b5d1ff0
...
...
@@ -2,6 +2,7 @@ import unittest
from
Cython.Compiler.Visitor
import
PrintTree
from
Cython.TestUtils
import
TransformTest
from
Cython.Compiler.TreePath
import
find_first
,
find_all
from
Cython.Compiler
import
Nodes
,
ExprNodes
class
TestTreePath
(
TransformTest
):
_tree
=
None
...
...
@@ -24,6 +25,12 @@ class TestTreePath(TransformTest):
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//ReturnStatNode"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode//ReturnStatNode"
)))
def
test_node_path_star
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
10
,
len
(
find_all
(
t
,
"//*"
)))
self
.
assertEquals
(
8
,
len
(
find_all
(
t
,
"//DefNode//*"
)))
self
.
assertEquals
(
0
,
len
(
find_all
(
t
,
"//NameNode//*"
)))
def
test_node_path_attribute
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode/@name"
)))
...
...
@@ -34,9 +41,27 @@ class TestTreePath(TransformTest):
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode/ReturnStatNode/NameNode"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//ReturnStatNode/NameNode"
)))
def
test_node_path_node_predicate
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
0
,
len
(
find_all
(
t
,
"//DefNode[.//ForInStatNode]"
)))
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode]"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//ReturnStatNode[./NameNode]"
)))
self
.
assertEquals
(
Nodes
.
ReturnStatNode
,
type
(
find_first
(
t
,
"//ReturnStatNode[./NameNode]"
)))
def
test_node_path_node_predicate_step
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode]"
)))
self
.
assertEquals
(
8
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode]//*"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode]//ReturnStatNode"
)))
self
.
assertEquals
(
Nodes
.
ReturnStatNode
,
type
(
find_first
(
t
,
"//DefNode[.//NameNode]//ReturnStatNode"
)))
def
test_node_path_attribute_exists
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode[@name]"
)))
self
.
assertEquals
(
ExprNodes
.
NameNode
,
type
(
find_first
(
t
,
"//NameNode[@name]"
)))
def
test_node_path_attribute_exists_not
(
self
):
t
=
self
.
_build_tree
()
...
...
@@ -47,5 +72,11 @@ class TestTreePath(TransformTest):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//NameNode[@name = 'decorator']"
)))
def
test_node_path_recursive_predicate
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode[@name]]"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode[.//NameNode[@name = 'decorator']]"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode[.//ReturnStatNode[./NameNode[@name = 'fun']]/NameNode]"
)))
if
__name__
==
'__main__'
:
unittest
.
main
()
Cython/Compiler/TreePath.py
View file @
8b5d1ff0
...
...
@@ -54,7 +54,7 @@ def parse_func(next, token):
def handle_func_not(next, token):
"""
func
(...)
not
(...)
"""
name, predicate = parse_func(next, token)
...
...
@@ -196,7 +196,7 @@ def handle_predicate(next, token):
subresult = select(subresult)
predicate_result = _get_first_or_none(subresult)
if predicate_result is not None:
yield
predicate_result
yield
node
return select
operations = {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment