summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-09-15 17:47:45 +0200
committerAnthon van der Neut <anthon@mnt.org>2016-09-15 17:47:45 +0200
commit1dbffd0a290a757547da1bf9a98123b5b361b333 (patch)
tree3dd128f5d1ecd0e586437574a5a8a91a56691fad
parent4682aff2579c954d79439f5dee6e1d848fe6ea58 (diff)
downloadruamel.yaml-1dbffd0a290a757547da1bf9a98123b5b361b333.tar.gz
fix for issue #60, merges not printing correctly0.12.13
reported by Tal Liron
-rw-r--r--README.rst4
-rw-r--r--__init__.py2
-rw-r--r--_test/test_comments.py23
-rw-r--r--comments.py6
4 files changed, 34 insertions, 1 deletions
diff --git a/README.rst b/README.rst
index 9101755..4203014 100644
--- a/README.rst
+++ b/README.rst
@@ -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)