diff options
author | Anthon van der Neut <anthon@mnt.org> | 2016-08-17 23:20:49 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2016-08-17 23:20:49 +0200 |
commit | f21343115c0b7f2849766f741bbe64e6c170a556 (patch) | |
tree | 9d6acdd6db9a3f8cb0ebead98d1233a5da1607cc /_test/test_anchor.py | |
parent | d8b794cccf8054a73ae61b6128e342b23b390e1d (diff) | |
download | ruamel.yaml-f21343115c0b7f2849766f741bbe64e6c170a556.tar.gz |
added .keys(), items(), values(), corrected __contains__
There was a huge problem with 3.4 and 3.3 as the OrderedDict
does not define a __contains__ and the implementation based on
the one by Ngo would not work with merge keys defining keys
that later were in the main dict (which should override).
Fix was to add the merge key info at the point the dict
has been completely created, thus restricting __contains__
automatically to the dict itself (and not test subkeys)
Diffstat (limited to '_test/test_anchor.py')
-rw-r--r-- | _test/test_anchor.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/_test/test_anchor.py b/_test/test_anchor.py index 929b1ed..1c795c0 100644 --- a/_test/test_anchor.py +++ b/_test/test_anchor.py @@ -175,7 +175,7 @@ class TestAnchorsAliases: k: &level_2 { a: 1, b2 } l: &level_1 { a: 10, c: 3 } m: - << : *level_1 + <<: *level_1 c: 30 d: 40 """) @@ -227,3 +227,62 @@ class TestAnchorsAliases: c: 3 b: 2 """) + + +class TestMergeKeysValues: + + yaml_str = dedent("""\ + - &mx + a: x1 + b: x2 + c: x3 + - &my + a: y1 + b: y2 # masked by the one in &mx + d: y4 + - + a: 1 + <<: *mx + m: 6 + <<: *my + """) + + def test_merge_for(self): + from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) + data = round_trip_load(self.yaml_str) + count = 0 + for x in data[2]: + count += 1 + print(count, x) + assert count == len(d[2]) + + def test_merge_keys(self): + from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) + data = round_trip_load(self.yaml_str) + count = 0 + for x in data[2].keys(): + count += 1 + print(count, x) + assert count == len(d[2]) + + def test_merge_values(self): + from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) + data = round_trip_load(self.yaml_str) + count = 0 + for x in data[2].values(): + count += 1 + print(count, x) + assert count == len(d[2]) + + def test_merge_items(self): + from ruamel.yaml import safe_load + d = safe_load(self.yaml_str) + data = round_trip_load(self.yaml_str) + count = 0 + for x in data[2].items(): + count += 1 + print(count, x) + assert count == len(d[2]) |