diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-07-02 11:41:24 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-12 19:15:42 +0000 |
commit | 6580c97e48e7abca694f8f5d3e955bdf12a6ec55 (patch) | |
tree | bcda10463444802c8004fb46b4cb86ef5bc3a017 /zephyr/zmake/tests/test_zmake.py | |
parent | 0a639566d7e7769b7f627614c3359128c0c42763 (diff) | |
download | chrome-ec-6580c97e48e7abca694f8f5d3e955bdf12a6ec55.tar.gz |
zephyr: zmake: run black on all files, enable check in run_tests.sh
Run black on all files. Enable check in run_tests.sh to enforce
future formatting requirements.
BUG=b:192389533
BRANCH=none
TEST=run_tests.sh
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I5d93ef61d32d0dab4fe4bf3a77faf3f6693be627
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3002839
Commit-Queue: Yuval Peress <peress@chromium.org>
Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/zmake/tests/test_zmake.py')
-rw-r--r-- | zephyr/zmake/tests/test_zmake.py | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py index f037ab82f8..a5c132dbaa 100644 --- a/zephyr/zmake/tests/test_zmake.py +++ b/zephyr/zmake/tests/test_zmake.py @@ -26,12 +26,13 @@ OUR_PATH = os.path.dirname(os.path.realpath(__file__)) class FakeProject: """A fake project which requests two builds and does no packing""" + # pylint: disable=too-few-public-methods def __init__(self): self.packer = mock.Mock() self.packer.pack_firmware = mock.Mock(return_value=[]) - self.project_dir = pathlib.Path('FakeProjectDir') + self.project_dir = pathlib.Path("FakeProjectDir") self.config = mock.Mock() self.config.supported_zephyr_versions = [(2, 5)] @@ -39,11 +40,11 @@ class FakeProject: @staticmethod def iter_builds(): """Yield the two builds that zmake normally does""" - yield 'build-ro', zmake.build_config.BuildConfig() - yield 'build-rw', zmake.build_config.BuildConfig() + yield "build-ro", zmake.build_config.BuildConfig() + yield "build-rw", zmake.build_config.BuildConfig() def prune_modules(self, paths): - return {} #pathlib.Path('path')] + return {} # pathlib.Path('path')] def find_dts_overlays(self, module_paths): return zmake.build_config.BuildConfig() @@ -72,14 +73,13 @@ class FakeJobserver(zmake.jobserver.GNUMakeJobServer): """Ignores the provided command and just runs 'cat' instead""" for pattern, filename in self.fnames.items(): # Convert to a list of strings - cmd = [isinstance(c, pathlib.PosixPath) and c.as_posix() or c - for c in cmd] + cmd = [isinstance(c, pathlib.PosixPath) and c.as_posix() or c for c in cmd] if pattern.match(" ".join(cmd)): - new_cmd = ['cat', filename] + new_cmd = ["cat", filename] break else: raise Exception('No pattern matched "%s"' % " ".join(cmd)) - kwargs.pop('env', None) + kwargs.pop("env", None) return self.jobserver.popen(new_cmd, *args, **kwargs) @@ -92,7 +92,7 @@ def get_test_filepath(suffix): Returns: Full path to the test file """ - return os.path.join(OUR_PATH, 'files', 'sample_{}.txt'.format(suffix)) + return os.path.join(OUR_PATH, "files", "sample_{}.txt".format(suffix)) def do_test_with_log_level(log_level, use_configure=False, fnames=None): @@ -112,30 +112,34 @@ def do_test_with_log_level(log_level, use_configure=False, fnames=None): """ if fnames is None: fnames = { - re.compile(r".*build-ro"): get_test_filepath('ro'), - re.compile(r".*build-rw"): get_test_filepath('rw'), + re.compile(r".*build-ro"): get_test_filepath("ro"), + re.compile(r".*build-rw"): get_test_filepath("rw"), } zephyr_base = mock.Mock() - zmk = zm.Zmake(jobserver=FakeJobserver(fnames), - zephyr_base=zephyr_base,) + zmk = zm.Zmake( + jobserver=FakeJobserver(fnames), + zephyr_base=zephyr_base, + ) with LogCapture(level=log_level) as cap: with tempfile.TemporaryDirectory() as tmpname: - with open(os.path.join(tmpname, 'VERSION'), 'w') as fd: - fd.write('''VERSION_MAJOR = 2 + with open(os.path.join(tmpname, "VERSION"), "w") as fd: + fd.write( + """VERSION_MAJOR = 2 VERSION_MINOR = 5 PATCHLEVEL = 0 VERSION_TWEAK = 0 EXTRAVERSION = -''') +""" + ) zephyr_base.resolve = mock.Mock(return_value=pathlib.Path(tmpname)) - with patch('zmake.version.get_version_string', return_value='123'): - with patch.object(zmake.project, 'Project', - return_value=FakeProject()): + with patch("zmake.version.get_version_string", return_value="123"): + with patch.object(zmake.project, "Project", return_value=FakeProject()): if use_configure: - zmk.configure(pathlib.Path(tmpname), - build_dir=pathlib.Path('build')) + zmk.configure( + pathlib.Path(tmpname), build_dir=pathlib.Path("build") + ) else: zmk.build(pathlib.Path(tmpname)) multiproc.wait_for_log_end() @@ -152,57 +156,59 @@ class TestFilters(unittest.TestCase): recs, _ = do_test_with_log_level(logging.ERROR) self.assertFalse(recs) - def test_filter_info(self): """Test what appears on the INFO level""" recs, tmpname = do_test_with_log_level(logging.INFO) # TODO: Remove sets and figure out how to check the lines are in the # right order. expected = { - 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format( - tmpname, tmpname), - 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format( - tmpname, tmpname), + "Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro".format( + tmpname, tmpname + ), + "Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw".format( + tmpname, tmpname + ), } - for suffix in ['ro', 'rw']: - with open(get_test_filepath('%s_INFO' % suffix)) as f: + for suffix in ["ro", "rw"]: + with open(get_test_filepath("%s_INFO" % suffix)) as f: for line in f: expected.add( - "[{}:build-{}]{}".format(tmpname, suffix, line.strip())) + "[{}:build-{}]{}".format(tmpname, suffix, line.strip()) + ) # This produces an easy-to-read diff if there is a difference self.assertEqual(expected, set(recs)) - def test_filter_debug(self): """Test what appears on the DEBUG level""" recs, tmpname = do_test_with_log_level(logging.DEBUG) # TODO: Remove sets and figure out how to check the lines are in the # right order. expected = { - 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format( - tmpname, tmpname), - 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format( - tmpname, tmpname), - 'Running cat {}/files/sample_ro.txt'.format(OUR_PATH), - 'Running cat {}/files/sample_rw.txt'.format(OUR_PATH), + "Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro".format( + tmpname, tmpname + ), + "Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw".format( + tmpname, tmpname + ), + "Running cat {}/files/sample_ro.txt".format(OUR_PATH), + "Running cat {}/files/sample_rw.txt".format(OUR_PATH), } - for suffix in ['ro', 'rw']: + for suffix in ["ro", "rw"]: with open(get_test_filepath(suffix)) as f: for line in f: expected.add( - "[{}:build-{}]{}".format(tmpname, suffix, line.strip())) + "[{}:build-{}]{}".format(tmpname, suffix, line.strip()) + ) # This produces an easy-to-read diff if there is a difference self.assertEqual(expected, set(recs)) - def test_filter_devicetree_error(self): """Test that devicetree errors appear""" recs, tmpname = do_test_with_log_level( - logging.ERROR, - True, - {re.compile(r'.*'): get_test_filepath('err')}) + logging.ERROR, True, {re.compile(r".*"): get_test_filepath("err")} + ) - dt_errs = [rec for rec in recs if 'adc' in rec] + dt_errs = [rec for rec in recs if "adc" in rec] assert "devicetree error: 'adc' is marked as required" in list(dt_errs)[0] |