Skip to content

Commit

Permalink
final clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Mar 15, 2024
1 parent d66145d commit eb3970b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/hdmf/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def load_termset_config(**kwargs):
return __TYPE_MAP

Check warning on line 34 in src/hdmf/common/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/common/__init__.py#L34

Added line #L34 was not covered by tests

def get_loaded_config():
"""
This method returns the entire config file.
"""
if __TYPE_MAP.ts_config.config is None:
msg = "No configuration is loaded."
raise ValueError(msg)

Check warning on line 42 in src/hdmf/common/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/common/__init__.py#L41-L42

Added lines #L41 - L42 were not covered by tests
Expand All @@ -42,7 +45,7 @@ def get_loaded_config():

def unload_termset_config():
"""
Remove validation.
Unload the configuration file.
"""
return __TYPE_MAP.ts_config.unload_termset_config()

Check warning on line 50 in src/hdmf/common/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/common/__init__.py#L50

Added line #L50 was not covered by tests

Expand Down
16 changes: 9 additions & 7 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,23 @@ def _field_config(self, arg_name, val):
This method will be called in the setter. The termset configuration will be used (if loaded)
to check for a defined TermSet associated with the field. If found, the value of the field
will be wrapped with a TermSetWrapper.
Even though the path field in the configurator can be a list of paths, the config
itself is only one file. When a user loads custom configs, the config is appended/modified.
The modificiations are not written to file, avoiding permanent modifications.
"""
# load termset configuration file from global Config
try:
"""
Even though the path field in the configurator can be a list of paths, the config
itself is only one file. When a user loads custom configs, the config is appended/modified.
The modificiations are not written to file, avoiding permanent modifications.
"""
configurator = self.type_map.ts_config
if len(configurator.path)>0:
# The type_map has a config always set; however, when toggled off, the config path path is empty.
CUR_DIR = os.path.dirname(os.path.realpath(configurator.path[0]))
termset_config = configurator.config

Check warning on line 110 in src/hdmf/container.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/container.py#L109-L110

Added lines #L109 - L110 were not covered by tests
else:
return val
except AttributeError: # This is for containers that are not registered, e.g., testing classes.
except AttributeError:
# These are for classes that have not been registered, e.g., some test containers.
# Without register_class, the type_map parameter is not defined.
return val

# check to see that the namespace for the container is in the config
Expand All @@ -130,9 +132,9 @@ def _field_config(self, arg_name, val):
else:
for attr in config_namespace['data_types'][object_name]:
obj_mapper = self.type_map.get_map(self)

Check warning on line 134 in src/hdmf/container.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/container.py#L134

Added line #L134 was not covered by tests

# get the spec according to attr name in schema
# Note: this is the name for the field in the config

spec = obj_mapper.get_attr_spec(attr)

Check warning on line 138 in src/hdmf/container.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/container.py#L138

Added line #L138 was not covered by tests

# In the case of dealing with datasets directly or not defined in the spec.
Expand Down
13 changes: 10 additions & 3 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,25 @@ def __init__(self, **kwargs):
self.path = [kwargs['path']]
self.load_termset_config(config_path=self.path[0])

Check warning on line 314 in src/hdmf/term_set.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L313-L314

Added lines #L313 - L314 were not covered by tests

def get_config(self, object_name, namespace):
@docval({'name': 'data_type', 'type': str,
'doc': 'The desired data type within the configuration file.'},
{'name': 'namespace', 'type': str,
'doc': 'The namespace for the data type. '})
def get_config(self, data_type, namespace):
"""
Return the config for that data type in the given namespace.
"""
try:
namespace_config = self.config['namespaces'][namespace]
except KeyError:
msg = 'The namespace %s was not found within the configuration.' % namespace
raise ValueError(msg)

Check warning on line 328 in src/hdmf/term_set.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L324-L328

Added lines #L324 - L328 were not covered by tests

try:
type_config = namespace_config['data_types'][object_name]
type_config = namespace_config['data_types'][data_type]
return type_config
except KeyError:
msg = '%s was not found within the configuration for that namespace.' % object_name
msg = '%s was not found within the configuration for that namespace.' % data_type
raise ValueError(msg)

Check warning on line 335 in src/hdmf/term_set.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L330-L335

Added lines #L330 - L335 were not covered by tests

@docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuration file.'})
Expand Down

0 comments on commit eb3970b

Please sign in to comment.