diff options
author | Simon Glass <sjg@chromium.org> | 2022-01-09 20:13:57 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2022-01-25 12:36:11 -0700 |
commit | 56ee85eef11e6162e2626ba644c6de459137dd23 (patch) | |
tree | 07757079f1a23c6f16c68b0fb184928f56bf9b2a /tools/binman/ftest.py | |
parent | e1b7e4ddb6b1a1d0b416facbd0f576dde9c404e6 (diff) |
binman: Enable bintool tests including cmdline processing
The tests rely on having at least 5 bintool implementions. Now that we
have this, enable them. Add tests for the binman 'tool' subcommand.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/ftest.py')
-rw-r--r-- | tools/binman/ftest.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 179326c42a3..92bcb740884 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -17,6 +17,8 @@ import struct import sys import tempfile import unittest +import unittest.mock +import urllib.error from binman import bintool from binman import cbfs_util @@ -4991,6 +4993,36 @@ fdt fdtmap Extract the devicetree blob from the fdtmap err = stderr.getvalue() self.assertRegex(err, "Image 'main-section'.*faked.*: blob-ext-list") + def testListBintools(self): + args = ['tool', '--list'] + with test_util.capture_sys_output() as (stdout, _): + self._DoBinman(*args) + out = stdout.getvalue().splitlines() + self.assertTrue(len(out) >= 2) + + def testFetchBintools(self): + def fail_download(url): + """Take the tools.Download() function by raising an exception""" + raise urllib.error.URLError('my error') + + args = ['tool'] + with self.assertRaises(ValueError) as e: + self._DoBinman(*args) + self.assertIn("Invalid arguments to 'tool' subcommand", + str(e.exception)) + + args = ['tool', '--fetch'] + with self.assertRaises(ValueError) as e: + self._DoBinman(*args) + self.assertIn('Please specify bintools to fetch', str(e.exception)) + + args = ['tool', '--fetch', '_testing'] + with unittest.mock.patch.object(tools, 'Download', + side_effect=fail_download): + with test_util.capture_sys_output() as (stdout, _): + self._DoBinman(*args) + self.assertIn('failed to fetch with all methods', stdout.getvalue()) + if __name__ == "__main__": unittest.main() |