-
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.
Improve error message if adding neurodata types of the wrong types as…
… property values (#638) * Add utility methods for checking if an object / classname represents a neurodata type * Fix bug and improve error for invalid neurodata types in types.util.checkDType * Update isNeurodataTypeClassName.m Fix missing arg * Try running tests with pynwb pre-release (dev) * Add new error id to whitelist * Update run_tests.yml * Update requirements to use dev from pynwb and nwbinspector * Change error id in types.util.checkDType * Fix errorID in linkTest * Add test for new utility function * Fix +matnwb/+utility/isNeurodataTypeClassName.m Make check more robust
- Loading branch information
1 parent
349b175
commit bb9acbf
Showing
7 changed files
with
97 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function tf = isNeurodataType(value) | ||
% isNeurodataType - Check if a value / object is a neurodata type. | ||
% | ||
% tf = matnwb.utility.isNeurodataType(value) returns true if the value | ||
% is an object of a class representing a neurodata type of the NWB Format. | ||
% If the input is a string representing the class name of a neurodata | ||
% type, the function will also return true. | ||
|
||
tf = false; | ||
if isa(value, 'char') || isa(value, 'string') | ||
tf = matnwb.utility.isNeurodataTypeClassName(value); | ||
elseif isa(value, 'types.untyped.MetaClass') | ||
className = class(value); | ||
tf = matnwb.utility.isNeurodataTypeClassName(className); | ||
end | ||
end |
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,58 @@ | ||
function tf = isNeurodataTypeClassName(typeName) | ||
% isNeurodataTypeClassName - Check if a name is the class name of a neurodata type. | ||
% | ||
% tf = matnwb.utility.isNeurodataTypeClassName(value) returns true if a | ||
% string is the class name of a class representing a neurodata type of | ||
% the NWB Format | ||
|
||
arguments | ||
typeName (1,1) string | ||
end | ||
|
||
tf = false; | ||
if startsWith(typeName, 'types.') && ~startsWith(typeName, 'types.untyped') | ||
mc = meta.class.fromName(typeName); | ||
if ~isempty(mc) | ||
tf = hasSuperClass(mc, 'types.untyped.MetaClass'); | ||
end | ||
end | ||
end | ||
|
||
function tf = hasSuperClass(mc, superClassName) | ||
% hasSuperClass - Recursively check if a meta.class object has a specific superclass. | ||
% | ||
% tf = hasSuperClass(mc, superClassName) returns true if the meta.class object | ||
% mc has a superclass with the name superClassName, either directly or | ||
% indirectly (through its own superclasses). | ||
% | ||
% Arguments: | ||
% mc - A meta.class object. | ||
% superClassName - The name of the superclass to check for (string). | ||
% | ||
% Returns: | ||
% tf - Logical value indicating if the class has the specified superclass. | ||
|
||
arguments | ||
mc meta.class | ||
superClassName (1,1) string | ||
end | ||
|
||
% Check if the current class has the desired superclass directly. | ||
for i = 1:numel(mc.SuperclassList) | ||
if mc.SuperclassList(i).Name == superClassName | ||
tf = true; | ||
return; | ||
end | ||
end | ||
|
||
% If not, check recursively through each superclass. | ||
for i = 1:numel(mc.SuperclassList) | ||
if hasSuperClass(mc.SuperclassList(i), superClassName) | ||
tf = true; | ||
return; | ||
end | ||
end | ||
|
||
% If no match found, return false. | ||
tf = false; | ||
end |
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
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,3 +1,3 @@ | ||
hdf5plugin | ||
git+https://github.com/NeurodataWithoutBorders/nwbinspector.git@dev | ||
git+https://github.com/NeurodataWithoutBorders/pynwb.git@dev | ||
git+https://github.com/NeurodataWithoutBorders/pynwb.git@dev |
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