Skip to content

Commit 831d2a9

Browse files
committed
Print file line stderr
1 parent 93b7b66 commit 831d2a9

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

pre_commit_hooks/pretty_format_json.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
120120
)
121121

122122
if contents != pretty_contents:
123-
print('File {} is not pretty-formatted'.format(json_file))
123+
print(
124+
'File {} is not pretty-formatted'.format(json_file),
125+
file=sys.stderr,
126+
)
124127

125128
if args.autofix:
126129
_autofix(json_file, pretty_contents)

tests/pretty_format_json_test.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ def test_badfile_main():
108108

109109

110110
def test_diffing_output(capsys):
111-
resource_path = get_resource_path('not_pretty_formatted_json.json')
112111
expected_retval = 1
113-
expected_diff = '''
114-
{
112+
expected_out = ''' {
115113
- "foo":
116114
- "bar",
117115
- "alist": [2, 34, 234],
@@ -126,17 +124,10 @@ def test_diffing_output(capsys):
126124
+ "foo": "bar"
127125
}
128126
129-
130127
'''
131-
# output should include a line with the filepath, build it here
132-
file_output_line = 'File {} is not pretty-formatted'.format(resource_path)
133-
# prepend the above line to the diff
134-
expected_output = file_output_line + expected_diff
135128

136-
actual_retval = main([resource_path])
137-
actual_output = capsys.readouterr()
129+
actual_retval = main([get_resource_path('not_pretty_formatted_json.json')])
130+
out, err = capsys.readouterr()
138131

139132
assert actual_retval == expected_retval
140-
141-
actual_output = '\n'.join(actual_output)
142-
assert actual_output == expected_output
133+
assert out == expected_out

0 commit comments

Comments
 (0)