Skip to content

Commit

Permalink
tests/clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Mar 15, 2024
1 parent 4fd0116 commit 39ea8c2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 71 deletions.
63 changes: 2 additions & 61 deletions tests/unit/common/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
EnumData,
DynamicTableRegion,
get_manager,
SimpleMultiContainer,
load_termset_config,
unload_termset_config,
get_loaded_config)
SimpleMultiContainer)
from hdmf.testing import TestCase, H5RoundTripMixin, remove_test_file
from hdmf.utils import StrDataset, popargs
from hdmf.utils import StrDataset
from hdmf.data_utils import DataChunkIterator

from tests.unit.helpers.utils import (
Expand Down Expand Up @@ -2837,59 +2834,3 @@ def test_columns(self):
{'name': 'col3', 'description': '...'}, {'name': 'col4', 'description': '...'})
)
self.assertEqual(self.foo2.__columns__, self.foo3.__columns__)


class ExtensionContainer(Container):
__fields__ = ("description",)

def __init__(self, **kwargs):
description, namespace, type_map = popargs('description', 'namespace', 'type_map', kwargs)
super().__init__(**kwargs)
self.namespace = namespace
self.type_map = type_map
self.description = description


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

unload_termset_config()
self.tm = load_termset_config(config_path='tests/unit/hdmf_config.yaml', return_map=True)

def tearDown(self):
unload_termset_config()

def test_load_config(self):
config = get_loaded_config()
self.assertEqual(config,
{'namespaces': {'hdmf-common': {'version': '3.12.2',
'data_types': {'VectorData': {'description': 'example_test_term_set.yaml'}}}}})

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):
ExtensionContainer(name='foo',
namespace='foo',
type_map=self.tm,
description='Homo sapiens')

def test_container_type_warn(self):
with self.assertWarns(Warning):
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')
VectorData(name='foo',
data=[0],
description=TermSetWrapper(value='Homo sapiens', termset=terms))

unload_termset_config()
83 changes: 73 additions & 10 deletions tests/unit/test_term_set.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import numpy as np

from hdmf import Container
from hdmf.term_set import TermSet, TermSetWrapper, TermSetConfigurator
from hdmf.testing import TestCase, remove_test_file
from hdmf.common import VectorData, unload_termset_config
import numpy as np
from hdmf.common import VectorData, unload_termset_config, get_loaded_config, load_termset_config
from hdmf.utils import popargs


CUR_DIR = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -224,6 +226,20 @@ def setUp(self):
def tearDown(self):
unload_termset_config()

def test_get_loaded_config(self):
load_termset_config(config_path='tests/unit/hdmf_config.yaml', return_map=True)
loaded_config = get_loaded_config()
config = {'namespaces':
{'hdmf-common':
{'version': '3.12.2',
'data_types': {'VectorData': {'description': 'example_test_term_set.yaml'}}}}}

self.assertEqual(loaded_config, config)

def test_get_loaded_config_error(self):
with self.assertRaises(ValueError):
get_loaded_config()

def test_config_path(self):
path = 'tests/unit/hdmf_config.yaml'
tc = TermSetConfigurator(path=path)
Expand Down Expand Up @@ -260,11 +276,58 @@ def test_load_two_unique_configs(self):
tc.load_termset_config(config_path=path2)
self.assertEqual(tc.path, [path, path2])

# def test_append_namespace(self):
# pass
#
# def test_replace_config(self):
# pass
#
# def test_append_config(self):
# pass

class ExtensionContainer(Container):
__fields__ = ("description",)

def __init__(self, **kwargs):
description, namespace, type_map = popargs('description', 'namespace', 'type_map', kwargs)
super().__init__(**kwargs)
self.namespace = namespace
self.type_map = type_map
self.description = description


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

unload_termset_config()
self.tm = load_termset_config(config_path='tests/unit/hdmf_config.yaml', return_map=True)

def tearDown(self):
unload_termset_config()

def test_load_config(self):
config = get_loaded_config()
self.assertEqual(config,
{'namespaces': {'hdmf-common': {'version': '3.12.2',
'data_types': {'VectorData': {'description': 'example_test_term_set.yaml'}}}}})

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):
ExtensionContainer(name='foo',
namespace='foo',
type_map=self.tm,
description='Homo sapiens')

def test_container_type_warn(self):
with self.assertWarns(Warning):
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')
VectorData(name='foo',
data=[0],
description=TermSetWrapper(value='Homo sapiens', termset=terms))

unload_termset_config()

0 comments on commit 39ea8c2

Please sign in to comment.