From 2d32acf41df9993615132809d2a3fe879a384978 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Thu, 14 Mar 2024 15:59:16 -0700 Subject: [PATCH] cov --- src/hdmf/term_set.py | 2 +- tests/unit/hdmf_config2.yaml | 13 +++++++ tests/unit/test_term_set.py | 57 +++++++++++++++++++++++++++- tests/unit/test_termset_config.py | 63 ------------------------------- 4 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 tests/unit/hdmf_config2.yaml delete mode 100644 tests/unit/test_termset_config.py diff --git a/src/hdmf/term_set.py b/src/hdmf/term_set.py index 04619d8d0..566d10df5 100644 --- a/src/hdmf/term_set.py +++ b/src/hdmf/term_set.py @@ -334,7 +334,7 @@ def load_termset_config(self,config_path): """ try: import yaml - except ImportError: + except ImportError: # pragma: no cover msg = "Install yaml." raise ValueError(msg) diff --git a/tests/unit/hdmf_config2.yaml b/tests/unit/hdmf_config2.yaml new file mode 100644 index 000000000..8970d81ac --- /dev/null +++ b/tests/unit/hdmf_config2.yaml @@ -0,0 +1,13 @@ +namespaces: + hdmf-common: + version: 3.12.2 + data_types: + Data: + description: example_test_term_set.yaml + EnumData: + description: example_test_term_set.yaml + namespace2: + version: 0 + data_types: + MythicData: + description: example_test_term_set.yaml diff --git a/tests/unit/test_term_set.py b/tests/unit/test_term_set.py index b4a469438..ffdd3a2fb 100644 --- a/tests/unit/test_term_set.py +++ b/tests/unit/test_term_set.py @@ -1,8 +1,8 @@ import os -from hdmf.term_set import TermSet, TermSetWrapper +from hdmf.term_set import TermSet, TermSetWrapper, TermSetConfigurator from hdmf.testing import TestCase, remove_test_file -from hdmf.common import VectorData +from hdmf.common import VectorData, unload_termset_config import numpy as np @@ -215,3 +215,56 @@ def test_wrapper_extend_error(self): data_obj = VectorData(name='species', description='...', data=self.wrapped_list) with self.assertRaises(ValueError): data_obj.extend(['bad_data']) + +class TestTermSetConfig(TestCase): + def setUp(self): + if not REQUIREMENTS_INSTALLED: + self.skipTest("optional LinkML module is not installed") + + def tearDown(self): + unload_termset_config() + + def test_config_path(self): + path = 'tests/unit/hdmf_config.yaml' + tc = TermSetConfigurator(path=path) + self.assertEqual(tc.path, [path]) + + def test_get_config(self): + path = 'tests/unit/hdmf_config.yaml' + tc = TermSetConfigurator(path=path) + self.assertEqual(tc.get_config('VectorData', 'hdmf-common'), + {'description': 'example_test_term_set.yaml'}) + + def test_get_config_namespace_error(self): + path = 'tests/unit/hdmf_config.yaml' + tc = TermSetConfigurator(path=path) + with self.assertRaises(ValueError): + tc.get_config('VectorData', 'hdmf-common11') + + def test_get_config_container_error(self): + path = 'tests/unit/hdmf_config.yaml' + tc = TermSetConfigurator(path=path) + with self.assertRaises(ValueError): + tc.get_config('VectorData11', 'hdmf-common') + + def test_already_loaded_path_error(self): + path = 'tests/unit/hdmf_config.yaml' + tc = TermSetConfigurator(path=path) + with self.assertRaises(ValueError): + tc.load_termset_config(config_path=path) + + def test_load_two_unique_configs(self): + path = 'tests/unit/hdmf_config.yaml' + path2 = 'tests/unit/hdmf_config2.yaml' + tc = TermSetConfigurator(path=path) + 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 diff --git a/tests/unit/test_termset_config.py b/tests/unit/test_termset_config.py deleted file mode 100644 index 18dcc6ca1..000000000 --- a/tests/unit/test_termset_config.py +++ /dev/null @@ -1,63 +0,0 @@ -# from hdmf.testing import TestCase -# from hdmf import load_termset_config, unload_termset_config -# from hdmf.term_set import TermSetConfigurator -# -# class TestConfig(TestCase): -# self.test_config = {} -# self.test_merged_extension_config = {} -# self.hdmf_config = {} -# -# def test_construct_config(self): -# # add asserts for self.path and self.config -# test_config = TermSetConfigurator(path='tests/unit/test_config.yaml') -# self.assertEqual(test_config.path, ['tests/unit/test_config.yaml']) -# # self.assertEqual(test_config.config, None) -# -# def test_load_termset_config(self): -# test_config = TermSetConfigurator(path='tests/unit/test_config.yaml') -# test_config.load_termset_config(path='tests/unit/test_extension_config.yaml') -# self.assertEqual(config.path, ['tests/unit/test_config.yaml', 'tests/unit/test_extension_config.yaml']) -# # self.assertEqual(config.config, None) -# -# def test_unload_termset_config(self): -# test_config = TermSetConfigurator(path='tests/unit/test_config.yaml') -# test_config.unload_termset_config() -# self.assertEqual(config.path, ['src/hdmf/hdmf_config.yaml']) -# self.assertEqual(config.config, None) -# -# def test_unload_global_config(self): -# config = get_termset_config() -# unload_termset_config() -# self.assertEqual(config.path, ['src/hdmf/hdmf_config.yaml']) -# self.assertEqual(config.config, None) -# -# def test_load_global_config_reset(self): -# load_termset_config() -# self.assertEqual(config.path, ['src/hdmf/hdmf_config.yaml']) -# # self.assertEqual(config.config, None) -# -# def test_load_global_config_extension_config(self): -# load_termset_config() -# self.assertEqual(config.path, ['tests/unit/test_config.yaml', 'tests/unit/test_extension_config.yaml']) -# # self.assertEqual(config.config, None) -# -# def test_data(self): -# pass -# -# def test_dataset_not_in_spec(self): -# pass -# -# def test_attribute_not_in_spec(self): -# pass -# -# def test_attriute_in_spec(self): -# pass -# -# def test_dataset_in_spec(self): -# pass -# -# def test_data_type_not_in_namespace(self): -# pass -# -# def test_warn_not_wrapped(self): -# pass