diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
commit | 9e44a205fbec7fd83ff4c41fa17a7e4c049ef1ba (patch) | |
tree | befe94e0de99d3994ee0c9b06ffa2862df830e38 /tests/testutils | |
parent | 6382d56b09f88a1d9d62baf8c7969703126b6672 (diff) |
test_supercommand: test --list-cmds
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/__init__.py | 5 | ||||
-rw-r--r-- | tests/testutils/capture.py | 30 |
2 files changed, 30 insertions, 5 deletions
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py index cc5e4cb4..a4f52437 100644 --- a/tests/testutils/__init__.py +++ b/tests/testutils/__init__.py @@ -15,10 +15,11 @@ from gbp.deb.changelog import ChangeLog from . gbplogtester import GbpLogTester from . debiangittestrepo import DebianGitTestRepo -from . capture import capture_stderr +from . capture import capture_stdout, capture_stderr __all__ = ['GbpLogTester', 'DebianGitTestRepo', 'OsReleaseFile', - 'MockedChangeLog', 'get_dch_default_urgency', 'capture_stderr', + 'MockedChangeLog', 'get_dch_default_urgency', + 'capture_stderr', 'capture_stdout', 'ls_dir', 'ls_tar', 'ls_zip'] diff --git a/tests/testutils/capture.py b/tests/testutils/capture.py index 31621f39..94aeac65 100644 --- a/tests/testutils/capture.py +++ b/tests/testutils/capture.py @@ -5,9 +5,9 @@ from contextlib import contextmanager from six import StringIO -class StderrCapture(StringIO): +class _StderrCapture(StringIO): def save(self): - self.safed = sys.stderr + self.safed = sys.stdout sys.stderr = self def restore(self): @@ -20,10 +20,34 @@ class StderrCapture(StringIO): return self.read() +class _StdoutCapture(StringIO): + def save(self): + self.safed = sys.stdout + sys.stdout = self + + def restore(self): + if self.safed is not None: + sys.stdout = self.safed + self.safed = None + + def output(self): + self.seek(0) + return self.read() + + @contextmanager def capture_stderr(): """Capture an output and return its content""" - c = StderrCapture() + c = _StderrCapture() + c.save() + yield c + c.restore() + + +@contextmanager +def capture_stdout(): + """Capture an output and return its content""" + c = _StdoutCapture() c.save() yield c c.restore() |