Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Mar 14, 2024
1 parent 809d511 commit 6b99a8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def _field_config(self, arg_name, val):
return val

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/container.py#L141-L143

Added lines #L141 - L143 were not covered by tests
# From the spec, get the corresponding constructor name
else:
constr_name = obj_mapper.get_const_arg(spec)
termset_path = os.path.join(CUR_DIR, config_namespace['data_types'][object_name][attr])
termset = TermSet(term_schema_path=termset_path)
# If the val has been manually wrapped then skip checking the config for the attr
Expand Down
11 changes: 8 additions & 3 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ def load_termset_config(self,config_path):
"""
Load the configuration file for validation on the fields defined for the objects within the file.
"""
try:
import yaml
except ImportError:
msg = "Install yaml."
raise ValueError(msg)

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L337-L339

Added lines #L337 - L339 were not covered by tests

with open(config_path, 'r') as config:
termset_config = yaml.load(config, Loader=yaml.FullLoader)
if self.config is None: # set the initial config/load after config has been unloaded
Expand All @@ -347,14 +353,13 @@ def load_termset_config(self,config_path):
if namespace not in self.config: # append namespace config if not present within self.config
self.config['namespaces'][namespace] = termset_config['namespaces'][namespace]

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L354

Added line #L354 was not covered by tests
else: # check for any needed overrides within existing namespace configs
breakpoint()
for data_type in termset_config['namespaces'][namespace]['data_types']:
if data_type in self.config['namespaces'][namespace]['data_types']:
replace_config = termset_config['namespaces'][namespace]['data_types'][data_type]
self.config['namespaces'][namespace]['data_types'][data_type] = replace_config

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L358-L359

Added lines #L358 - L359 were not covered by tests
else: # append to config
new_data_type_config = termset_config['namespaces'][namespace]['data_types'][data_type]
self.config['namespaces'][namespace]['data_types'] = new_data_type_config
new_config = termset_config['namespaces'][namespace]['data_types'][data_type]
self.config['namespaces'][namespace]['data_types'] = new_config

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L361-L362

Added lines #L361 - L362 were not covered by tests

# append path to self.path
self.path.append(config_path)

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L365

Added line #L365 was not covered by tests
Expand Down
24 changes: 15 additions & 9 deletions tests/unit/common/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
import unittest

from hdmf import Container, Data
from hdmf import Container
from hdmf import TermSet, TermSetWrapper
from hdmf.backends.hdf5 import H5DataIO, HDF5IO
from hdmf.backends.hdf5.h5tools import H5_TEXT, H5PY_3
Expand All @@ -20,11 +20,9 @@
SimpleMultiContainer,
load_termset_config,
unload_termset_config,
get_loaded_config,
get_type_map
)
get_loaded_config)
from hdmf.testing import TestCase, H5RoundTripMixin, remove_test_file
from hdmf.utils import StrDataset, popargs, docval
from hdmf.utils import StrDataset, popargs
from hdmf.data_utils import DataChunkIterator

from tests.unit.helpers.utils import (
Expand All @@ -36,7 +34,6 @@

try:
import linkml_runtime # noqa: F401
import yaml
REQUIREMENTS_INSTALLED = True
except ImportError:
REQUIREMENTS_INSTALLED = False
Expand Down Expand Up @@ -2804,18 +2801,27 @@ def test_load_config(self):

def test_validate_with_config(self):
data = VectorData(name='foo', data=[0], description='Homo sapiens')
self.assertEqual(data.description.value, 'Homo sapiens')

def test_namespace_warn(self):
with self.assertWarns(Warning):
container = ExtensionContainer(name='foo', namespace='foo', type_map=self.tm, description='Homo sapiens')
ExtensionContainer(name='foo',
namespace='foo',
type_map=self.tm,
description='Homo sapiens')

def test_container_type_warn(self):
with self.assertWarns(Warning):
container = ExtensionContainer(name='foo', namespace='hdmf-common', type_map=self.tm, description='Homo sapiens')
ExtensionContainer(name='foo',
namespace='hdmf-common',
type_map=self.tm,
description='Homo sapiens')

def test_already_wrapped_warn(self):
with self.assertWarns(Warning):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
data = VectorData(name='foo', data=[0], description=TermSetWrapper(value='Homo sapiens', termset=terms))
VectorData(name='foo',
data=[0],
description=TermSetWrapper(value='Homo sapiens', termset=terms))

unload_termset_config()

0 comments on commit 6b99a8a

Please sign in to comment.