summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-08-17 13:15:20 +0200
committerAnthon van der Neut <anthon@mnt.org>2016-08-17 13:15:20 +0200
commitd8b794cccf8054a73ae61b6128e342b23b390e1d (patch)
tree26a8aa35793c493044fb52524434715630872419
parentb7333fbcfa612f59ec745e5c7d425ee48a947fa2 (diff)
downloadruamel.yaml-d8b794cccf8054a73ae61b6128e342b23b390e1d.tar.gz
operator "in" for merged maps
-rw-r--r--README.rst3
-rw-r--r--__init__.py2
-rw-r--r--_test/test_comments.py18
-rw-r--r--_test/test_fail.py12
-rw-r--r--comments.py8
5 files changed, 36 insertions, 7 deletions
diff --git a/README.rst b/README.rst
index 1965ca6..8c70e81 100644
--- a/README.rst
+++ b/README.rst
@@ -18,6 +18,9 @@ ChangeLog
::
+ 0.12.3 (2016-08-XX):
+ - proper 'in' operation for merged CommentedMaps (implementation by J.Ngo)
+
0.12.2 (2016-08-16):
- minor improvements based on feedback from M. Crusoe
https://bitbucket.org/ruamel/yaml/issues/42/
diff --git a/__init__.py b/__init__.py
index 7bb5066..a7817d0 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, 2),
+ version_info=(0, 12, 2, "dev"),
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 b6b12e2..0cab926 100644
--- a/_test/test_comments.py
+++ b/_test/test_comments.py
@@ -472,3 +472,21 @@ class TestInsertInMapping:
about: Art Vandelay is a fictional character that George invents...
last name: Vandelay # new key
""")
+
+
+class TestCommentedMapMerge:
+ def test_in_operator(self):
+ data = round_trip_load("""
+ x: &base
+ a: 1
+ b: 2
+ c: 3
+ y:
+ <<: *base
+ k: 4
+ l: 5
+ """)
+ assert data['x']['a'] == 1
+ assert 'a' in data['x']
+ assert data['y']['a'] == 1
+ assert 'a' in data['y']
diff --git a/_test/test_fail.py b/_test/test_fail.py
index 852fde7..34516a0 100644
--- a/_test/test_fail.py
+++ b/_test/test_fail.py
@@ -12,7 +12,7 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump
class TestCommentFailures:
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_set_comment_before_tag(self):
# no comments before tags
round_trip("""
@@ -47,7 +47,7 @@ class TestCommentFailures:
# this is the end
""")
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_comment_dash_line(self):
round_trip("""
- # abc
@@ -72,7 +72,7 @@ class TestCommentFailures:
class TestIndentFailures:
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_roundtrip_four_space_indents(self):
s = (
'a:\n'
@@ -93,7 +93,7 @@ class TestIndentFailures:
- bar
""")
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_roundtrip_four_space_indents_expl_indent(self):
s = (
'a:\n'
@@ -114,7 +114,7 @@ class TestIndentFailures:
- bar
""")
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_indent_not_retained(self):
round_trip("""
verbosity: 1 # 0 is minimal output, -1 none
@@ -192,7 +192,7 @@ class TestIndentFailures:
class TestTagFailures:
- @pytest.mark.xfail
+ @pytest.mark.xfail(strict=True)
def test_standard_short_tag(self):
round_trip("""\
!!map
diff --git a/comments.py b/comments.py
index c4bffce..07e2e9b 100644
--- a/comments.py
+++ b/comments.py
@@ -425,6 +425,14 @@ class CommentedMap(ordereddict, CommentedBase):
return merged[1][key]
raise
+ def __contains__(self, key):
+ if ordereddict.__contains__(self, key):
+ return True
+ for merged in getattr(self, merge_attrib, []):
+ if key in merged[1]:
+ return True
+ return False
+
def get(self, key, default=None):
try:
return self.__getitem__(key)