summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-03-20 14:12:06 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-03-21 16:40:43 +0000
commit9f6e8f9a933c4af6f250b54da014922dbe8d4584 (patch)
tree7da4fe157226a22714db4e6d90054ac5ace550df /tests
parentaa326c937b0146269be78ff03a554d6c1d7826cb (diff)
downloadbuildstream-9f6e8f9a933c4af6f250b54da014922dbe8d4584.tar.gz
tests: when comparing lists/dicts, compare all at once
This allows pytest to show a better report of the difference between the two lists and not just tell that one entry is wrong.
Diffstat (limited to 'tests')
-rw-r--r--tests/cachekey/cachekey.py7
-rw-r--r--tests/elements/filter.py13
-rw-r--r--tests/format/dependencies.py59
-rw-r--r--tests/frontend/artifact.py6
-rw-r--r--tests/frontend/push.py14
-rw-r--r--tests/frontend/track.py12
6 files changed, 61 insertions, 50 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py
index bfeb89a8b..3fc5d73ee 100644
--- a/tests/cachekey/cachekey.py
+++ b/tests/cachekey/cachekey.py
@@ -255,6 +255,7 @@ def test_keys_stable_over_targets(cli, datafiles):
ordering2_result.assert_success()
ordering2_cache_keys = parse_output_keys(ordering2_result.output)
- for element in ordering1_cache_keys:
- assert ordering1_cache_keys[element] == ordering2_cache_keys[element]
- assert ordering1_cache_keys[element] == all_cache_keys[element]
+ elements = ordering1_cache_keys.keys()
+
+ assert {key: ordering2_cache_keys[key] for key in elements} == ordering1_cache_keys
+ assert {key: all_cache_keys[key] for key in elements} == ordering1_cache_keys
diff --git a/tests/elements/filter.py b/tests/elements/filter.py
index 56e4c2b5a..afc428641 100644
--- a/tests/elements/filter.py
+++ b/tests/elements/filter.py
@@ -396,8 +396,11 @@ def test_filter_track_multi(datafiles, cli, tmpdir):
# Assert that a fetch is needed
states = cli.get_element_states(project, [input_name, input2_name])
- assert states[input_name] == 'no reference'
- assert states[input2_name] == 'no reference'
+
+ assert states == {
+ input_name: "no reference",
+ input2_name: "no reference",
+ }
# Now try to track it
result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst"])
@@ -458,8 +461,10 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir):
# Assert that a fetch is needed
states = cli.get_element_states(project, [input_name, input2_name])
- assert states[input_name] == 'no reference'
- assert states[input2_name] == 'no reference'
+ assert states == {
+ input_name: "no reference",
+ input2_name: "no reference",
+ }
# Now try to track it
result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst", "--except", input_name])
diff --git a/tests/format/dependencies.py b/tests/format/dependencies.py
index e0f517249..780eac73e 100644
--- a/tests/format/dependencies.py
+++ b/tests/format/dependencies.py
@@ -147,15 +147,15 @@ def test_scope_all(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='all')
- assert len(element_list) == 7
-
- assert element_list[0] == "build-build.bst"
- assert element_list[1] == "run-build.bst"
- assert element_list[2] == "build.bst"
- assert element_list[3] == "dep-one.bst"
- assert element_list[4] == "run.bst"
- assert element_list[5] == "dep-two.bst"
- assert element_list[6] == "target.bst"
+ assert element_list == [
+ "build-build.bst",
+ "run-build.bst",
+ "build.bst",
+ "dep-one.bst",
+ "run.bst",
+ "dep-two.bst",
+ "target.bst",
+ ]
@pytest.mark.datafiles(DATA_DIR)
@@ -165,12 +165,12 @@ def test_scope_run(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='run')
- assert len(element_list) == 4
-
- assert element_list[0] == "dep-one.bst"
- assert element_list[1] == "run.bst"
- assert element_list[2] == "dep-two.bst"
- assert element_list[3] == "target.bst"
+ assert element_list == [
+ "dep-one.bst",
+ "run.bst",
+ "dep-two.bst",
+ "target.bst",
+ ]
@pytest.mark.datafiles(DATA_DIR)
@@ -180,11 +180,7 @@ def test_scope_build(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='build')
- assert len(element_list) == 3
-
- assert element_list[0] == "dep-one.bst"
- assert element_list[1] == "run.bst"
- assert element_list[2] == "dep-two.bst"
+ assert element_list == ["dep-one.bst", "run.bst", "dep-two.bst"]
@pytest.mark.datafiles(DATA_DIR)
@@ -200,10 +196,7 @@ def test_scope_build_of_child(cli, datafiles):
# Pass two, let's look at these
element_list = cli.get_pipeline(project, [element], scope='build')
- assert len(element_list) == 2
-
- assert element_list[0] == "run-build.bst"
- assert element_list[1] == "build.bst"
+ assert element_list == ["run-build.bst", "build.bst"]
@pytest.mark.datafiles(DATA_DIR)
@@ -216,12 +209,12 @@ def test_no_recurse(cli, datafiles):
# show` option does this directly.
element_list = cli.get_pipeline(project, elements, scope='plan')
- assert len(element_list) == 7
-
- assert element_list[0] == 'build-build.bst'
- assert element_list[1] in ['build.bst', 'run-build.bst']
- assert element_list[2] in ['build.bst', 'run-build.bst']
- assert element_list[3] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[4] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[5] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[6] == 'target.bst'
+ assert element_list == [
+ 'build-build.bst',
+ 'run-build.bst',
+ 'build.bst',
+ 'dep-one.bst',
+ 'run.bst',
+ 'dep-two.bst',
+ 'target.bst',
+ ]
diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact.py
index eadc6d443..887649f96 100644
--- a/tests/frontend/artifact.py
+++ b/tests/frontend/artifact.py
@@ -128,8 +128,10 @@ def test_artifact_delete_element_and_artifact(cli, tmpdir, datafiles):
# First build an element so that we can find its artifact
result = cli.run(project=project, args=['build', element])
result.assert_success()
- assert cli.get_element_state(project, element) == 'cached'
- assert cli.get_element_state(project, dep) == 'cached'
+ assert cli.get_element_states(project, [element, dep], deps="none") == {
+ element: "cached",
+ dep: "cached",
+ }
# Obtain the artifact ref
cache_key = cli.get_element_key(project, element)
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index 919ce3a84..061607446 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -253,8 +253,12 @@ def test_artifact_expires(cli, datafiles, tmpdir):
# check that element's 1 and 2 are cached both locally and remotely
states = cli.get_element_states(project, ['element1.bst', 'element2.bst'])
- assert states['element1.bst'] == 'cached'
- assert states['element2.bst'] == 'cached'
+
+ assert states == {
+ "element1.bst": "cached",
+ "element2.bst": "cached",
+ }
+
assert_shared(cli, share, project, 'element1.bst')
assert_shared(cli, share, project, 'element2.bst')
@@ -339,8 +343,10 @@ def test_recently_pulled_artifact_does_not_expire(cli, datafiles, tmpdir):
# Ensure they are cached locally
states = cli.get_element_states(project, ['element1.bst', 'element2.bst'])
- assert states['element1.bst'] == 'cached'
- assert states['element2.bst'] == 'cached'
+ assert states == {
+ "element1.bst": "cached",
+ "element2.bst": "cached",
+ }
# Ensure that they have been pushed to the cache
assert_shared(cli, share, project, 'element1.bst')
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index b3b063f69..5a6460d3d 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -51,8 +51,10 @@ def test_track_single(cli, tmpdir, datafiles):
# Assert that tracking is needed for both elements
states = cli.get_element_states(project, [element_target_name])
- assert states[element_dep_name] == 'no reference'
- assert states[element_target_name] == 'no reference'
+ assert states == {
+ element_dep_name: "no reference",
+ element_target_name: "no reference",
+ }
# Now first try to track only one element
result = cli.run(project=project, args=[
@@ -68,8 +70,10 @@ def test_track_single(cli, tmpdir, datafiles):
# Assert that the dependency is waiting and the target has still never been tracked
states = cli.get_element_states(project, [element_target_name])
- assert states[element_dep_name] == 'no reference'
- assert states[element_target_name] == 'waiting'
+ assert states == {
+ element_dep_name: 'no reference',
+ element_target_name: 'waiting',
+ }
@pytest.mark.datafiles(os.path.join(TOP_DIR))