Skip to content

Commit b117d12

Browse files
committed
Fix failing tests
1 parent 7d838c8 commit b117d12

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

+tests/+unit/+schema/DataTypesTest.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function testSubgroupUntypedDatasetWithWrongType(testCase)
363363
subGroup.set('untyped_text_data', 2);
364364
testCase.verifyWarning(...
365365
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
366-
'NWB:Set:FailedValidation')
366+
'NWB:Set:InvalidEntry')
367367
end
368368

369369
function testSubgroupTypedDatasetWithCorrectType(testCase)
@@ -379,7 +379,7 @@ function testSubgroupTypedDatasetWithWrongType(testCase)
379379
subGroup.set('any_data', types.hdmf_common.VectorData('data', 1));
380380
testCase.verifyWarning(...
381381
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
382-
'NWB:Set:FailedValidation')
382+
'NWB:Set:InvalidEntry')
383383
end
384384

385385
function testSubgroupConstrainedDatasetWithCorrectType(testCase)
@@ -397,7 +397,7 @@ function testSubgroupConstrainedDatasetWithWrongType(testCase)
397397
subGroup.set('constrained', types.dt.AnyData('data', 1));
398398
testCase.verifyWarning(...
399399
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
400-
'NWB:Set:FailedValidation')
400+
'NWB:Set:InvalidEntry')
401401
end
402402

403403
function testSubgroupAttributeWithCorrectType(testCase)
@@ -413,7 +413,7 @@ function testSubgroupAttributeWithWrongType(testCase)
413413
subGroup.set('description', 1);
414414
testCase.verifyWarning(...
415415
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
416-
'NWB:Set:FailedValidation')
416+
'NWB:Set:InvalidEntry')
417417
end
418418

419419
function testSubgroupLinkWithCorrectType(testCase)
@@ -431,7 +431,7 @@ function testSubgroupLinkWithWrongType(testCase)
431431
subGroup.set('subgroup_link', types.untyped.SoftLink(invalidLinkedDataset));
432432
testCase.verifyWarning(...
433433
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
434-
'NWB:Set:FailedValidation')
434+
'NWB:Set:InvalidEntry')
435435
end
436436

437437
function testNestedSubgroupWithCorrectType(testCase)
@@ -446,7 +446,7 @@ function testNestedSubgroupWithWrongType(testCase)
446446
subGroup.set('nested_subgroup', types.core.TimeSeries);
447447
testCase.verifyWarning(...
448448
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
449-
'NWB:Set:FailedValidation')
449+
'NWB:Set:InvalidEntry')
450450
end
451451

452452
function testNestedConstrainedSubgroupWithCorrectType(testCase)
@@ -461,7 +461,7 @@ function testNestedConstrainedSubgroupWithWrongType(testCase)
461461
subGroup.set('nested_constrained_subgroup', types.hdmf_common.DynamicTable());
462462
testCase.verifyWarning(...
463463
@() types.dt.NestedDataTypeContainer('subgroup', subGroup), ...
464-
'NWB:Set:FailedValidation')
464+
'NWB:Set:InvalidEntry')
465465
end
466466
end
467467
end

+tests/+unit/untypedSetTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function testCreateSetWithFunctionInput(testCase)
1414
% Verify a function that validates the input
1515
set = types.untyped.Set(@(key, value) assert(strcmp(key, 'test')));
1616
try
17-
set.validateEntry('test', 1)
17+
set.validateEntry('test', 1);
1818
catch
1919
testCase.verifyFail('Expected validation to pass')
2020
end

+types/+untyped/Set.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,23 @@
5252

5353
function value = validateEntry(obj, name, value)
5454
if ~isempty(obj.ValidationFunction)
55+
MECause = [];
5556
try
5657
value = obj.ValidationFunction(name, value);
5758
catch MECause
58-
ME = MException('NWB:Set:InvalidEntry', ...
59+
if strcmp(MECause.identifier, 'MATLAB:maxlhs')
60+
MECause = []; % Reset MECause
61+
% Validation function does not provide output. Call
62+
% again expecting no output
63+
try
64+
obj.ValidationFunction(name, value);
65+
catch MECause
66+
% pass, handled below
67+
end
68+
end
69+
end
70+
if ~isempty(MECause)
71+
ME = MException('NWB:Set:InvalidEntry', ...
5972
'Entry of Constrained Set with name `%s` is invalid.\n', name);
6073
ME = ME.addCause(MECause);
6174
throw(ME)

0 commit comments

Comments
 (0)