aboutsummaryrefslogtreecommitdiff
path: root/tools/patman/test_util.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-07-06 10:27:34 -0600
committerSimon Glass <sjg@chromium.org>2018-07-09 09:11:00 -0600
commitc3f9454103462e2cfcc5a9120b893f4ea250650a (patch)
tree951ff33957eefd047dfa91a2c435d7ccf6f1df1b /tools/patman/test_util.py
parentba765217ed0258fa0ecd5cb77c6c4c171624c4ad (diff)
downloadu-boot-c3f9454103462e2cfcc5a9120b893f4ea250650a.zip
u-boot-c3f9454103462e2cfcc5a9120b893f4ea250650a.tar.gz
u-boot-c3f9454103462e2cfcc5a9120b893f4ea250650a.tar.bz2
binman: Move capture_sys_output() to test_util
This function is useful in various tests. Move it into the common test utility module. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/test_util.py')
-rw-r--r--tools/patman/test_util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py
index 1a33c99..0e79af8 100644
--- a/tools/patman/test_util.py
+++ b/tools/patman/test_util.py
@@ -3,12 +3,19 @@
# Copyright (c) 2016 Google, Inc
#
+from contextlib import contextmanager
import glob
import os
import sys
import command
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+
def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None):
"""Run tests and check that we get 100% coverage
@@ -62,3 +69,17 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None):
ok = False
if not ok:
raise ValueError('Test coverage failure')
+
+
+# Use this to suppress stdout/stderr output:
+# with capture_sys_output() as (stdout, stderr)
+# ...do something...
+@contextmanager
+def capture_sys_output():
+ capture_out, capture_err = StringIO(), StringIO()
+ old_out, old_err = sys.stdout, sys.stderr
+ try:
+ sys.stdout, sys.stderr = capture_out, capture_err
+ yield capture_out, capture_err
+ finally:
+ sys.stdout, sys.stderr = old_out, old_err