diff options
author | Daniel Wakefield <daniel.wakefield@hp.com> | 2014-12-04 16:59:11 +0000 |
---|---|---|
committer | Daniel Wakefield <daniel.wakefield@hp.com> | 2014-12-05 10:57:09 +0000 |
commit | 49a80f734c5a4ec8cbc359c6fc8099ddfbdfc6ba (patch) | |
tree | 547ff28038ee8f327720d9d5e9c978515249e893 /tests/unit/utils.py | |
parent | d89e08f722f030925495a4180d2fe8422977841d (diff) | |
download | python-swiftclient-49a80f734c5a4ec8cbc359c6fc8099ddfbdfc6ba.tar.gz |
Change tests to use new CaptureOutput class.
Added the ability to clear the buffers in the
CaptureOutput class so it can be easily used multiple
times in the same context manager.
Also added a option to suppress the SystemExit
associated with printing an error.
Change-Id: Ib59bbbe88256f215eed0a8ebc8282e02181d4377
Diffstat (limited to 'tests/unit/utils.py')
-rw-r--r-- | tests/unit/utils.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 3cbb160..88a214d 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -238,17 +238,29 @@ class CaptureStream(object): def getvalue(self): return self._capture.getvalue() + def clear(self): + self._capture.truncate(0) + self._capture.seek(0) + class CaptureOutput(object): - def __init__(self): + def __init__(self, suppress_systemexit=False): self._out = CaptureStream(sys.stdout) self._err = CaptureStream(sys.stderr) + self.patchers = [] WrappedOutputManager = functools.partial(s.OutputManager, print_stream=self._out, error_stream=self._err) - self.patchers = [ + + if suppress_systemexit: + self.patchers += [ + mock.patch('swiftclient.shell.OutputManager.get_error_count', + return_value=0) + ] + + self.patchers += [ mock.patch('swiftclient.shell.OutputManager', WrappedOutputManager), mock.patch('sys.stdout', self._out), @@ -272,6 +284,10 @@ class CaptureOutput(object): def err(self): return self._err.getvalue() + def clear(self): + self._out.clear() + self._err.clear() + # act like the string captured by stdout def __str__(self): |