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
Kirill Smelkov
cython
Commits
8a365013
Commit
8a365013
authored
Jan 18, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up some test code and apply some safety fixes
parent
df86b715
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
+27
-19
Cython/TestUtils.py
Cython/TestUtils.py
+27
-19
No files found.
Cython/TestUtils.py
View file @
8a365013
...
@@ -8,13 +8,15 @@ import unittest
...
@@ -8,13 +8,15 @@ import unittest
import
os
,
sys
import
os
,
sys
import
tempfile
import
tempfile
class
NodeTypeWriter
(
TreeVisitor
):
class
NodeTypeWriter
(
TreeVisitor
):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
NodeTypeWriter
,
self
).
__init__
()
super
(
NodeTypeWriter
,
self
).
__init__
()
self
.
_indents
=
0
self
.
_indents
=
0
self
.
result
=
[]
self
.
result
=
[]
def
visit_Node
(
self
,
node
):
def
visit_Node
(
self
,
node
):
if
len
(
self
.
access_path
)
==
0
:
if
not
self
.
access_path
:
name
=
u"(root)"
name
=
u"(root)"
else
:
else
:
tip
=
self
.
access_path
[
-
1
]
tip
=
self
.
access_path
[
-
1
]
...
@@ -29,6 +31,7 @@ class NodeTypeWriter(TreeVisitor):
...
@@ -29,6 +31,7 @@ class NodeTypeWriter(TreeVisitor):
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
self
.
_indents
-=
1
self
.
_indents
-=
1
def
treetypes
(
root
):
def
treetypes
(
root
):
"""Returns a string representing the tree by class names.
"""Returns a string representing the tree by class names.
There's a leading and trailing whitespace so that it can be
There's a leading and trailing whitespace so that it can be
...
@@ -38,6 +41,7 @@ def treetypes(root):
...
@@ -38,6 +41,7 @@ def treetypes(root):
w
.
visit
(
root
)
w
.
visit
(
root
)
return
u"
\
n
"
.
join
([
u""
]
+
w
.
result
+
[
u""
])
return
u"
\
n
"
.
join
([
u""
]
+
w
.
result
+
[
u""
])
class
CythonTest
(
unittest
.
TestCase
):
class
CythonTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -110,6 +114,7 @@ class CythonTest(unittest.TestCase):
...
@@ -110,6 +114,7 @@ class CythonTest(unittest.TestCase):
except
:
except
:
self
.
fail
(
str
(
sys
.
exc_info
()[
1
]))
self
.
fail
(
str
(
sys
.
exc_info
()[
1
]))
class
TransformTest
(
CythonTest
):
class
TransformTest
(
CythonTest
):
"""
"""
Utility base class for transform unit tests. It is based around constructing
Utility base class for transform unit tests. It is based around constructing
...
@@ -134,7 +139,6 @@ class TransformTest(CythonTest):
...
@@ -134,7 +139,6 @@ class TransformTest(CythonTest):
Plans: One could have a pxd dictionary parameter to run_pipeline.
Plans: One could have a pxd dictionary parameter to run_pipeline.
"""
"""
def
run_pipeline
(
self
,
pipeline
,
pyx
,
pxds
=
{}):
def
run_pipeline
(
self
,
pipeline
,
pyx
,
pxds
=
{}):
tree
=
self
.
fragment
(
pyx
,
pxds
).
root
tree
=
self
.
fragment
(
pyx
,
pxds
).
root
# Run pipeline
# Run pipeline
...
@@ -166,6 +170,7 @@ class TreeAssertVisitor(VisitorTransform):
...
@@ -166,6 +170,7 @@ class TreeAssertVisitor(VisitorTransform):
visit_Node
=
VisitorTransform
.
recurse_to_children
visit_Node
=
VisitorTransform
.
recurse_to_children
def
unpack_source_tree
(
tree_file
,
dir
=
None
):
def
unpack_source_tree
(
tree_file
,
dir
=
None
):
if
dir
is
None
:
if
dir
is
None
:
dir
=
tempfile
.
mkdtemp
()
dir
=
tempfile
.
mkdtemp
()
...
@@ -176,21 +181,24 @@ def unpack_source_tree(tree_file, dir=None):
...
@@ -176,21 +181,24 @@ def unpack_source_tree(tree_file, dir=None):
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
finally
:
finally
:
f
.
close
()
f
.
close
()
f
=
None
del
f
for
line
in
lines
:
try
:
if
line
[:
5
]
==
'#####'
:
for
line
in
lines
:
filename
=
line
.
strip
().
strip
(
'#'
).
strip
().
replace
(
'/'
,
os
.
path
.
sep
)
if
line
[:
5
]
==
'#####'
:
path
=
os
.
path
.
join
(
dir
,
filename
)
filename
=
line
.
strip
().
strip
(
'#'
).
strip
().
replace
(
'/'
,
os
.
path
.
sep
)
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
path
=
os
.
path
.
join
(
dir
,
filename
)
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
if
cur_file
is
not
None
:
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
cur_file
.
close
()
if
cur_file
is
not
None
:
cur_file
=
open
(
path
,
'w'
)
f
,
cur_file
=
cur_file
,
None
elif
cur_file
is
not
None
:
f
.
close
()
cur_file
.
write
(
line
)
cur_file
=
open
(
path
,
'w'
)
elif
line
.
strip
()
and
not
line
.
lstrip
().
startswith
(
'#'
):
elif
cur_file
is
not
None
:
if
line
.
strip
()
not
in
(
'"""'
,
"'''"
):
cur_file
.
write
(
line
)
header
.
append
(
line
)
elif
line
.
strip
()
and
not
line
.
lstrip
().
startswith
(
'#'
):
if
cur_file
is
not
None
:
if
line
.
strip
()
not
in
(
'"""'
,
"'''"
):
cur_file
.
close
()
header
.
append
(
line
)
finally
:
if
cur_file
is
not
None
:
cur_file
.
close
()
return
dir
,
''
.
join
(
header
)
return
dir
,
''
.
join
(
header
)
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