mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 04:34:16 +00:00
Print file line stderr
This commit is contained in:
parent
93b7b66cda
commit
831d2a99ab
2 changed files with 8 additions and 14 deletions
|
|
@ -120,7 +120,10 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||||
)
|
)
|
||||||
|
|
||||||
if contents != pretty_contents:
|
if contents != pretty_contents:
|
||||||
print('File {} is not pretty-formatted'.format(json_file))
|
print(
|
||||||
|
'File {} is not pretty-formatted'.format(json_file),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
|
||||||
if args.autofix:
|
if args.autofix:
|
||||||
_autofix(json_file, pretty_contents)
|
_autofix(json_file, pretty_contents)
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,8 @@ def test_badfile_main():
|
||||||
|
|
||||||
|
|
||||||
def test_diffing_output(capsys):
|
def test_diffing_output(capsys):
|
||||||
resource_path = get_resource_path('not_pretty_formatted_json.json')
|
|
||||||
expected_retval = 1
|
expected_retval = 1
|
||||||
expected_diff = '''
|
expected_out = ''' {
|
||||||
{
|
|
||||||
- "foo":
|
- "foo":
|
||||||
- "bar",
|
- "bar",
|
||||||
- "alist": [2, 34, 234],
|
- "alist": [2, 34, 234],
|
||||||
|
|
@ -126,17 +124,10 @@ def test_diffing_output(capsys):
|
||||||
+ "foo": "bar"
|
+ "foo": "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# output should include a line with the filepath, build it here
|
|
||||||
file_output_line = 'File {} is not pretty-formatted'.format(resource_path)
|
|
||||||
# prepend the above line to the diff
|
|
||||||
expected_output = file_output_line + expected_diff
|
|
||||||
|
|
||||||
actual_retval = main([resource_path])
|
actual_retval = main([get_resource_path('not_pretty_formatted_json.json')])
|
||||||
actual_output = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
|
|
||||||
assert actual_retval == expected_retval
|
assert actual_retval == expected_retval
|
||||||
|
assert out == expected_out
|
||||||
actual_output = '\n'.join(actual_output)
|
|
||||||
assert actual_output == expected_output
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue