Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Mar 14, 2024
1 parent b806404 commit 901cb56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 6 additions & 8 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import warnings
import numpy as np
from .data_utils import append_data, extend_data
import yaml


class TermSet:
Expand Down Expand Up @@ -163,6 +162,7 @@ def __schemasheets_convert(self):
This method returns a path to the new schema to be viewed via SchemaView.
"""
try:
import yaml
from linkml_runtime.utils.schema_as_dict import schema_as_dict
from schemasheets.schemamaker import SchemaMaker
except ImportError: # pragma: no cover
Expand Down Expand Up @@ -262,13 +262,6 @@ def __getitem__(self, val):
"""
return self.__value[val]

# uncomment when DataChunkIterator objects can be wrapped by TermSet
# def __next__(self):
# """
# Return the next item of a wrapped iterator.
# """
# return self.__value.__next__()
#
def __len__(self):
return len(self.__value)

Expand Down Expand Up @@ -313,6 +306,11 @@ class TermSetConfigurator:
"""
@docval({'name': 'path', 'type': str, 'doc': 'Path to the configuration file.', 'default': None})
def __init__(self, **kwargs):
try:
import yaml
except ImportError:
msg = "Install yaml"
raise ValueError(msg)
self.config = None
if kwargs['path'] is None:
self.path = []
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/common/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@

try:
import linkml_runtime # noqa: F401
LINKML_INSTALLED = True
import yaml
REQUIREMENTS_INSTALLED = True
except ImportError:
LINKML_INSTALLED = False
REQUIREMENTS_INSTALLED = False


class TestDynamicTable(TestCase):
Expand Down Expand Up @@ -135,7 +136,7 @@ def test_constructor_all_columns_are_iterators(self):
# now test that when we supply id's that the error goes away
_ = DynamicTable(name="TestTable", description="", columns=[column], id=list(range(3)))

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
@unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed")
def test_add_col_validate(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
col1 = VectorData(
Expand All @@ -154,7 +155,7 @@ def test_add_col_validate(self):
expected_df.index.name = 'id'
pd.testing.assert_frame_equal(species.to_dataframe(), expected_df)

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
@unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed")
def test_add_col_validate_bad_data(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
col1 = VectorData(
Expand All @@ -169,7 +170,7 @@ def test_add_col_validate_bad_data(self):
data=TermSetWrapper(value=['bad data'],
termset=terms))

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
@unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed")
def test_add_row_validate(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
col1 = VectorData(
Expand All @@ -191,7 +192,7 @@ def test_add_row_validate(self):
expected_df.index.name = 'id'
pd.testing.assert_frame_equal(species.to_dataframe(), expected_df)

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
@unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed")
def test_add_row_validate_bad_data_one_col(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
col1 = VectorData(
Expand All @@ -208,7 +209,7 @@ def test_add_row_validate_bad_data_one_col(self):
with self.assertRaises(ValueError):
species.add_row(Species_1='bad', Species_2='Ursus arctos horribilis')

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
@unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed")
def test_add_row_validate_bad_data_all_col(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
col1 = VectorData(
Expand Down Expand Up @@ -2786,7 +2787,7 @@ def __init__(self, **kwargs):

class TestTermSetConfig(TestCase):
def setUp(self):
if not LINKML_INSTALLED:
if not REQUIREMENTS_INSTALLED:
self.skipTest("optional LinkML module is not installed")

unload_termset_config()
Expand Down

0 comments on commit 901cb56

Please sign in to comment.