diff options
-rw-r--r-- | README.rst | 4 | ||||
-rw-r--r-- | __init__.py | 2 | ||||
-rw-r--r-- | _test/test_comments.py | 23 | ||||
-rw-r--r-- | comments.py | 6 |
4 files changed, 34 insertions, 1 deletions
@@ -18,6 +18,10 @@ ChangeLog :: + 0.12.13 (2016-09-15): + - Fix for issue #60 representation of CommentedMap with merge + keys incorrect (reported by Tal Liron) + 0.12.11 (2016-09-06): - Fix issue 58 endless loop in scanning tokens (reported by Christopher Lambert) diff --git a/__init__.py b/__init__.py index 9a8d456..15b8eff 100644 --- a/__init__.py +++ b/__init__.py @@ -9,7 +9,7 @@ from __future__ import absolute_import _package_data = dict( full_package_name="ruamel.yaml", - version_info=(0, 12, 12), + version_info=(0, 12, 13), author="Anthon van der Neut", author_email="a.van.der.neut@ruamel.eu", description="ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order", # NOQA diff --git a/_test/test_comments.py b/_test/test_comments.py index b858fbc..f2aa1f0 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -491,6 +491,29 @@ class TestCommentedMapMerge: assert data['y']['a'] == 1 assert 'a' in data['y'] + def test_issue_60(self): + data = round_trip_load(""" + x: &base + a: 1 + y: + <<: *base + """) + assert data['x']['a'] == 1 + assert data['y']['a'] == 1 + assert str(data['y']) == """ordereddict([('a', 1)])""" + + def test_issue_60_1(self): + data = round_trip_load(""" + x: &base + a: 1 + y: + <<: *base + b: 2 + """) + assert data['x']['a'] == 1 + assert data['y']['a'] == 1 + assert str(data['y']) == """ordereddict([('b', 2), ('a', 1)])""" + class TestEmptyLines: # prompted by issue 46 from Alex Harvey diff --git a/comments.py b/comments.py index c3d17b0..c57b647 100644 --- a/comments.py +++ b/comments.py @@ -501,6 +501,7 @@ class CommentedMap(ordereddict, CommentedBase): try: return ordereddict.__getitem__(self, key) except KeyError: + print('keyerror') for merged in getattr(self, merge_attrib, []): if key in merged[1]: return merged[1][key] @@ -525,6 +526,11 @@ class CommentedMap(ordereddict, CommentedBase): except: return default + def __repr__(self): + if not hasattr(self, merge_attrib): + return ordereddict.__repr__(self) + return 'ordereddict(' + repr(list(self._items())) + ')' + def non_merged_items(self): for x in ordereddict.__iter__(self): yield x, ordereddict.__getitem__(self, x) |