[PATCH v3 05/29] patman: Use capture_sys_output() consistently

Simon Glass sjg at chromium.org
Fri Oct 30 14:46:14 AEDT 2020


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 at chromium.org>
---

(no changes since v1)

 tools/patman/func_test.py | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index 7fffe649974..263cb340ef5 100644
--- a/tools/patman/func_test.py
+++ b/tools/patman/func_test.py
@@ -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
 
 
- at 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])
-- 
2.29.1.341.ge80a0c044ae-goog



More information about the Patchwork mailing list