diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-12-30 21:28:43 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-12-30 21:28:43 +0000 |
commit | dfbb1807fb9ea041981193d05ada34da64afaeb2 (patch) | |
tree | 2c479fc38255445750d576cb8f040d3b57528845 /tests/unit/utils.py | |
parent | d59af8cc8b3f5ddf846046dd11029b84db4828ea (diff) | |
parent | 49a80f734c5a4ec8cbc359c6fc8099ddfbdfc6ba (diff) | |
download | python-swiftclient-dfbb1807fb9ea041981193d05ada34da64afaeb2.tar.gz |
Merge "Change tests to use new CaptureOutput class."
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): |