diff options
author | Josh Smith <joshsmith@codethink.co.uk> | 2018-08-09 16:27:16 +0100 |
---|---|---|
committer | Josh Smith <qinusty@gmail.com> | 2018-08-15 12:15:58 +0100 |
commit | 03527d5afd967a94f95f2ee8f035236b387dd335 (patch) | |
tree | 9bd54dfc9cfa45000c87914bdbd3b371da147bfb /tests/cachekey/cachekey.py | |
parent | c9dd51f2a69997a60387a2c468c9a013b73d7955 (diff) | |
download | buildstream-03527d5afd967a94f95f2ee8f035236b387dd335.tar.gz |
tests: Add tests for configurable warnings
This adds multiple tests for custom plugin warnings and core warnings,
providing checks for both cases which should cause warnings and errors
when configured as fatal.
Also adds tests for cache key calculations.
Diffstat (limited to 'tests/cachekey/cachekey.py')
-rw-r--r-- | tests/cachekey/cachekey.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py index 36562fbf3..21beef8fb 100644 --- a/tests/cachekey/cachekey.py +++ b/tests/cachekey/cachekey.py @@ -37,7 +37,8 @@ # from tests.testutils.runcli import cli from tests.testutils.site import HAVE_BZR, HAVE_GIT, HAVE_OSTREE, IS_LINUX - +from buildstream.plugin import CoreWarnings +from buildstream import _yaml import os from collections import OrderedDict import pytest @@ -128,7 +129,6 @@ def assert_cache_keys(project_dir, output): "Use tests/cachekey/update.py to automatically " + "update this test case") - ############################################## # Test Entry Point # ############################################## @@ -167,3 +167,47 @@ def test_cache_key(datafiles, cli): ]) result.assert_success() assert_cache_keys(project, result.output) + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("first_warnings, second_warnings, identical_keys", [ + [[], [], True], + [[], [CoreWarnings.REF_NOT_IN_TRACK], False], + [[CoreWarnings.REF_NOT_IN_TRACK], [], False], + [[CoreWarnings.REF_NOT_IN_TRACK], [CoreWarnings.REF_NOT_IN_TRACK], True], + [[CoreWarnings.REF_NOT_IN_TRACK, CoreWarnings.OVERLAPS], + [CoreWarnings.OVERLAPS, CoreWarnings.REF_NOT_IN_TRACK], True], +]) +def test_cache_key_fatal_warnings(cli, tmpdir, first_warnings, second_warnings, identical_keys): + + # Builds project, Runs bst show, gathers cache keys + def run_get_cache_key(project_name, warnings): + config = { + 'name': project_name, + 'element-path': 'elements', + 'fatal-warnings': warnings + } + + project_dir = tmpdir.mkdir(project_name) + project_config_file = str(project_dir.join('project.conf')) + _yaml.dump(_yaml.node_sanitize(config), filename=project_config_file) + + elem_dir = project_dir.mkdir('elements') + element_file = str(elem_dir.join('stack.bst')) + _yaml.dump({'kind': 'stack'}, filename=element_file) + + result = cli.run(project=str(project_dir), args=[ + 'show', + '--format', '%{name}::%{full-key}', + 'stack.bst' + ]) + return result.output + + # Returns true if all keys are identical + def compare_cache_keys(first_keys, second_keys): + return not any((x != y for x, y in zip(first_keys, second_keys))) + + first_keys = run_get_cache_key("first", first_warnings) + second_keys = run_get_cache_key("second", second_warnings) + + assert compare_cache_keys(first_keys, second_keys) == identical_keys |