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
be4f9fb5
Commit
be4f9fb5
authored
Mar 28, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor code cleanups
parent
642b09e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
Cython/TestUtils.py
Cython/TestUtils.py
+21
-15
No files found.
Cython/TestUtils.py
View file @
be4f9fb5
import
Cython.Compiler.Errors
as
Errors
from
__future__
import
absolute_import
from
Cython.CodeWriter
import
CodeWriter
from
Cython.Compiler.TreeFragment
import
TreeFragment
,
strip_common_indent
from
Cython.Compiler.Visitor
import
TreeVisitor
,
VisitorTransform
from
Cython.Compiler
import
TreePath
import
os
import
unittest
import
unittest
import
os
,
sys
import
tempfile
import
tempfile
from
.Compiler
import
Errors
from
.CodeWriter
import
CodeWriter
from
.Compiler.TreeFragment
import
TreeFragment
,
strip_common_indent
from
.Compiler.Visitor
import
TreeVisitor
,
VisitorTransform
from
.Compiler
import
TreePath
class
NodeTypeWriter
(
TreeVisitor
):
class
NodeTypeWriter
(
TreeVisitor
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -55,12 +57,15 @@ class CythonTest(unittest.TestCase):
...
@@ -55,12 +57,15 @@ class CythonTest(unittest.TestCase):
def
assertLines
(
self
,
expected
,
result
):
def
assertLines
(
self
,
expected
,
result
):
"Checks that the given strings or lists of strings are equal line by line"
"Checks that the given strings or lists of strings are equal line by line"
if
not
isinstance
(
expected
,
list
):
expected
=
expected
.
split
(
u"
\
n
"
)
if
not
isinstance
(
expected
,
list
):
if
not
isinstance
(
result
,
list
):
result
=
result
.
split
(
u"
\
n
"
)
expected
=
expected
.
split
(
u"
\
n
"
)
if
not
isinstance
(
result
,
list
):
result
=
result
.
split
(
u"
\
n
"
)
for
idx
,
(
expected_line
,
result_line
)
in
enumerate
(
zip
(
expected
,
result
)):
for
idx
,
(
expected_line
,
result_line
)
in
enumerate
(
zip
(
expected
,
result
)):
self
.
assertEqual
(
expected_line
,
result_line
,
"Line %d:
\
n
Exp: %s
\
n
Got: %s"
%
(
idx
,
expected_line
,
result_line
))
self
.
assertEqual
(
expected_line
,
result_line
,
"Line %d:
\
n
Exp: %s
\
n
Got: %s"
%
(
idx
,
expected_line
,
result_line
))
self
.
assertEqual
(
len
(
expected
),
len
(
result
),
self
.
assertEqual
(
len
(
expected
),
len
(
result
),
"Unmatched lines. Got:
\
n
%s
\
n
Expected:
\
n
%s"
%
(
"
\
n
"
.
join
(
expected
),
u"
\
n
"
.
join
(
result
)))
"Unmatched lines. Got:
\
n
%s
\
n
Expected:
\
n
%s"
%
(
"
\
n
"
.
join
(
expected
),
u"
\
n
"
.
join
(
result
)))
def
codeToLines
(
self
,
tree
):
def
codeToLines
(
self
,
tree
):
writer
=
CodeWriter
()
writer
=
CodeWriter
()
...
@@ -76,9 +81,10 @@ class CythonTest(unittest.TestCase):
...
@@ -76,9 +81,10 @@ class CythonTest(unittest.TestCase):
expected_lines
=
strip_common_indent
(
expected
.
split
(
"
\
n
"
))
expected_lines
=
strip_common_indent
(
expected
.
split
(
"
\
n
"
))
for
idx
,
(
line
,
expected_line
)
in
enumerate
(
zip
(
result_lines
,
expected_lines
)):
for
idx
,
(
line
,
expected_line
)
in
enumerate
(
zip
(
result_lines
,
expected_lines
)):
self
.
assertEqual
(
expected_line
,
line
,
"Line %d:
\
n
Got: %s
\
n
Exp: %s"
%
(
idx
,
line
,
expected_line
))
self
.
assertEqual
(
expected_line
,
line
,
"Line %d:
\
n
Got: %s
\
n
Exp: %s"
%
(
idx
,
line
,
expected_line
))
self
.
assertEqual
(
len
(
result_lines
),
len
(
expected_lines
),
self
.
assertEqual
(
len
(
result_lines
),
len
(
expected_lines
),
"Unmatched lines. Got:
\
n
%s
\
n
Expected:
\
n
%s"
%
(
"
\
n
"
.
join
(
result_lines
),
expected
))
"Unmatched lines. Got:
\
n
%s
\
n
Expected:
\
n
%s"
%
(
"
\
n
"
.
join
(
result_lines
),
expected
))
def
assertNodeExists
(
self
,
path
,
result_tree
):
def
assertNodeExists
(
self
,
path
,
result_tree
):
self
.
assertNotEqual
(
TreePath
.
find_first
(
result_tree
,
path
),
None
,
self
.
assertNotEqual
(
TreePath
.
find_first
(
result_tree
,
path
),
None
,
...
@@ -107,7 +113,7 @@ class CythonTest(unittest.TestCase):
...
@@ -107,7 +113,7 @@ class CythonTest(unittest.TestCase):
func
()
func
()
self
.
fail
(
"Expected an exception of type %r"
%
exc_type
)
self
.
fail
(
"Expected an exception of type %r"
%
exc_type
)
except
exc_type
as
e
:
except
exc_type
as
e
:
self
.
assert
_
(
isinstance
(
e
,
exc_type
))
self
.
assert
True
(
isinstance
(
e
,
exc_type
))
return
e
return
e
def
should_not_fail
(
self
,
func
):
def
should_not_fail
(
self
,
func
):
...
@@ -116,8 +122,8 @@ class CythonTest(unittest.TestCase):
...
@@ -116,8 +122,8 @@ class CythonTest(unittest.TestCase):
the return value of func."""
the return value of func."""
try
:
try
:
return
func
()
return
func
()
except
:
except
Exception
as
exc
:
self
.
fail
(
str
(
sys
.
exc_info
()[
1
]
))
self
.
fail
(
str
(
exc
))
class
TransformTest
(
CythonTest
):
class
TransformTest
(
CythonTest
):
...
...
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