diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-08-09 11:03:04 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-08-09 11:03:04 +0200 |
commit | b3b5301e1b0a21d81a2ec1501df9ef92abac5ce2 (patch) | |
tree | 3728d199188d082ceba1613eaaa7f1bd8d79c350 /_test/roundtrip.py | |
parent | bb292fb88d1e5f6d8a3139e94e0678ce4c55ac1f (diff) | |
download | ruamel.yaml-b3b5301e1b0a21d81a2ec1501df9ef92abac5ce2.tar.gz |
update tests
Diffstat (limited to '_test/roundtrip.py')
-rw-r--r-- | _test/roundtrip.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/_test/roundtrip.py b/_test/roundtrip.py index 00413e6..9774fc4 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -4,6 +4,7 @@ from __future__ import print_function """ helper routines for testing round trip of commented YAML data """ +import sys import textwrap import ruamel.yaml @@ -54,6 +55,19 @@ def round_trip_dump(data, indent=None, block_seq_indent=None, top_level_colon_al version=version) +def diff(inp, outp, file_name='stdin'): + import difflib + inl = inp.splitlines(True) # True for keepends + outl = outp.splitlines(True) + diff = difflib.unified_diff(inl, outl, file_name, 'round trip YAML') + # 2.6 difflib has trailing space on filename lines %-) + strip_trailing_space = sys.version_info < (2, 7) + for line in diff: + if strip_trailing_space and line[:4] in ['--- ', '+++ ']: + line = line.rstrip() + '\n' + sys.stdout.write(line) + + def round_trip(inp, outp=None, extra=None, intermediate=None, indent=None, block_seq_indent=None, top_level_colon_align=None, prefix_colon=None, preserve_quotes=None, @@ -81,7 +95,9 @@ def round_trip(inp, outp=None, extra=None, intermediate=None, indent=None, explicit_start=explicit_start, explicit_end=explicit_end, version=version) - print('roundtrip data:\n', res, sep='') + if res != doutp: + diff(doutp, res, "input string") + print('\nroundtrip data:\n', res, sep='') assert res == doutp res = round_trip_dump(data, indent=indent, block_seq_indent=block_seq_indent, top_level_colon_align=top_level_colon_align, |