summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2019-08-15 12:18:08 +0200
committerAnthon van der Neut <anthon@mnt.org>2019-08-15 12:18:08 +0200
commitff8e03fe5542a9d7930a5720450c59bb9e9eaaf3 (patch)
tree6f22060b92e421ca0bad2a2df0eb499518c4b07e /_test
parentc355613aea4e2045fa5360837bd0b622fb84877b (diff)
downloadruamel.yaml-ff8e03fe5542a9d7930a5720450c59bb9e9eaaf3.tar.gz
preserve directives, optional push root level scalar to own line
You need to set YAML().scalar_after_indicator = False to get a single scalar document starting on its own line (instead of after the directives end indicator: --- abc") fixes issue #304 *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))*
Diffstat (limited to '_test')
-rw-r--r--_test/roundtrip.py49
-rw-r--r--_test/test_issues.py11
2 files changed, 60 insertions, 0 deletions
diff --git a/_test/roundtrip.py b/_test/roundtrip.py
index ee430a3..090b9e0 100644
--- a/_test/roundtrip.py
+++ b/_test/roundtrip.py
@@ -151,6 +151,55 @@ def round_trip(
return data
+def na_round_trip(
+ inp,
+ outp=None,
+ extra=None,
+ intermediate=None,
+ indent=None,
+ top_level_colon_align=None,
+ prefix_colon=None,
+ preserve_quotes=None,
+ explicit_start=None,
+ explicit_end=None,
+ version=None,
+ dump_data=None,
+):
+ """
+ inp: input string to parse
+ outp: expected output (equals input if not specified)
+ """
+ if outp is None:
+ outp = inp
+ if version is not None:
+ version = version
+ doutp = dedent(outp)
+ if extra is not None:
+ doutp += extra
+ yaml = YAML()
+ yaml.preserve_quotes = preserve_quotes
+ yaml.scalar_after_indicator = False # newline after every directives end
+ data = yaml.load(inp)
+ if dump_data:
+ print('data', data)
+ if intermediate is not None:
+ if isinstance(intermediate, dict):
+ for k, v in intermediate.items():
+ if data[k] != v:
+ print('{0!r} <> {1!r}'.format(data[k], v))
+ raise ValueError
+ yaml.indent = indent
+ yaml.top_level_colon_align = top_level_colon_align
+ yaml.prefix_colon = prefix_colon
+ yaml.explicit_start = explicit_start
+ yaml.explicit_end = explicit_end
+ res = yaml.dump(data, compare=doutp)
+ #if res != doutp:
+ # diff(doutp, res, 'input string')
+ #print('\nroundtrip data:\n', res, sep="")
+ #assert res == doutp
+
+
def YAML(**kw):
import ruamel.yaml # NOQA
diff --git a/_test/test_issues.py b/_test/test_issues.py
index 3692f61..9b301a9 100644
--- a/_test/test_issues.py
+++ b/_test/test_issues.py
@@ -8,6 +8,7 @@ import pytest # NOQA
from roundtrip import (
round_trip,
+ na_round_trip,
round_trip_load,
round_trip_dump,
dedent,
@@ -850,6 +851,16 @@ class TestIssues:
match='while scanning a directive'):
yaml.load(inp)
+ def test_issue_304(self):
+ inp = """
+ %YAML 1.2
+ %TAG ! tag:example.com,2019:
+ ---
+ !foo null
+ ...
+ """
+ d = na_round_trip(inp) # NOQA
+
# @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError)
# def test_issue_ xxx(self):
# inp = """