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/bintool_test.py b/tools/binman/bintool_test.py
index 949d6f4..7e8dafe 100644
--- a/tools/binman/bintool_test.py
+++ b/tools/binman/bintool_test.py
@@ -55,14 +55,14 @@
def test_version(self):
"""Check handling of a tool being present or absent"""
btest = Bintool.create('_testing')
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
btest.show()
self.assertFalse(btest.is_present())
self.assertIn('-', stdout.getvalue())
btest.present = True
self.assertTrue(btest.is_present())
self.assertEqual('123', btest.version())
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
btest.show()
self.assertIn('123', stdout.getvalue())
@@ -90,7 +90,7 @@
col = terminal.Color()
with unittest.mock.patch.object(tools, 'download',
side_effect=fake_download):
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
btest.fetch_tool(method, col, False)
return stdout.getvalue()
@@ -144,7 +144,7 @@
with unittest.mock.patch.object(bintool.Bintool, 'tooldir', destdir):
with unittest.mock.patch.object(tools, 'download',
side_effect=handle_download):
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
Bintool.fetch_tools(bintool.FETCH_ANY, ['_testing'] * 2)
self.assertTrue(os.path.exists(dest_fname))
data = tools.read_file(dest_fname)
@@ -177,7 +177,7 @@
self.count = collections.defaultdict(int)
with unittest.mock.patch.object(bintool.Bintool, 'fetch_tool',
side_effect=fake_fetch):
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
Bintool.fetch_tools(method, ['all'])
lines = stdout.getvalue().splitlines()
self.assertIn(f'{self.count[bintool.FETCHED]}: ', lines[-2])
@@ -220,7 +220,7 @@
side_effect=[all_tools]):
with unittest.mock.patch.object(bintool.Bintool, 'create',
side_effect=self.btools.values()):
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
Bintool.fetch_tools(bintool.FETCH_ANY, ['missing'])
lines = stdout.getvalue().splitlines()
num_tools = len(self.btools)
@@ -255,7 +255,7 @@
with unittest.mock.patch.object(bintool.Bintool, 'tooldir',
self._indir):
with unittest.mock.patch.object(tools, 'run', side_effect=fake_run):
- with test_util.capture_sys_output() as (stdout, _):
+ with terminal.capture() as (stdout, _):
btest.fetch_tool(bintool.FETCH_BUILD, col, False)
fname = os.path.join(self._indir, '_testing')
return fname if write_file else self.fname, stdout.getvalue()
@@ -278,7 +278,7 @@
btest.install = True
col = terminal.Color()
with unittest.mock.patch.object(tools, 'run', return_value=None):
- with test_util.capture_sys_output() as _:
+ with terminal.capture() as _:
result = btest.fetch_tool(bintool.FETCH_BIN, col, False)
self.assertEqual(bintool.FETCHED, result)
@@ -287,7 +287,7 @@
btest = Bintool.create('_testing')
btest.disable = True
col = terminal.Color()
- with test_util.capture_sys_output() as _:
+ with terminal.capture() as _:
result = btest.fetch_tool(bintool.FETCH_BIN, col, False)
self.assertEqual(bintool.FAIL, result)
@@ -314,7 +314,7 @@
with unittest.mock.patch.object(tools, 'run', side_effect=fake_run):
with unittest.mock.patch.object(tools, 'download',
side_effect=handle_download):
- with test_util.capture_sys_output() as _:
+ with terminal.capture() as _:
for name in Bintool.get_tool_list():
btool = Bintool.create(name)
for method in range(bintool.FETCH_COUNT):