|
1 | 1 | import json
|
2 | 2 | import os
|
3 | 3 | import os.path as op
|
| 4 | + |
| 5 | +try: |
| 6 | + from json.decoder import JSONDecodeError |
| 7 | +except ImportError: |
| 8 | + JSONDecodeError = ValueError |
| 9 | + |
4 | 10 | from heudiconv.utils import (
|
5 | 11 | get_known_heuristics_with_descriptions,
|
6 | 12 | get_heuristic_description,
|
@@ -65,12 +71,22 @@ def test_json_dumps_pretty():
|
65 | 71 |
|
66 | 72 | def test_load_json(tmp_path, capsys):
|
67 | 73 | # 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) |
72 | 78 |
|
73 |
| - with pytest.raises(json.JSONDecodeError): |
74 |
| - load_json(json_file) |
| 79 | + with pytest.raises(JSONDecodeError): |
| 80 | + load_json(invalid_json_file) |
75 | 81 | 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