From 76b0f89d8fcbf88616f62c01551731cc043f86a3 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Fri, 21 Sep 2018 20:39:48 +0200 Subject: fix #233 fix #231 reverting to subclass dict resp list for CommentedMap/Seq had to reimplement round-trippable mappings with merge-keys to get both JSON dumping and casting using dict(**some_commented_map) to work. (JSON dump of merge maps not tested) *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))* --- _test/test_issues.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to '_test') diff --git a/_test/test_issues.py b/_test/test_issues.py index 2651cff..80be4f4 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -187,13 +187,12 @@ class TestIssues: assert res == yaml_str.replace(' b ', ' B ').replace(' d\n', ' D\n') def test_issue_176_test_slicing(self): - from ruamel.yaml.comments import CommentedSeq + from ruamel.yaml.compat import PY2 mss = round_trip_load('[0, 1, 2, 3, 4]') assert len(mss) == 5 assert mss[2:2] == [] assert mss[2:4] == [2, 3] - assert isinstance(mss[2:4], CommentedSeq) assert mss[1::2] == [1, 3] # slice assignment @@ -219,10 +218,18 @@ class TestIssues: m[1::2] = [42, 43] assert m == [0, 42, 2, 43, 4] m = mss[:] - with pytest.raises(TypeError, match='too many'): - m[1::2] = [42, 43, 44] - with pytest.raises(TypeError, match='not enough'): - m[1::2] = [42] + if PY2: + with pytest.raises(ValueError, match='attempt to assign'): + m[1::2] = [42, 43, 44] + else: + with pytest.raises(TypeError, match='too many'): + m[1::2] = [42, 43, 44] + if PY2: + with pytest.raises(ValueError, match='attempt to assign'): + m[1::2] = [42] + else: + with pytest.raises(TypeError, match='not enough'): + m[1::2] = [42] m = mss[:] m += [5] m[1::2] = [42, 43, 44] @@ -408,7 +415,6 @@ class TestIssues: with pytest.raises(ruamel.yaml.parser.ParserError): yaml.safe_load('{]') - # @pytest.mark.xfail(strict=True, reason='not a dict subclass', raises=TypeError) def test_issue_233(self): from ruamel.yaml import YAML import json @@ -417,7 +423,6 @@ class TestIssues: data = yaml.load('{}') json_str = json.dumps(data) # NOQA - @pytest.mark.xfail(strict=True, reason='not a list subclass', raises=TypeError) def test_issue_233a(self): from ruamel.yaml import YAML import json -- cgit v1.2.1