diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-06-10 07:51:57 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:02 +0000 |
commit | 38671fb53f4522d046bed94699db8cc344ac2862 (patch) | |
tree | dc75c432d897d393d3a568290d45d762c7bde093 /tests/internals | |
parent | fcef3658433f74a2f396ed353bb3534f0001f3d8 (diff) | |
download | buildstream-38671fb53f4522d046bed94699db8cc344ac2862.tar.gz |
_yaml: Add 'as_str()' on ScalarNode and 'get_scalar()' on MappingNode
- 'get_scalar()' allows retrieving a scalar node from a mapping.
- 'as_str()' casts a ScalarNode into a string (thus removing the node
information).
Both together, those replace 'node_get(mapping, key, type=str)' but
also allow retrieving the 'Node' itself, which will allow in the future
lazier provenance computation.
Diffstat (limited to 'tests/internals')
-rw-r--r-- | tests/internals/yaml.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/tests/internals/yaml.py b/tests/internals/yaml.py index a553cbf0f..012449ee4 100644 --- a/tests/internals/yaml.py +++ b/tests/internals/yaml.py @@ -128,7 +128,7 @@ def test_node_set(datafiles): assert 'mother' not in base _yaml.node_set(base, 'mother', 'snow white') - assert _yaml.node_get(base, str, 'mother') == 'snow white' + assert base.get_str('mother') == 'snow white' @pytest.mark.datafiles(os.path.join(DATA_DIR)) @@ -141,14 +141,14 @@ def test_node_set_overwrite(datafiles): base = _yaml.load(filename) # Overwrite a string - assert _yaml.node_get(base, str, 'kind') == 'pony' + assert base.get_str('kind') == 'pony' _yaml.node_set(base, 'kind', 'cow') - assert _yaml.node_get(base, str, 'kind') == 'cow' + assert base.get_str('kind') == 'cow' # Overwrite a list as a string assert _yaml.node_get(base, list, 'moods') == ['happy', 'sad'] _yaml.node_set(base, 'moods', 'unemotional') - assert _yaml.node_get(base, str, 'moods') == 'unemotional' + assert base.get_str('moods') == 'unemotional' @pytest.mark.datafiles(os.path.join(DATA_DIR)) @@ -192,10 +192,10 @@ def test_composite_preserve_originals(datafiles): orig_extra = base.get_mapping('extra') # Test that the node copy has the overridden value... - assert _yaml.node_get(copy_extra, str, 'old') == 'override' + assert copy_extra.get_str('old') == 'override' # But the original node is not effected by the override. - assert _yaml.node_get(orig_extra, str, 'old') == 'new' + assert orig_extra.get_str('old') == 'new' # Tests for list composition @@ -258,7 +258,7 @@ def test_list_composition(datafiles, filename, tmpdir, assert len(children) == length child = children[index] - assert _yaml.node_get(child, str, 'mood') == mood + assert child.get_str('mood') == mood assert_provenance(prov_file, prov_line, prov_col, child, 'mood') @@ -394,7 +394,7 @@ def test_list_composition_twice(datafiles, tmpdir, filename1, filename2, assert len(children) == length child = children[index] - assert _yaml.node_get(child, str, 'mood') == mood + assert child.get_str('mood') == mood assert_provenance(prov_file, prov_line, prov_col, child, 'mood') ##################### @@ -411,7 +411,7 @@ def test_list_composition_twice(datafiles, tmpdir, filename1, filename2, assert len(children) == length child = children[index] - assert _yaml.node_get(child, str, 'mood') == mood + assert child.get_str('mood') == mood assert_provenance(prov_file, prov_line, prov_col, child, 'mood') @@ -424,19 +424,19 @@ def test_convert_value_to_string(datafiles): # Run file through yaml to convert it test_dict = _yaml.load(conf_file) - user_config = _yaml.node_get(test_dict, str, "Test1") + user_config = test_dict.get_str("Test1") assert isinstance(user_config, str) assert user_config == "1_23_4" - user_config = _yaml.node_get(test_dict, str, "Test2") + user_config = test_dict.get_str("Test2") assert isinstance(user_config, str) assert user_config == "1.23.4" - user_config = _yaml.node_get(test_dict, str, "Test3") + user_config = test_dict.get_str("Test3") assert isinstance(user_config, str) assert user_config == "1.20" - user_config = _yaml.node_get(test_dict, str, "Test4") + user_config = test_dict.get_str("Test4") assert isinstance(user_config, str) assert user_config == "OneTwoThree" |