patman: Move capture_sys_output() into terminal and rename
This function is sometimes useful outside tests. Also it can affect how
terminal output is done, e.g. whether ANSI characters should be emitted
or not.
Move it out of the test_util package and into terminal.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py
index 4c415b7..2494a6b 100755
--- a/tools/binman/cbfs_util_test.py
+++ b/tools/binman/cbfs_util_test.py
@@ -20,6 +20,7 @@
from binman import cbfs_util
from binman.cbfs_util import CbfsWriter
from binman import elf
+from u_boot_pylib import terminal
from u_boot_pylib import test_util
from u_boot_pylib import tools
@@ -314,7 +315,7 @@
newdata = data[:-4] + struct.pack('<I', cbw._header_offset + 1)
# We should still be able to find the master header by searching
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
cbfs = cbfs_util.CbfsReader(newdata)
self.assertIn('Relative offset seems wrong', stdout.getvalue())
self.assertIn('u-boot', cbfs.files)
@@ -330,7 +331,7 @@
# Drop most of the header and try reading the modified CBFS
newdata = data[:cbw._header_offset + 4]
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
with self.assertRaises(ValueError) as e:
cbfs_util.CbfsReader(newdata)
self.assertIn('Relative offset seems wrong', stdout.getvalue())
@@ -351,7 +352,7 @@
# Remove all but 4 bytes of the file headerm and try to read the file
newdata = data[:pos + 4]
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
with io.BytesIO(newdata) as fd:
fd.seek(pos)
self.assertEqual(False, cbr._read_next_file(fd))
@@ -373,7 +374,7 @@
# Create a new CBFS with only the first 16 bytes of the file name, then
# try to read the file
newdata = data[:pos + cbfs_util.FILE_HEADER_LEN + 16]
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
with io.BytesIO(newdata) as fd:
fd.seek(pos)
self.assertEqual(False, cbr._read_next_file(fd))
@@ -389,7 +390,7 @@
try:
cbfs_util.DEBUG = True
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
cbfs_util.CbfsReader(data)
self.assertEqual('name u-boot\nftype 50\ndata %s\n' % U_BOOT_DATA,
stdout.getvalue())
@@ -416,7 +417,7 @@
# Create a new CBFS with the tag changed to something invalid
newdata = data[:pos] + struct.pack('>I', 0x123) + data[pos + 4:]
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
cbfs_util.CbfsReader(newdata)
self.assertEqual('Unknown attribute tag 123\n', stdout.getvalue())
@@ -441,7 +442,7 @@
tag_pos = (4 + pos + cbfs_util.FILE_HEADER_LEN +
cbfs_util.ATTRIBUTE_ALIGN)
newdata = data[:tag_pos + 4]
- with test_util.capture_sys_output() as (stdout, _stderr):
+ with terminal.capture() as (stdout, _stderr):
with io.BytesIO(newdata) as fd:
fd.seek(pos)
self.assertEqual(False, cbr._read_next_file(fd))