summaryrefslogtreecommitdiff
path: root/_test/roundtrip.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/roundtrip.py')
-rw-r--r--_test/roundtrip.py49
1 files changed, 49 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