summaryrefslogtreecommitdiff
path: root/tools/binman/elf_test.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-07-06 10:27:34 -0600
committerSimon Glass <sjg@chromium.org>2018-07-09 09:11:00 -0600
commitc3f9454103462e2cfcc5a9120b893f4ea250650a (patch)
tree951ff33957eefd047dfa91a2c435d7ccf6f1df1b /tools/binman/elf_test.py
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/binman/elf_test.py')
-rw-r--r--tools/binman/elf_test.py22
1 files changed, 2 insertions, 20 deletions
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index fb6e451cf0..9c8f1feca8 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -4,33 +4,15 @@
#
# Test for the elf module
-from contextlib import contextmanager
import os
import sys
import unittest
-try:
- from StringIO import StringIO
-except ImportError:
- from io import StringIO
-
import elf
+import test_util
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
-# 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
-
class FakeEntry:
def __init__(self, contents_size):
@@ -110,7 +92,7 @@ class TestElf(unittest.TestCase):
entry = FakeEntry(20)
section = FakeSection()
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
- with capture_sys_output() as (stdout, stderr):
+ with test_util.capture_sys_output() as (stdout, stderr):
syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
elf.debug = False
self.assertTrue(len(stdout.getvalue()) > 0)