diff options
Diffstat (limited to '_test/test_yamlfile.py')
-rw-r--r-- | _test/test_yamlfile.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/_test/test_yamlfile.py b/_test/test_yamlfile.py index a02fcab..f1de872 100644 --- a/_test/test_yamlfile.py +++ b/_test/test_yamlfile.py @@ -1,11 +1,11 @@ - -from __future__ import print_function +# coding: utf-8 """ various test cases for YAML files """ import sys +import io import pytest # NOQA import platform @@ -25,7 +25,7 @@ class TestYAML: import ruamel.yaml # NOQA x = ordereddict([('a', 1), ('b', 2)]) - res = ruamel.yaml.dump(x, default_flow_style=False) + res = round_trip_dump(x, default_flow_style=False) assert res == dedent(""" !!omap - a: 1 @@ -48,7 +48,7 @@ class TestYAML: # OrderedDict mapped to !!omap x = OrderedDict([('a', 1), ('b', 2)]) - res = ruamel.yaml.dump(x, Dumper=ruamel.yaml.RoundTripDumper, default_flow_style=False) + res = round_trip_dump(x, default_flow_style=False) assert res == dedent(""" !!omap - a: 1 @@ -65,7 +65,7 @@ class TestYAML: # OrderedDict mapped to !!omap x = ordereddict([('a', 1), ('b', 2)]) - res = ruamel.yaml.dump(x, Dumper=ruamel.yaml.RoundTripDumper, default_flow_style=False) + res = round_trip_dump(x, default_flow_style=False) assert res == dedent(""" !!omap - a: 1 @@ -89,8 +89,12 @@ class TestYAML: import ruamel.yaml # NOQA x = set(['a', 'b', 'c']) - res = ruamel.yaml.dump(x, default_flow_style=False) - assert res == dedent(""" + # cannot use round_trip_dump, it doesn't show null in block style + buf = io.StringIO() + yaml = ruamel.yaml.YAML(typ='unsafe', pure=True) + yaml.default_flow_style = False + yaml.dump(x, buf) + assert buf.getvalue() == dedent(""" !!set a: null b: null @@ -202,15 +206,19 @@ class TestYAML: def test_load_all_perserve_quotes(self): import ruamel.yaml # NOQA + yaml = ruamel.yaml.YAML() + yaml.preserve_quotes = True s = dedent("""\ a: 'hello' --- b: "goodbye" """) data = [] - for x in ruamel.yaml.round_trip_load_all(s, preserve_quotes=True): + for x in yaml.load_all(s): data.append(x) - out = ruamel.yaml.dump_all(data, Dumper=ruamel.yaml.RoundTripDumper) + buf = ruamel.yaml.compat.StringIO() + yaml.dump_all(data, buf) + out = buf.getvalue() print(type(data[0]['a']), data[0]['a']) # out = ruamel.yaml.round_trip_dump_all(data) print(out) |