This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch tristan/yaml-fixes in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 45b446c42cf4e674957ea8bb7fc4566d4d63981b Author: Tristan van Berkom <[email protected]> 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 + + [email protected](os.path.join(DATA_DIR)) [email protected]( + "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" ]
