diff options
author | Simon Glass <sjg@chromium.org> | 2021-05-07 09:48:05 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-07 19:20:14 +0000 |
commit | e981b032ff108202832fd60ee09e29d5b97c4375 (patch) | |
tree | 35c87edbab89ee11f95a3a23a3541c70c5ccd341 | |
parent | e371bbee46cf5a2a21339d2afcf2d59ef6f57d45 (diff) | |
download | chrome-ec-e981b032ff108202832fd60ee09e29d5b97c4375.tar.gz |
zmake: Add a helper function for test filenames
Create a new function to reduce the amount of duplicated code.
BUG=b:184298184
BRANCH=none
TEST=(cd zephyr/zmake/; python3 -m pytest tests/*.py -v -k test_filter)
Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I51124fa47eb298112bd9b2b06018d8f14b9968ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2880415
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | zephyr/zmake/tests/test_zmake.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py index 652b456bf7..eef63a31cb 100644 --- a/zephyr/zmake/tests/test_zmake.py +++ b/zephyr/zmake/tests/test_zmake.py @@ -67,6 +67,18 @@ class FakeJobserver(zmake.jobserver.GNUMakeJobServer): return self.jobserver.popen(new_cmd, *args, **kwargs) +def get_test_filepath(suffix): + """Get the filepath for a particular test file + + Args: + suffix: Suffix of the file to read, e.g. 'ro' or 'ro_INFO' + + Returns: + Full path to the test file + """ + return os.path.join(OUR_PATH, 'files', 'sample_{}.txt'.format(suffix)) + + def do_test_with_log_level(log_level): """Test filtering using a particular log level @@ -79,10 +91,8 @@ def do_test_with_log_level(log_level): - Temporary directory used for build """ fnames = { - re.compile(r".*build-ro"): os.path.join( - OUR_PATH, 'files', 'sample_ro.txt'), - re.compile(r".*build-rw"): os.path.join( - OUR_PATH, 'files', 'sample_rw.txt'), + re.compile(r".*build-ro"): get_test_filepath('ro'), + re.compile(r".*build-rw"): get_test_filepath('rw'), } zmk = zm.Zmake(jobserver=FakeJobserver(fnames)) @@ -116,12 +126,7 @@ def test_filter_info(): tmpname, tmpname), } for suffix in ['ro', 'rw']: - with open( - os.path.join( - OUR_PATH, - 'files', - 'sample_{}_INFO.txt'.format(suffix)), - 'r') as f: + with open(get_test_filepath('%s_INFO' % suffix)) as f: for line in f: expected.add( "[{}:build-{}]{}".format(tmpname, suffix, line.strip())) @@ -143,12 +148,7 @@ def test_filter_debug(): 'Running cat {}/files/sample_rw.txt'.format(OUR_PATH), } for suffix in ['ro', 'rw']: - with open( - os.path.join( - OUR_PATH, - 'files', - 'sample_{}.txt'.format(suffix)), - 'r') as f: + with open(get_test_filepath(suffix)) as f: for line in f: expected.add( "[{}:build-{}]{}".format(tmpname, suffix, line.strip())) |