-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] give more meaningful error messsages when failing to read json (#…
…582) * add warning mentioning which json files could not be read * add file not found erro
- Loading branch information
Showing
3 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
miss_hit==0.9.35 | ||
miss_hit | ||
pre-commit | ||
jupyterlab | ||
octave_kernel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function test_suite = test_json_decode %#ok<*STOUT> | ||
try % assignment of 'localfunctions' is necessary in Matlab >= 2016 | ||
test_functions = localfunctions(); %#ok<*NASGU> | ||
catch % no problem; early Matlab versions can use initTestSuite fine | ||
end | ||
initTestSuite; | ||
end | ||
|
||
function test_json_decode_file_not_found() | ||
|
||
% write dummy faulty json | ||
|
||
filename = fullfile(temp_dir, 'foo.json'); | ||
assertExceptionThrown(@() bids.util.jsondecode(filename), ... | ||
'jsondecode:FileNotFound'); | ||
|
||
end | ||
|
||
function test_json_decode_parse_error() | ||
|
||
% write dummy faulty json | ||
|
||
filename = fullfile(temp_dir, 'wrong.json'); | ||
fid = fopen(filename, 'Wt'); | ||
fprintf(fid, '{"foo": "bla"'); | ||
fclose(fid); | ||
|
||
assertWarning(@() bids.util.jsondecode(filename), ... | ||
'jsondecode:CannotReadJson'); | ||
|
||
end |