From 7298136642010d4e02a607f4275ffe3ad5657a14 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Tue, 11 Jun 2019 18:19:46 +0100 Subject: _yaml: Introduce 'get_sequence()' and 'sequence_at()'/'mapping_at()' - Adding 'get_sequence' on MappingNode to access sequences in a mapping - Adding 'sequence_at' on SequenceNode to access sequences in a sequence - Adding 'mapping_at' on SequenceNode to access mappings in a sequence Using "*_at" in sequences allows us to quickly understand if we are dealing with a sequence or a mapping. --- tests/format/include.py | 4 ++-- tests/format/include_composition.py | 18 +++++++++--------- tests/format/options.py | 10 +++++----- tests/format/projectoverrides.py | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'tests/format') diff --git a/tests/format/include.py b/tests/format/include.py index 7c5a35a65..e2e16c34a 100644 --- a/tests/format/include.py +++ b/tests/format/include.py @@ -197,7 +197,7 @@ def test_include_element_overrides_composition(cli, datafiles): 'element.bst']) result.assert_success() loaded = _yaml.load_data(result.output) - assert _yaml.node_get(loaded, list, 'build-commands') == ['first', 'second'] + assert loaded.get_sequence('build-commands').as_str_list() == ['first', 'second'] @pytest.mark.datafiles(DATA_DIR) @@ -215,7 +215,7 @@ def test_list_overide_does_not_fail_upon_first_composition(cli, datafiles): # Assert that the explicitly overwritten public data is present bst = loaded.get_mapping('bst') assert 'foo-commands' in bst - assert _yaml.node_get(bst, list, 'foo-commands') == ['need', 'this'] + assert bst.get_sequence('foo-commands').as_str_list() == ['need', 'this'] @pytest.mark.datafiles(DATA_DIR) diff --git a/tests/format/include_composition.py b/tests/format/include_composition.py index 2051f02d5..b922c7a0e 100644 --- a/tests/format/include_composition.py +++ b/tests/format/include_composition.py @@ -14,7 +14,7 @@ def make_includes(basedir): return Includes(loader) -def test_main_has_prority(tmpdir): +def test_main_has_priority(tmpdir): includes = make_includes(str(tmpdir)) _yaml.dump({'(@)': ['a.yml'], @@ -28,7 +28,7 @@ def test_main_has_prority(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['main'] + assert main.get_sequence('test').as_str_list() == ['main'] def test_include_cannot_append(tmpdir): @@ -44,7 +44,7 @@ def test_include_cannot_append(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['main'] + assert main.get_sequence('test').as_str_list() == ['main'] def test_main_can_append(tmpdir): @@ -60,7 +60,7 @@ def test_main_can_append(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['a', 'main'] + assert main.get_sequence('test').as_str_list() == ['a', 'main'] def test_sibling_cannot_append_backward(tmpdir): @@ -77,7 +77,7 @@ def test_sibling_cannot_append_backward(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['b'] + assert main.get_sequence('test').as_str_list() == ['b'] def test_sibling_can_append_forward(tmpdir): @@ -94,7 +94,7 @@ def test_sibling_can_append_forward(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['a', 'b'] + assert main.get_sequence('test').as_str_list() == ['a', 'b'] def test_lastest_sibling_has_priority(tmpdir): @@ -111,7 +111,7 @@ def test_lastest_sibling_has_priority(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['b'] + assert main.get_sequence('test').as_str_list() == ['b'] def test_main_keeps_keys(tmpdir): @@ -127,7 +127,7 @@ def test_main_keeps_keys(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['a'] + assert main.get_sequence('test').as_str_list() == ['a'] assert main.get_str('something') == 'else' @@ -151,5 +151,5 @@ def test_overwrite_directive_on_later_composite(tmpdir): includes.process(main) - assert _yaml.node_get(main, list, 'test') == ['Overwritten'] + assert main.get_sequence('test').as_str_list() == ['Overwritten'] assert main.get_str('foo') == 'should be present' diff --git a/tests/format/options.py b/tests/format/options.py index e902b8b86..9c0e043f9 100644 --- a/tests/format/options.py +++ b/tests/format/options.py @@ -223,8 +223,8 @@ def test_deep_nesting_level1(cli, datafiles, option, expected): 'element.bst']) result.assert_success() loaded = _yaml.load_data(result.output) - shallow_list = _yaml.node_get(loaded, list, 'shallow-nest') - first_dict = shallow_list[0] + shallow_list = loaded.get_sequence('shallow-nest') + first_dict = shallow_list.mapping_at(0) assert first_dict.get_str('animal') == expected @@ -244,8 +244,8 @@ def test_deep_nesting_level2(cli, datafiles, option, expected): 'element-deeper.bst']) result.assert_success() loaded = _yaml.load_data(result.output) - shallow_list = _yaml.node_get(loaded, list, 'deep-nest') - deeper_list = shallow_list[0] - first_dict = deeper_list[0] + shallow_list = loaded.get_sequence('deep-nest') + deeper_list = shallow_list.sequence_at(0) + first_dict = deeper_list.mapping_at(0) assert first_dict.get_str('animal') == expected diff --git a/tests/format/projectoverrides.py b/tests/format/projectoverrides.py index 4b0c3f4d0..730e43b1e 100644 --- a/tests/format/projectoverrides.py +++ b/tests/format/projectoverrides.py @@ -24,6 +24,6 @@ def test_prepend_configure_commands(cli, datafiles): result.assert_success() loaded = _yaml.load_data(result.output) - config_commands = _yaml.node_get(loaded, list, 'configure-commands') + config_commands = loaded.get_sequence('configure-commands').as_str_list() assert len(config_commands) == 3 assert config_commands[0] == 'echo "Hello World!"' -- cgit v1.2.1