|
2 | 2 | import os
|
3 | 3 | import os.path as op
|
4 | 4 |
|
5 |
| -try: |
6 |
| - from json.decoder import JSONDecodeError |
7 |
| -except ImportError: |
8 |
| - JSONDecodeError = ValueError |
| 5 | +from ..utils import JSONDecodeError, create_tree, save_json |
9 | 6 |
|
10 | 7 | from heudiconv.utils import (
|
11 | 8 | get_known_heuristics_with_descriptions,
|
@@ -69,24 +66,21 @@ def test_json_dumps_pretty():
|
69 | 66 | assert pretty({'WipMemBlock': tstr}) == '{\n "WipMemBlock": "%s"\n}' % tstr
|
70 | 67 |
|
71 | 68 |
|
72 |
| -def test_load_json(tmp_path, capsys): |
| 69 | +def test_load_json(tmp_path, caplog): |
73 | 70 | # test invalid json
|
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) |
| 71 | + ifname = 'invalid.json' |
| 72 | + invalid_json_file = str(tmp_path / ifname) |
| 73 | + create_tree(str(tmp_path), {ifname: u"I'm Jason Bourne"}) |
78 | 74 |
|
79 | 75 | with pytest.raises(JSONDecodeError):
|
80 | 76 | load_json(str(invalid_json_file))
|
81 |
| - captured = capsys.readouterr() |
82 |
| - assert ifname in captured.out |
| 77 | + |
| 78 | + assert ifname in caplog.text |
83 | 79 |
|
84 | 80 | # test valid json
|
85 | 81 | vcontent = {"secret": "spy"}
|
86 | 82 | vfname = "valid.json"
|
87 |
| - valid_json_file = tmp_path / vfname |
88 |
| - |
89 |
| - with open(str(valid_json_file), "w") as vj: |
90 |
| - json.dump(vcontent, vj) |
| 83 | + valid_json_file = str(tmp_path / vfname) |
| 84 | + save_json(valid_json_file, vcontent) |
91 | 85 |
|
92 |
| - assert load_json(str(valid_json_file)) == vcontent |
| 86 | + assert load_json(valid_json_file) == vcontent |
0 commit comments