Use unified_diff

This commit is contained in:
Joey Pinhas 2019-09-15 13:48:00 -04:00
parent 27cd688c8e
commit 31e740ed05
2 changed files with 18 additions and 16 deletions

View file

@ -59,7 +59,7 @@ def parse_topkeys(s): # type: (str) -> List[str]
def get_diff(source, target): # type: (str, str) -> str def get_diff(source, target): # type: (str, str) -> str
source_lines = source.splitlines(True) source_lines = source.splitlines(True)
target_lines = target.splitlines(True) target_lines = target.splitlines(True)
diff = ''.join(difflib.ndiff(source_lines, target_lines)) diff = ''.join(difflib.unified_diff(source_lines, target_lines))
return diff return diff

View file

@ -111,22 +111,24 @@ def test_diffing_output(capsys):
resource_path = get_resource_path('not_pretty_formatted_json.json') resource_path = get_resource_path('not_pretty_formatted_json.json')
expected_retval = 1 expected_retval = 1
expected_out = '''\ expected_out = '''\
{ ---
- "foo": +++
- "bar", @@ -1,6 +1,9 @@
- "alist": [2, 34, 234], {
+ "alist": [ - "foo":
+ 2, - "bar",
+ 34, - "alist": [2, 34, 234],
+ 234 - "blah": null
+ ], + "alist": [
- "blah": null + 2,
+ "blah": null, + 34,
? + + 234
+ "foo": "bar" + ],
} + "blah": null,
+ "foo": "bar"
}
''' ''' # noqa: W291
expected_err = 'File {} is not pretty-formatted\n'.format(resource_path) expected_err = 'File {} is not pretty-formatted\n'.format(resource_path)
actual_retval = main([resource_path]) actual_retval = main([resource_path])