Skip to content

Commit e6eb9b2

Browse files
committed
fix some python2/3 incompatibilities
1 parent 9021018 commit e6eb9b2

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

heudiconv/tests/test_utils.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import json
22
import os
33
import os.path as op
4+
5+
try:
6+
from json.decoder import JSONDecodeError
7+
except ImportError:
8+
JSONDecodeError = ValueError
9+
410
from heudiconv.utils import (
511
get_known_heuristics_with_descriptions,
612
get_heuristic_description,
@@ -65,12 +71,22 @@ def test_json_dumps_pretty():
6571

6672
def test_load_json(tmp_path, capsys):
6773
# test invalid json
68-
content = u"I'm Jason Bourne"
69-
fname = "invalid.json"
70-
json_file = tmp_path / fname
71-
json_file.write_text(content)
74+
icontent = u"I'm Jason Bourne"
75+
ifname = "invalid.json"
76+
invalid_json_file = tmp_path / ifname
77+
invalid_json_file.write_text(icontent)
7278

73-
with pytest.raises(json.JSONDecodeError):
74-
load_json(json_file)
79+
with pytest.raises(JSONDecodeError):
80+
load_json(invalid_json_file)
7581
captured = capsys.readouterr()
76-
assert fname in captured.out
82+
assert ifname in captured.out
83+
84+
# test valid json
85+
vcontent = {"secret": "spy"}
86+
vfname = "valid.json"
87+
valid_json_file = tmp_path / vfname
88+
89+
with open(valid_json_file, "w") as vj:
90+
json.dump(vcontent, vj)
91+
92+
assert load_json(valid_json_file) == vcontent

0 commit comments

Comments
 (0)