Skip to content

Commit adac5f3

Browse files
committed
Tests: Fix error handler for reporting failed runs of scripts (issue #109)
1 parent d7f2ef4 commit adac5f3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/future/tests/base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ def mymin(numbers):
8888
return '\n'.join(new_lines)
8989

9090

91-
class FuturizeError(CalledProcessError):
92-
"""This exception is raised when a process run by check_call() or
93-
check_output() returns a non-zero exit status.
94-
The exit status will be stored in the returncode attribute;
95-
check_output() will also store the output in the output attribute.
91+
class VerboseCalledProcessError(CalledProcessError):
92+
"""
93+
Like CalledProcessError, but it displays more information (message and
94+
script output) for diagnosing test failures etc.
9695
"""
9796
def __init__(self, msg, returncode, cmd, output=None):
9897
self.msg = msg
@@ -104,9 +103,13 @@ def __str__(self):
104103
return ("Command '%s' failed with exit status %d\nMessage: %s\nOutput: %s"
105104
% (self.cmd, self.returncode, self.msg, self.output))
106105

107-
class PasteurizeError(FuturizeError):
106+
class FuturizeError(VerboseCalledProcessError):
107+
pass
108+
109+
class PasteurizeError(VerboseCalledProcessError):
108110
pass
109111

112+
110113
class CodeHandler(unittest.TestCase):
111114
"""
112115
Handy mixin for test classes for writing / reading / futurizing /
@@ -344,8 +347,7 @@ def _run_test_script(self, filename='mytestscript.py',
344347
'----\n%s\n----' % open(fn).read(),
345348
)
346349
)
347-
ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError)
348-
raise ErrorClass(msg, e.returncode, e.cmd)
350+
raise VerboseCalledProcessError(msg, e.returncode, e.cmd, output=e.output)
349351
return output
350352

351353

0 commit comments

Comments
 (0)