summaryrefslogtreecommitdiff
path: root/Cython/TestUtils.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2016-03-28 16:51:29 +0200
committerStefan Behnel <stefan_ml@behnel.de>2016-03-28 16:53:22 +0200
commitbe4f9fb5d779f4176447e0dc651b4905a9e00d82 (patch)
tree688e9b96878c215dbfe00ef670a3e7b0428172ce /Cython/TestUtils.py
parent642b09e7023e4898728227913e49c38b1ed8b930 (diff)
downloadcython-be4f9fb5d779f4176447e0dc651b4905a9e00d82.tar.gz
minor code cleanups
Diffstat (limited to 'Cython/TestUtils.py')
-rw-r--r--Cython/TestUtils.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/Cython/TestUtils.py b/Cython/TestUtils.py
index eb1ed571b..9d6eb67fc 100644
--- a/Cython/TestUtils.py
+++ b/Cython/TestUtils.py
@@ -1,13 +1,15 @@
-import Cython.Compiler.Errors as Errors
-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
+from __future__ import absolute_import
+import os
import unittest
-import os, sys
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):
def __init__(self):
@@ -55,12 +57,15 @@ class CythonTest(unittest.TestCase):
def assertLines(self, expected, result):
"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(result, list): result = result.split(u"\n")
+ if not isinstance(expected, list):
+ 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)):
- self.assertEqual(expected_line, result_line, "Line %d:\nExp: %s\nGot: %s" % (idx, expected_line, result_line))
+ self.assertEqual(expected_line, result_line,
+ "Line %d:\nExp: %s\nGot: %s" % (idx, expected_line, result_line))
self.assertEqual(len(expected), len(result),
- "Unmatched lines. Got:\n%s\nExpected:\n%s" % ("\n".join(expected), u"\n".join(result)))
+ "Unmatched lines. Got:\n%s\nExpected:\n%s" % ("\n".join(expected), u"\n".join(result)))
def codeToLines(self, tree):
writer = CodeWriter()
@@ -76,9 +81,10 @@ class CythonTest(unittest.TestCase):
expected_lines = strip_common_indent(expected.split("\n"))
for idx, (line, expected_line) in enumerate(zip(result_lines, expected_lines)):
- self.assertEqual(expected_line, line, "Line %d:\nGot: %s\nExp: %s" % (idx, line, expected_line))
+ self.assertEqual(expected_line, line,
+ "Line %d:\nGot: %s\nExp: %s" % (idx, line, expected_line))
self.assertEqual(len(result_lines), len(expected_lines),
- "Unmatched lines. Got:\n%s\nExpected:\n%s" % ("\n".join(result_lines), expected))
+ "Unmatched lines. Got:\n%s\nExpected:\n%s" % ("\n".join(result_lines), expected))
def assertNodeExists(self, path, result_tree):
self.assertNotEqual(TreePath.find_first(result_tree, path), None,
@@ -107,7 +113,7 @@ class CythonTest(unittest.TestCase):
func()
self.fail("Expected an exception of type %r" % exc_type)
except exc_type as e:
- self.assert_(isinstance(e, exc_type))
+ self.assertTrue(isinstance(e, exc_type))
return e
def should_not_fail(self, func):
@@ -116,8 +122,8 @@ class CythonTest(unittest.TestCase):
the return value of func."""
try:
return func()
- except:
- self.fail(str(sys.exc_info()[1]))
+ except Exception as exc:
+ self.fail(str(exc))
class TransformTest(CythonTest):