aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/testutils/capture.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-12-26 20:15:17 +0100
committerGuido Günther <agx@sigxcpu.org>2016-12-26 20:15:17 +0100
commit9e44a205fbec7fd83ff4c41fa17a7e4c049ef1ba (patch)
treebefe94e0de99d3994ee0c9b06ffa2862df830e38 /tests/testutils/capture.py
parent6382d56b09f88a1d9d62baf8c7969703126b6672 (diff)
test_supercommand: test --list-cmds
Diffstat (limited to 'tests/testutils/capture.py')
-rw-r--r--tests/testutils/capture.py30
1 files changed, 27 insertions, 3 deletions
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()