You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/01/24 13:37:11 UTC

[buildstream] 04/06: tests/internals/yaml.py: Test error reporting of SequenceNode.as_str_list()

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/change-remote-config
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit b38e387fef01ddb0a0f544d47c161bc655b010e1
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Sun Jan 24 12:45:45 2021 +0900

    tests/internals/yaml.py: Test error reporting of SequenceNode.as_str_list()
    
    Test bad data in what is expected to be lists of strings, tested
    indirectly via MappingNode.get_str_list()
---
 tests/internals/yaml.py                | 20 ++++++++++++++++++++
 tests/internals/yaml/list-of-dict.yaml |  5 +++++
 tests/internals/yaml/list-of-list.yaml |  3 +++
 3 files changed, 28 insertions(+)

diff --git a/tests/internals/yaml.py b/tests/internals/yaml.py
index 4727d5d..b577c7e 100644
--- a/tests/internals/yaml.py
+++ b/tests/internals/yaml.py
@@ -482,3 +482,23 @@ def test_node_find_target_fails(datafiles):
     brand_new = Node.from_dict({})
 
     assert loaded._find(brand_new) is None
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR))
+@pytest.mark.parametrize(
+    "filename, provenance",
+    [
+        ("list-of-dict.yaml", "list-of-dict.yaml [line 2 column 2]"),
+        ("list-of-list.yaml", "list-of-list.yaml [line 2 column 2]"),
+    ],
+    ids=["list-of-dict", "list-of-list"],
+)
+def test_get_str_list_invalid(datafiles, filename, provenance):
+    conf_file = os.path.join(datafiles.dirname, datafiles.basename, filename)
+
+    base = _yaml.load(conf_file, shortname=None)
+
+    with pytest.raises(LoadError) as exc:
+        strings = base.get_str_list("list")
+    assert exc.value.reason == LoadErrorReason.INVALID_DATA
+    assert provenance in str(exc.value)
diff --git a/tests/internals/yaml/list-of-dict.yaml b/tests/internals/yaml/list-of-dict.yaml
new file mode 100644
index 0000000..b3f6e50
--- /dev/null
+++ b/tests/internals/yaml/list-of-dict.yaml
@@ -0,0 +1,5 @@
+list:
+- key1: one
+  key2: two
+- key1: one
+  key2: two
diff --git a/tests/internals/yaml/list-of-list.yaml b/tests/internals/yaml/list-of-list.yaml
new file mode 100644
index 0000000..4ac183a
--- /dev/null
+++ b/tests/internals/yaml/list-of-list.yaml
@@ -0,0 +1,3 @@
+list:
+- [ "one", "two" ]
+- [ "one", "two" ]