Skip to content

Commit e2d622c

Browse files
committed
test that load_json provides filename if invalid
1 parent 353da69 commit e2d622c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

heudiconv/tests/test_utils.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import json
12
import os
23
import os.path as op
34
from heudiconv.utils import (
45
get_known_heuristics_with_descriptions,
56
get_heuristic_description,
67
load_heuristic,
7-
json_dumps_pretty)
8+
json_dumps_pretty,
9+
load_json)
810

911
import pytest
1012
from .utils import HEURISTICS_PATH
@@ -58,4 +60,17 @@ def test_json_dumps_pretty():
5860
'Mar 3 2017 10:46:13 by eja'
5961
# just the date which reveals the issue
6062
# tstr = 'Mar 3 2017 10:46:13 by eja'
61-
assert pretty({'WipMemBlock': tstr}) == '{\n "WipMemBlock": "%s"\n}' % tstr
63+
assert pretty({'WipMemBlock': tstr}) == '{\n "WipMemBlock": "%s"\n}' % tstr
64+
65+
66+
def test_load_json(tmp_path, capsys):
67+
# test invalid json
68+
content = "I'm Jason Bourne"
69+
fname = "invalid.json"
70+
json_file = tmp_path / fname
71+
json_file.write_text(content)
72+
73+
with pytest.raises(json.JSONDecodeError):
74+
load_json(json_file)
75+
captured = capsys.readouterr()
76+
assert fname in captured.out

0 commit comments

Comments
 (0)