u_boot_pylib: Correct case for test_result

This should be in capitals and defined at the start of the file. Update
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2025-02-03 09:26:42 -07:00 committed by Tom Rini
parent 752321b625
commit d6900a778a
3 changed files with 23 additions and 24 deletions

View file

@ -303,7 +303,7 @@ class TestFunctional(unittest.TestCase):
def setUp(self): def setUp(self):
# Enable this to turn on debugging output # Enable this to turn on debugging output
# tout.init(tout.DEBUG) # tout.init(tout.DEBUG)
command.test_result = None command.TEST_RESULT = None
def tearDown(self): def tearDown(self):
"""Remove the temporary output directory""" """Remove the temporary output directory"""
@ -780,11 +780,11 @@ class TestFunctional(unittest.TestCase):
def testFullHelpInternal(self): def testFullHelpInternal(self):
"""Test that the full help is displayed with -H""" """Test that the full help is displayed with -H"""
try: try:
command.test_result = command.CommandResult() command.TEST_RESULT = command.CommandResult()
result = self._DoBinman('-H') result = self._DoBinman('-H')
help_file = os.path.join(self._binman_dir, 'README.rst') help_file = os.path.join(self._binman_dir, 'README.rst')
finally: finally:
command.test_result = None command.TEST_RESULT = None
def testHelp(self): def testHelp(self):
"""Test that the basic help is displayed with -h""" """Test that the basic help is displayed with -h"""
@ -1872,7 +1872,7 @@ class TestFunctional(unittest.TestCase):
def testGbb(self): def testGbb(self):
"""Test for the Chromium OS Google Binary Block""" """Test for the Chromium OS Google Binary Block"""
command.test_result = self._HandleGbbCommand command.TEST_RESULT = self._HandleGbbCommand
entry_args = { entry_args = {
'keydir': 'devkeys', 'keydir': 'devkeys',
'bmpblk': 'bmpblk.bin', 'bmpblk': 'bmpblk.bin',
@ -1941,7 +1941,7 @@ class TestFunctional(unittest.TestCase):
def testVblock(self): def testVblock(self):
"""Test for the Chromium OS Verified Boot Block""" """Test for the Chromium OS Verified Boot Block"""
self._hash_data = False self._hash_data = False
command.test_result = self._HandleVblockCommand command.TEST_RESULT = self._HandleVblockCommand
entry_args = { entry_args = {
'keydir': 'devkeys', 'keydir': 'devkeys',
} }
@ -1974,7 +1974,7 @@ class TestFunctional(unittest.TestCase):
def testVblockContent(self): def testVblockContent(self):
"""Test that the vblock signs the right data""" """Test that the vblock signs the right data"""
self._hash_data = True self._hash_data = True
command.test_result = self._HandleVblockCommand command.TEST_RESULT = self._HandleVblockCommand
entry_args = { entry_args = {
'keydir': 'devkeys', 'keydir': 'devkeys',
} }
@ -5496,7 +5496,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
def testFitSubentryUsesBintool(self): def testFitSubentryUsesBintool(self):
"""Test that binman FIT subentries can use bintools""" """Test that binman FIT subentries can use bintools"""
command.test_result = self._HandleGbbCommand command.TEST_RESULT = self._HandleGbbCommand
entry_args = { entry_args = {
'keydir': 'devkeys', 'keydir': 'devkeys',
'bmpblk': 'bmpblk.bin', 'bmpblk': 'bmpblk.bin',

View file

@ -187,7 +187,7 @@ class TestFunctional(unittest.TestCase):
self._git_dir = os.path.join(self._base_dir, 'src') self._git_dir = os.path.join(self._base_dir, 'src')
self._buildman_pathname = sys.argv[0] self._buildman_pathname = sys.argv[0]
self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
command.test_result = self._HandleCommand command.TEST_RESULT = self._HandleCommand
bsettings.setup(None) bsettings.setup(None)
bsettings.add_file(settings_data) bsettings.add_file(settings_data)
self.setupToolchains() self.setupToolchains()
@ -266,7 +266,7 @@ class TestFunctional(unittest.TestCase):
return result return result
def testFullHelp(self): def testFullHelp(self):
command.test_result = None command.TEST_RESULT = None
result = self._RunBuildman('-H') result = self._RunBuildman('-H')
help_file = os.path.join(self._buildman_dir, 'README.rst') help_file = os.path.join(self._buildman_dir, 'README.rst')
# Remove possible extraneous strings # Remove possible extraneous strings
@ -277,7 +277,7 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(0, result.return_code) self.assertEqual(0, result.return_code)
def testHelp(self): def testHelp(self):
command.test_result = None command.TEST_RESULT = None
result = self._RunBuildman('-h') result = self._RunBuildman('-h')
help_file = os.path.join(self._buildman_dir, 'README.rst') help_file = os.path.join(self._buildman_dir, 'README.rst')
self.assertTrue(len(result.stdout) > 1000) self.assertTrue(len(result.stdout) > 1000)
@ -286,11 +286,11 @@ class TestFunctional(unittest.TestCase):
def testGitSetup(self): def testGitSetup(self):
"""Test gitutils.Setup(), from outside the module itself""" """Test gitutils.Setup(), from outside the module itself"""
command.test_result = command.CommandResult(return_code=1) command.TEST_RESULT = command.CommandResult(return_code=1)
gitutil.setup() gitutil.setup()
self.assertEqual(gitutil.use_no_decorate, False) self.assertEqual(gitutil.use_no_decorate, False)
command.test_result = command.CommandResult(return_code=0) command.TEST_RESULT = command.CommandResult(return_code=0)
gitutil.setup() gitutil.setup()
self.assertEqual(gitutil.use_no_decorate, True) self.assertEqual(gitutil.use_no_decorate, True)

View file

@ -6,6 +6,13 @@ import os
from u_boot_pylib import cros_subprocess from u_boot_pylib import cros_subprocess
# This permits interception of RunPipe for test purposes. If it is set to
# a function, then that function is called with the pipe list being
# executed. Otherwise, it is assumed to be a CommandResult object, and is
# returned as the result for every run_pipe() call.
# When this value is None, commands are executed as normal.
TEST_RESULT = None
"""Shell command ease-ups for Python.""" """Shell command ease-ups for Python."""
class CommandResult: class CommandResult:
@ -32,14 +39,6 @@ class CommandResult:
self.combined = self.combined.decode('utf-8') self.combined = self.combined.decode('utf-8')
return self return self
# This permits interception of RunPipe for test purposes. If it is set to
# a function, then that function is called with the pipe list being
# executed. Otherwise, it is assumed to be a CommandResult object, and is
# returned as the result for every run_pipe() call.
# When this value is None, commands are executed as normal.
test_result = None
def run_pipe(pipe_list, infile=None, outfile=None, def run_pipe(pipe_list, infile=None, outfile=None,
capture=False, capture_stderr=False, oneline=False, capture=False, capture_stderr=False, oneline=False,
raise_on_error=True, cwd=None, binary=False, raise_on_error=True, cwd=None, binary=False,
@ -63,14 +62,14 @@ def run_pipe(pipe_list, infile=None, outfile=None,
Returns: Returns:
CommandResult object CommandResult object
""" """
if test_result: if TEST_RESULT:
if hasattr(test_result, '__call__'): if hasattr(TEST_RESULT, '__call__'):
# pylint: disable=E1102 # pylint: disable=E1102
result = test_result(pipe_list=pipe_list) result = TEST_RESULT(pipe_list=pipe_list)
if result: if result:
return result return result
else: else:
return test_result return TEST_RESULT
# No result: fall through to normal processing # No result: fall through to normal processing
result = CommandResult(b'', b'', b'') result = CommandResult(b'', b'', b'')
last_pipe = None last_pipe = None