patman: Use capture_sys_output() consistently
authorSimon Glass <sjg@chromium.org>
Fri, 30 Oct 2020 03:46:14 +0000 (21:46 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 5 Nov 2020 16:11:31 +0000 (09:11 -0700)
One test still uses its own function for capturing output. Modify it to
use the standard one in test_util

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/patman/func_test.py

index 7fffe64..263cb34 100644 (file)
@@ -4,7 +4,6 @@
 # Copyright 2017 Google, Inc
 #
 
-import contextlib
 import os
 import re
 import shutil
@@ -12,8 +11,6 @@ import sys
 import tempfile
 import unittest
 
-from io import StringIO
-
 from patman import control
 from patman import gitutil
 from patman import patchstream
@@ -29,19 +26,6 @@ except ModuleNotFoundError:
     HAVE_PYGIT2 = False
 
 
-@contextlib.contextmanager
-def capture():
-    oldout, olderr = sys.stdout, sys.stderr
-    try:
-        out = [StringIO(), StringIO()]
-        sys.stdout, sys.stderr = out
-        yield out
-    finally:
-        sys.stdout, sys.stderr = oldout, olderr
-        out[0] = out[0].getvalue()
-        out[1] = out[1].getvalue()
-
-
 class TestFunctional(unittest.TestCase):
     def setUp(self):
         self.tmpdir = tempfile.mkdtemp(prefix='patman.')
@@ -169,7 +153,7 @@ class TestFunctional(unittest.TestCase):
         text = self.GetText('test01.txt')
         series = patchstream.GetMetaDataForTest(text)
         cover_fname, args = self.CreatePatchesForTest(series)
-        with capture() as out:
+        with capture_sys_output() as out:
             patchstream.FixPatches(series, args)
             if cover_fname and series.get('cover'):
                 patchstream.InsertCoverLetter(cover_fname, series, count)
@@ -184,7 +168,7 @@ class TestFunctional(unittest.TestCase):
         cc_lines = open(cc_file, encoding='utf-8').read().splitlines()
         os.remove(cc_file)
 
-        lines = out[0].splitlines()
+        lines = out[0].getvalue().splitlines()
         self.assertEqual('Cleaned %s patches' % len(series.commits), lines[0])
         self.assertEqual('Change log missing for v2', lines[1])
         self.assertEqual('Change log missing for v3', lines[2])