mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 12:06:53 +00:00
Merge pull request #478 from pre-commit/remove_todo
check-json: resolve TODO
This commit is contained in:
commit
2322277afd
2 changed files with 7 additions and 2 deletions
|
|
@ -14,8 +14,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
try:
|
try:
|
||||||
json.load(f)
|
json.load(f)
|
||||||
# TODO: need UnicodeDecodeError?
|
except ValueError as exc:
|
||||||
except (ValueError, UnicodeDecodeError) as exc:
|
|
||||||
print(f'{filename}: Failed to json decode ({exc})')
|
print(f'{filename}: Failed to json decode ({exc})')
|
||||||
retval = 1
|
retval = 1
|
||||||
return retval
|
return retval
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,9 @@ def test_main(capsys, filename, expected_retval):
|
||||||
if expected_retval == 1:
|
if expected_retval == 1:
|
||||||
stdout, _ = capsys.readouterr()
|
stdout, _ = capsys.readouterr()
|
||||||
assert filename in stdout
|
assert filename in stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_utf8_file(tmpdir):
|
||||||
|
f = tmpdir.join('t.json')
|
||||||
|
f.write_binary(b'\xa9\xfe\x12')
|
||||||
|
assert main((str(f),))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue