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
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
import
os
,
sys
import
tempfile
class
NodeTypeWriter
(
TreeVisitor
):
def
__init__
(
self
):
super
(
NodeTypeWriter
,
self
).
__init__
()
self
.
_indents
=
0
self
.
result
=
[]
def
visit_Node
(
self
,
node
):
if
len
(
self
.
access_path
)
==
0
:
if
not
self
.
access_path
:
name
=
u"(root)"
else
:
tip
=
self
.
access_path
[
-
1
]
...
...
@@ -29,6 +31,7 @@ class NodeTypeWriter(TreeVisitor):
self
.
visitchildren
(
node
)
self
.
_indents
-=
1
def
treetypes
(
root
):
"""Returns a string representing the tree by class names.
There's a leading and trailing whitespace so that it can be
...
...
@@ -38,6 +41,7 @@ def treetypes(root):
w
.
visit
(
root
)
return
u"
\
n
"
.
join
([
u""
]
+
w
.
result
+
[
u""
])
class
CythonTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -110,6 +114,7 @@ class CythonTest(unittest.TestCase):
except
:
self
.
fail
(
str
(
sys
.
exc_info
()[
1
]))
class
TransformTest
(
CythonTest
):
"""
Utility base class for transform unit tests. It is based around constructing
...
...
@@ -134,7 +139,6 @@ class TransformTest(CythonTest):
Plans: One could have a pxd dictionary parameter to run_pipeline.
"""
def
run_pipeline
(
self
,
pipeline
,
pyx
,
pxds
=
{}):
tree
=
self
.
fragment
(
pyx
,
pxds
).
root
# Run pipeline
...
...
@@ -166,6 +170,7 @@ class TreeAssertVisitor(VisitorTransform):
visit_Node
=
VisitorTransform
.
recurse_to_children
def
unpack_source_tree
(
tree_file
,
dir
=
None
):
if
dir
is
None
:
dir
=
tempfile
.
mkdtemp
()
...
...
@@ -176,21 +181,24 @@ def unpack_source_tree(tree_file, dir=None):
lines
=
f
.
readlines
()
finally
:
f
.
close
()
f
=
None
for
line
in
lines
:
if
line
[:
5
]
==
'#####'
:
filename
=
line
.
strip
().
strip
(
'#'
).
strip
().
replace
(
'/'
,
os
.
path
.
sep
)
path
=
os
.
path
.
join
(
dir
,
filename
)
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
if
cur_file
is
not
None
:
cur_file
.
close
()
cur_file
=
open
(
path
,
'w'
)
elif
cur_file
is
not
None
:
cur_file
.
write
(
line
)
elif
line
.
strip
()
and
not
line
.
lstrip
().
startswith
(
'#'
):
if
line
.
strip
()
not
in
(
'"""'
,
"'''"
):
header
.
append
(
line
)
if
cur_file
is
not
None
:
cur_file
.
close
()
del
f
try
:
for
line
in
lines
:
if
line
[:
5
]
==
'#####'
:
filename
=
line
.
strip
().
strip
(
'#'
).
strip
().
replace
(
'/'
,
os
.
path
.
sep
)
path
=
os
.
path
.
join
(
dir
,
filename
)
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
if
cur_file
is
not
None
:
f
,
cur_file
=
cur_file
,
None
f
.
close
()
cur_file
=
open
(
path
,
'w'
)
elif
cur_file
is
not
None
:
cur_file
.
write
(
line
)
elif
line
.
strip
()
and
not
line
.
lstrip
().
startswith
(
'#'
):
if
line
.
strip
()
not
in
(
'"""'
,
"'''"
):
header
.
append
(
line
)
finally
:
if
cur_file
is
not
None
:
cur_file
.
close
()
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