diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-04-04 10:05:01 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-04-04 10:05:01 +0200 |
commit | 334c46400c2334b3939c76ab7a7b5d9195b6d131 (patch) | |
tree | 1f92afaffb8689b508234157a179f40df3b84856 /_test | |
parent | 106d8df15be91d294b6a6efd4476fdc87c0a9b5d (diff) | |
download | ruamel.yaml-334c46400c2334b3939c76ab7a7b5d9195b6d131.tar.gz |
fix issue #109 and #110
issue 109: None not represented round-trippable at top level, reported by
Andrea Censi
issue 110: .replace() on a ScalarString subclass would return a string instead
of an instance of that subclass, reported by sandres23
Diffstat (limited to '_test')
-rw-r--r-- | _test/test_none.py | 42 | ||||
-rw-r--r-- | _test/test_string.py | 31 |
2 files changed, 73 insertions, 0 deletions
diff --git a/_test/test_none.py b/_test/test_none.py new file mode 100644 index 0000000..ad51109 --- /dev/null +++ b/_test/test_none.py @@ -0,0 +1,42 @@ +# coding: utf-8 + + +import pytest # NOQA +import ruamel.yaml # NOQA + + +class TestNone: + def test_dump00(self): + data = None + s = ruamel.yaml.round_trip_dump(data) + assert s == 'null\n...\n' + d = ruamel.yaml.round_trip_load(s) + assert d == data + + def test_dump01(self): + data = None + s = ruamel.yaml.round_trip_dump(data, explicit_end=True) + assert s == 'null\n...\n' + d = ruamel.yaml.round_trip_load(s) + assert d == data + + def test_dump02(self): + data = None + s = ruamel.yaml.round_trip_dump(data, explicit_end=False) + assert s == 'null\n...\n' + d = ruamel.yaml.round_trip_load(s) + assert d == data + + def test_dump03(self): + data = None + s = ruamel.yaml.round_trip_dump(data, explicit_start=True) + assert s == '---\n...\n' + d = ruamel.yaml.round_trip_load(s) + assert d == data + + def test_dump04(self): + data = None + s = ruamel.yaml.round_trip_dump(data, explicit_start=True, explicit_end=False) + assert s == '---\n...\n' + d = ruamel.yaml.round_trip_load(s) + assert d == data diff --git a/_test/test_string.py b/_test/test_string.py index 13474b5..6b3070f 100644 --- a/_test/test_string.py +++ b/_test/test_string.py @@ -17,6 +17,7 @@ and the chomping modifiers: import pytest import platform +import ruamel # from ruamel.yaml.compat import ordereddict from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA @@ -124,3 +125,33 @@ class TestQuotedScalarString: """, outp=""" a: abc """) + + +class TestReplace: + """inspired by issue 110 from sandres23""" + def test_replace_preserved_scalar_string(self): + s = dedent("""\ + foo: | + foo + foo + bar + foo + """) + data = round_trip_load(s, preserve_quotes=True) + so = data['foo'].replace('foo', 'bar', 2) + assert isinstance(so, ruamel.yaml.scalarstring.PreservedScalarString) + assert so == dedent(""" + bar + bar + bar + foo + """) + + def test_replace_double_quoted_scalar_string(self): + s = dedent("""\ + foo: "foo foo bar foo" + """) + data = round_trip_load(s, preserve_quotes=True) + so = data['foo'].replace('foo', 'bar', 2) + assert isinstance(so, ruamel.yaml.scalarstring.DoubleQuotedScalarString) + assert so == 'bar bar bar foo' |