summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-08-04 22:51:25 +0900
committerbst-marge-bot <marge-bot@buildstream.build>2020-08-10 08:33:55 +0000
commit7f2bc71e74c9914d65775a68a61781e9851f6238 (patch)
tree5346388794047adbb64e63633a4cbe003ab4f907 /tests
parent89b3fa48d48ab559b582a0daa9daa6aac0d2604c (diff)
downloadbuildstream-7f2bc71e74c9914d65775a68a61781e9851f6238.tar.gz
_yaml.pyx: Make shortname a mandatory argument to _yaml.load()
This ensures that important calls to this function do give some thought to providing a reasonable shortname, which will be used as a display name in errors. This continues to support `None` as a shortname, which is used in various tests which don't need to provide a reasonable user facing error. The buildstream.testing module now exports a `load_yaml` function which only takes a filename and no shortname.
Diffstat (limited to 'tests')
-rw-r--r--tests/artifactcache/junctions.py2
-rw-r--r--tests/elements/filter.py14
-rw-r--r--tests/format/include_composition.py16
-rw-r--r--tests/frontend/init.py10
-rw-r--r--tests/frontend/interactive_init.py2
-rw-r--r--tests/frontend/workspace.py14
-rw-r--r--tests/internals/yaml.py34
7 files changed, 46 insertions, 46 deletions
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index df7ee9473..18c48b4a7 100644
--- a/tests/artifactcache/junctions.py
+++ b/tests/artifactcache/junctions.py
@@ -16,7 +16,7 @@ DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "junctions"
def project_set_artifacts(project, url):
project_conf_file = os.path.join(project, "project.conf")
- project_config = _yaml.load(project_conf_file)
+ project_config = _yaml.load(project_conf_file, shortname=None)
project_config["artifacts"] = {"url": url, "push": True}
_yaml.roundtrip_dump(project_config.strip_node_info(), file=project_conf_file)
diff --git a/tests/elements/filter.py b/tests/elements/filter.py
index 3bc24c20a..443f64d34 100644
--- a/tests/elements/filter.py
+++ b/tests/elements/filter.py
@@ -227,7 +227,7 @@ def test_filter_track(datafiles, cli, tmpdir):
result.assert_success()
# Now check that a ref field exists
- new_input = _yaml.load(input_file)
+ new_input = _yaml.load(input_file, shortname=None)
source_node = new_input.get_sequence("sources").mapping_at(0)
new_input_ref = source_node.get_str("ref")
assert new_input_ref == ref
@@ -273,7 +273,7 @@ def test_filter_track_excepted(datafiles, cli, tmpdir):
result.assert_success()
# Now check that a ref field exists
- new_input = _yaml.load(input_file)
+ new_input = _yaml.load(input_file, shortname=None)
source_node = new_input.get_sequence("sources").mapping_at(0)
assert "ref" not in source_node
@@ -318,7 +318,7 @@ def test_filter_track_multi_to_one(datafiles, cli, tmpdir):
result.assert_success()
# Now check that a ref field exists
- new_input = _yaml.load(input_file)
+ new_input = _yaml.load(input_file, shortname=None)
source_node = new_input.get_sequence("sources").mapping_at(0)
new_ref = source_node.get_str("ref")
assert new_ref == ref
@@ -374,12 +374,12 @@ def test_filter_track_multi(datafiles, cli, tmpdir):
result.assert_success()
# Now check that a ref field exists
- new_input = _yaml.load(input_file)
+ new_input = _yaml.load(input_file, shortname=None)
source_node = new_input.get_sequence("sources").mapping_at(0)
new_ref = source_node.get_str("ref")
assert new_ref == ref
- new_input2 = _yaml.load(input2_file)
+ new_input2 = _yaml.load(input2_file, shortname=None)
source_node2 = new_input2.get_sequence("sources").mapping_at(0)
new_ref2 = source_node2.get_str("ref")
assert new_ref2 == ref
@@ -434,11 +434,11 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir):
result.assert_success()
# Now check that a ref field exists
- new_input = _yaml.load(input_file)
+ new_input = _yaml.load(input_file, shortname=None)
source_node = new_input.get_sequence("sources").mapping_at(0)
assert "ref" not in source_node
- new_input2 = _yaml.load(input2_file)
+ new_input2 = _yaml.load(input2_file, shortname=None)
source_node2 = new_input2.get_sequence("sources").mapping_at(0)
new_ref2 = source_node2.get_str("ref")
assert new_ref2 == ref
diff --git a/tests/format/include_composition.py b/tests/format/include_composition.py
index 3224822af..8148e18fa 100644
--- a/tests/format/include_composition.py
+++ b/tests/format/include_composition.py
@@ -23,7 +23,7 @@ def test_main_has_priority(tmpdir):
_yaml.roundtrip_dump({"(@)": ["a.yml"], "test": ["main"]}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": ["a"]}, str(tmpdir.join("a.yml")))
@@ -36,7 +36,7 @@ def test_include_cannot_append(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml"], "test": ["main"]}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": {"(>)": ["a"]}}, str(tmpdir.join("a.yml")))
@@ -49,7 +49,7 @@ def test_main_can_append(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml"], "test": {"(>)": ["main"]}}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": ["a"]}, str(tmpdir.join("a.yml")))
@@ -62,7 +62,7 @@ def test_sibling_cannot_append_backward(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml", "b.yml"]}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": {"(>)": ["a"]}}, str(tmpdir.join("a.yml")))
_yaml.roundtrip_dump({"test": ["b"]}, str(tmpdir.join("b.yml")))
@@ -76,7 +76,7 @@ def test_sibling_can_append_forward(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml", "b.yml"]}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": ["a"]}, str(tmpdir.join("a.yml")))
_yaml.roundtrip_dump({"test": {"(>)": ["b"]}}, str(tmpdir.join("b.yml")))
@@ -90,7 +90,7 @@ def test_lastest_sibling_has_priority(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml", "b.yml"]}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": ["a"]}, str(tmpdir.join("a.yml")))
_yaml.roundtrip_dump({"test": ["b"]}, str(tmpdir.join("b.yml")))
@@ -104,7 +104,7 @@ def test_main_keeps_keys(tmpdir):
with make_includes(str(tmpdir)) as includes:
_yaml.roundtrip_dump({"(@)": ["a.yml"], "something": "else"}, str(tmpdir.join("main.yml")))
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
_yaml.roundtrip_dump({"test": ["a"]}, str(tmpdir.join("a.yml")))
@@ -121,7 +121,7 @@ def test_overwrite_directive_on_later_composite(tmpdir):
{"(@)": ["a.yml", "b.yml"], "test": {"(=)": ["Overwritten"]}}, str(tmpdir.join("main.yml"))
)
- main = _yaml.load(str(tmpdir.join("main.yml")))
+ main = _yaml.load(str(tmpdir.join("main.yml")), shortname=None)
# a.yml
_yaml.roundtrip_dump(
diff --git a/tests/frontend/init.py b/tests/frontend/init.py
index 3f897fb14..c3af27bea 100644
--- a/tests/frontend/init.py
+++ b/tests/frontend/init.py
@@ -33,7 +33,7 @@ def test_defaults(cli, tmpdir):
result = cli.run(args=["init", "--project-name", "foo", project])
result.assert_success()
- project_conf = _yaml.load(project_path)
+ project_conf = _yaml.load(project_path, shortname=None)
assert project_conf.get_str("name") == "foo"
assert project_conf.get_str("min-version") == get_default_min_version()
assert project_conf.get_str("element-path") == "elements"
@@ -48,7 +48,7 @@ def test_all_options(cli, tmpdir):
)
result.assert_success()
- project_conf = _yaml.load(project_path)
+ project_conf = _yaml.load(project_path, shortname=None)
assert project_conf.get_str("name") == "foo"
assert project_conf.get_str("min-version") == "2.0"
assert project_conf.get_str("element-path") == "ponies"
@@ -81,7 +81,7 @@ def test_force_overwrite_project(cli, tmpdir):
result = cli.run(args=["init", "--project-name", "foo", "--force", project])
result.assert_success()
- project_conf = _yaml.load(project_path)
+ project_conf = _yaml.load(project_path, shortname=None)
assert project_conf.get_str("name") == "foo"
assert project_conf.get_str("min-version") == get_default_min_version()
@@ -95,7 +95,7 @@ def test_relative_path_directory_as_argument(cli, tmpdir):
result = cli.run(args=["init", "--project-name", "foo", rel_path])
result.assert_success()
- project_conf = _yaml.load(project_path)
+ project_conf = _yaml.load(project_path, shortname=None)
assert project_conf.get_str("name") == "foo"
assert project_conf.get_str("min-version") == get_default_min_version()
assert project_conf.get_str("element-path") == "elements"
@@ -149,7 +149,7 @@ def test_element_path_interactive(cli, tmp_path, monkeypatch, element_path):
full_element_path = project.joinpath(element_path)
assert full_element_path.exists()
- project_conf = _yaml.load(str(project_conf_path))
+ project_conf = _yaml.load(str(project_conf_path), shortname=None)
assert project_conf.get_str("name") == "project_name"
assert project_conf.get_str("min-version") == "2.0"
assert project_conf.get_str("element-path") == element_path
diff --git a/tests/frontend/interactive_init.py b/tests/frontend/interactive_init.py
index b8cbe522f..c05fd4e37 100644
--- a/tests/frontend/interactive_init.py
+++ b/tests/frontend/interactive_init.py
@@ -36,7 +36,7 @@ def test_init(tmpdir):
session.close()
# Now assert that a project.conf got created with expected values
- project_conf = _yaml.load(os.path.join(str(tmpdir), "project.conf"))
+ project_conf = _yaml.load(os.path.join(str(tmpdir), "project.conf"), shortname=None)
assert project_conf.get_str("name") == name
assert project_conf.get_str("min-version") == min_version
assert project_conf.get_str("element-path") == element_path
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index 4aae61ad7..813e68196 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -167,7 +167,7 @@ def test_open_bzr_customize(cli, tmpdir, datafiles):
assert os.path.isdir(bzrdir)
# Check that the correct origin branch is set
- element_config = _yaml.load(os.path.join(project, "elements", element_name))
+ element_config = _yaml.load(os.path.join(project, "elements", element_name), shortname=None)
source_config = element_config.get_sequence("sources").mapping_at(0)
output = subprocess.check_output(["bzr", "info"], cwd=workspace)
stripped_url = source_config.get_str("url").lstrip("file:///")
@@ -859,7 +859,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte
def parse_dict_as_yaml(node):
tempfile = os.path.join(str(tmpdir), "yaml_dump")
_yaml.roundtrip_dump(node, tempfile)
- return _yaml.load(tempfile).strip_node_info()
+ return _yaml.load(tempfile, shortname=None).strip_node_info()
project = str(datafiles)
os.makedirs(os.path.join(project, ".bst"))
@@ -871,7 +871,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte
result = cli.run(project=project, args=["workspace", "list"])
result.assert_success()
- loaded_config = _yaml.load(workspace_config_path).strip_node_info()
+ loaded_config = _yaml.load(workspace_config_path, shortname=None).strip_node_info()
# Check that workspace config remains the same if no modifications
# to workspaces were made
@@ -900,7 +900,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte
result.assert_success()
# Check that workspace config is converted correctly if necessary
- loaded_config = _yaml.load(workspace_config_path).strip_node_info()
+ loaded_config = _yaml.load(workspace_config_path, shortname=None).strip_node_info()
assert loaded_config == parse_dict_as_yaml(expected)
@@ -1052,7 +1052,7 @@ def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
# Delete the ref from the source so that we can detect if the
# element has been tracked after closing the workspace
- element_contents = _yaml.load(element_file)
+ element_contents = _yaml.load(element_file, shortname=None)
ref1 = element_contents.get_sequence("sources").mapping_at(0).get_str("ref")
del element_contents.get_sequence("sources").mapping_at(0)["ref"]
_yaml.roundtrip_dump(element_contents, element_file)
@@ -1061,7 +1061,7 @@ def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
result.assert_success()
# Element is not tracked now
- element_contents = _yaml.load(element_file)
+ element_contents = _yaml.load(element_file, shortname=None)
assert "ref" not in element_contents.get_sequence("sources").mapping_at(0)
# close the workspace
@@ -1072,7 +1072,7 @@ def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
result = cli.run(project=project, args=["source", "track", element_name])
result.assert_success()
- element_contents = _yaml.load(element_file)
+ element_contents = _yaml.load(element_file, shortname=None)
ref2 = element_contents.get_sequence("sources").mapping_at(0).get_str("ref")
# these values should be equivalent
assert ref1 == ref2
diff --git a/tests/internals/yaml.py b/tests/internals/yaml.py
index a4f8d08cc..4727d5d28 100644
--- a/tests/internals/yaml.py
+++ b/tests/internals/yaml.py
@@ -16,7 +16,7 @@ def test_load_yaml(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- loaded = _yaml.load(filename)
+ loaded = _yaml.load(filename, shortname=None)
assert loaded.get_str("kind") == "pony"
@@ -35,7 +35,7 @@ def test_basic_provenance(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- loaded = _yaml.load(filename)
+ loaded = _yaml.load(filename, shortname=None)
assert loaded.get_str("kind") == "pony"
assert_provenance(filename, 1, 0, loaded)
@@ -46,7 +46,7 @@ def test_member_provenance(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- loaded = _yaml.load(filename)
+ loaded = _yaml.load(filename, shortname=None)
assert loaded.get_str("kind") == "pony"
assert_provenance(filename, 2, 13, loaded.get_scalar("description"))
@@ -56,7 +56,7 @@ def test_element_provenance(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- loaded = _yaml.load(filename)
+ loaded = _yaml.load(filename, shortname=None)
assert loaded.get_str("kind") == "pony"
assert_provenance(filename, 5, 2, loaded.get_sequence("moods").scalar_at(1))
@@ -67,11 +67,11 @@ def test_mapping_validate_keys(datafiles):
valid = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
invalid = os.path.join(datafiles.dirname, datafiles.basename, "invalid.yaml")
- base = _yaml.load(valid)
+ base = _yaml.load(valid, shortname=None)
base.validate_keys(["kind", "description", "moods", "children", "extra"])
- base = _yaml.load(invalid)
+ base = _yaml.load(invalid, shortname=None)
with pytest.raises(LoadError) as exc:
base.validate_keys(["kind", "description", "moods", "children", "extra"])
@@ -84,7 +84,7 @@ def test_node_get(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- base = _yaml.load(filename)
+ base = _yaml.load(filename, shortname=None)
assert base.get_str("kind") == "pony"
children = base.get_sequence("children")
@@ -106,7 +106,7 @@ def test_node_set(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- base = _yaml.load(filename)
+ base = _yaml.load(filename, shortname=None)
assert "mother" not in base
base["mother"] = "snow white"
@@ -118,7 +118,7 @@ def test_node_set_overwrite(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- base = _yaml.load(filename)
+ base = _yaml.load(filename, shortname=None)
# Overwrite a string
assert base.get_str("kind") == "pony"
@@ -136,7 +136,7 @@ def test_node_set_list_element(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
- base = _yaml.load(filename)
+ base = _yaml.load(filename, shortname=None)
assert base.get_str_list("moods") == ["happy", "sad"]
base.get_sequence("moods")[0] = "confused"
@@ -154,8 +154,8 @@ def test_composite_preserve_originals(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
overlayfile = os.path.join(datafiles.dirname, datafiles.basename, "composite.yaml")
- base = _yaml.load(filename)
- overlay = _yaml.load(overlayfile)
+ base = _yaml.load(filename, shortname=None)
+ overlay = _yaml.load(overlayfile, shortname=None)
base_copy = base.clone()
overlay._composite(base_copy)
@@ -216,7 +216,7 @@ def test_list_composition(datafiles, filename, tmpdir, index, length, mood, prov
base_file = os.path.join(datafiles.dirname, datafiles.basename, "basics.yaml")
overlay_file = os.path.join(datafiles.dirname, datafiles.basename, filename)
- base = _yaml.load(base_file, "basics.yaml")
+ base = _yaml.load(base_file, shortname="basics.yaml")
overlay = _yaml.load(overlay_file, shortname=filename)
overlay._composite(base)
@@ -369,7 +369,7 @@ def test_convert_value_to_string(datafiles):
conf_file = os.path.join(datafiles.dirname, datafiles.basename, "convert_value_to_str.yaml")
# Run file through yaml to convert it
- test_dict = _yaml.load(conf_file)
+ test_dict = _yaml.load(conf_file, shortname=None)
user_config = test_dict.get_str("Test1")
assert isinstance(user_config, str)
@@ -393,7 +393,7 @@ def test_value_doesnt_match_expected(datafiles):
conf_file = os.path.join(datafiles.dirname, datafiles.basename, "convert_value_to_str.yaml")
# Run file through yaml to convert it
- test_dict = _yaml.load(conf_file)
+ test_dict = _yaml.load(conf_file, shortname=None)
with pytest.raises(LoadError) as exc:
test_dict.get_int("Test4")
@@ -445,7 +445,7 @@ def test_node_find_target(datafiles, case):
filename = os.path.join(datafiles.dirname, datafiles.basename, "traversal.yaml")
# We set copy_tree in order to ensure that the nodes in `loaded`
# are not the same nodes as in `prov.toplevel`
- loaded = _yaml.load(filename, copy_tree=True)
+ loaded = _yaml.load(filename, shortname=None, copy_tree=True)
prov = loaded.get_provenance()
@@ -477,7 +477,7 @@ def test_node_find_target(datafiles, case):
@pytest.mark.datafiles(os.path.join(DATA_DIR))
def test_node_find_target_fails(datafiles):
filename = os.path.join(datafiles.dirname, datafiles.basename, "traversal.yaml")
- loaded = _yaml.load(filename, copy_tree=True)
+ loaded = _yaml.load(filename, shortname=None, copy_tree=True)
brand_new = Node.from_dict({})