aboutsummaryrefslogtreecommitdiff
path: root/tools/patman
diff options
context:
space:
mode:
authorSimon Glass2018-07-06 10:27:34 -0600
committerSimon Glass2018-07-09 09:11:00 -0600
commitc3f9454103462e2cfcc5a9120b893f4ea250650a (patch)
tree951ff33957eefd047dfa91a2c435d7ccf6f1df1b /tools/patman
parentba765217ed0258fa0ecd5cb77c6c4c171624c4ad (diff)
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')
-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 1a33c997c4c..0e79af871ab 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