From 6f9e3c64013af32e7a7e8c5da677a848e1249ca9 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Fri, 30 Jun 2023 08:55:57 -0700 Subject: [PATCH] feedback --- docs/gallery/example_term_set.yaml | 1 + docs/gallery/plot_term_set.py | 2 +- src/hdmf/term_set.py | 10 +--------- tests/unit/common/test_resources.py | 6 +++--- tests/unit/common/test_table.py | 10 +++++----- tests/unit/example_test_term_set.yaml | 1 + tests/unit/test_container.py | 16 ++++++++-------- tests/unit/test_term_set.py | 8 ++++---- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/docs/gallery/example_term_set.yaml b/docs/gallery/example_term_set.yaml index db39488e7..c47979e55 100644 --- a/docs/gallery/example_term_set.yaml +++ b/docs/gallery/example_term_set.yaml @@ -1,5 +1,6 @@ id: pynert/termset/species_example name: Species +version: 0.0.1 prefixes: NCBI_TAXON: https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id= imports: diff --git a/docs/gallery/plot_term_set.py b/docs/gallery/plot_term_set.py index b09d1f5cd..61a1ce68e 100644 --- a/docs/gallery/plot_term_set.py +++ b/docs/gallery/plot_term_set.py @@ -67,7 +67,7 @@ # Users can index specific terms from the :py:class:`~hdmf.TermSet`. if LINKML_INSTALLED: terms = TermSet(name='Species', term_schema_path='docs/gallery/example_term_set.yaml') - terms.view_set + print(terms.view_set) # Retrieve a specific term terms['Homo sapiens'] diff --git a/src/hdmf/term_set.py b/src/hdmf/term_set.py index 6285fd7c3..4ab0b9e17 100644 --- a/src/hdmf/term_set.py +++ b/src/hdmf/term_set.py @@ -12,32 +12,24 @@ class TermSet(): :ivar ontology_source_uri: The uri of the ontology """ def __init__(self, - name: str, term_schema_path: str, - # ontology_version: str, ): """ - :param name: The name of the TermSet :param term_schema_path: The path to LinkML YAML enumeration schema - :param ontology_version: The version of the ontology - :param ontology_source_name: The name of the ontology - :param ontology_source_uri: The uri of the ontology + """ try: from linkml_runtime.utils.schemaview import SchemaView except ImportError: msg = "Install linkml_runtime" raise ValueError(msg) - self.name = name self.term_schema_path = term_schema_path self.view = SchemaView(self.term_schema_path) self.sources = self.view.schema.prefixes def __repr__(self): re = "class: %s\n" % str(self.__class__) - re += "name: %s\n" % self.name re += "term_schema_path: %s\n" % self.term_schema_path - re += "ontology_source_name: %s\n" % self.sources return re def _perm_value_key_info(self, perm_values_dict: dict, key: str): diff --git a/tests/unit/common/test_resources.py b/tests/unit/common/test_resources.py index a2a37116a..0a421844a 100644 --- a/tests/unit/common/test_resources.py +++ b/tests/unit/common/test_resources.py @@ -271,7 +271,7 @@ def test_add_ref_search_for_file_error(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_ref_termset(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') er = ExternalResources() em = ExternalResourcesManagerContainer() em.link_resources(er) @@ -324,7 +324,7 @@ def test_add_ref_termset_missing_attribute_termset_value(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_ref_termset_missing_terms(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') er = ExternalResources() em = ExternalResourcesManagerContainer() em.link_resources(er) @@ -348,7 +348,7 @@ def test_add_ref_termset_missing_terms(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_ref_termset_missing_file_error(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') er = ExternalResources() col1 = VectorData(name='Species_Data', diff --git a/tests/unit/common/test_table.py b/tests/unit/common/test_table.py index 6957756d6..af6b6357e 100644 --- a/tests/unit/common/test_table.py +++ b/tests/unit/common/test_table.py @@ -105,7 +105,7 @@ def test_constructor_ids_bad_ids(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_col_validate(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') col1 = VectorData( name='Species_1', description='...', @@ -126,7 +126,7 @@ def test_add_col_validate(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_col_validate_bad_data(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') col1 = VectorData( name='Species_1', description='...', @@ -142,7 +142,7 @@ def test_add_col_validate_bad_data(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_row_validate(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') col1 = VectorData( name='Species_1', description='...', @@ -166,7 +166,7 @@ def test_add_row_validate(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_row_validate_bad_data_one_col(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') col1 = VectorData( name='Species_1', description='...', @@ -185,7 +185,7 @@ def test_add_row_validate_bad_data_one_col(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_add_row_validate_bad_data_all_col(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') col1 = VectorData( name='Species_1', description='...', diff --git a/tests/unit/example_test_term_set.yaml b/tests/unit/example_test_term_set.yaml index db39488e7..c47979e55 100644 --- a/tests/unit/example_test_term_set.yaml +++ b/tests/unit/example_test_term_set.yaml @@ -1,5 +1,6 @@ id: pynert/termset/species_example name: Species +version: 0.0.1 prefixes: NCBI_TAXON: https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id= imports: diff --git a/tests/unit/test_container.py b/tests/unit/test_container.py index bb345f790..dde950fad 100644 --- a/tests/unit/test_container.py +++ b/tests/unit/test_container.py @@ -307,54 +307,54 @@ def test_shape_list(self): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_validate_data(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens']) bool = data_obj.validate_data(term='Homo sapiens', term_set=terms) self.assertEqual(bool, True) # @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_validate_data_error(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens']) bool = data_obj.validate_data(term='term', term_set=terms) self.assertEqual(bool, False) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_validate(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens'], term_set=terms) self.assertEqual(data_obj.data, ['Homo sapiens']) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_validate_value_error(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') with self.assertRaises(ValueError): Data(name='species', data=['Macaca mulatta'], term_set=terms) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_append_validate(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens'], term_set=terms) data_obj.append('Mus musculus') self.assertEqual(data_obj.data, ['Homo sapiens', 'Mus musculus']) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_append_validate_error(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens'], term_set=terms) with self.assertRaises(ValueError): data_obj.append('Macaca mulatta') @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_extend_validate(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens'], term_set=terms) data_obj.extend(['Mus musculus', 'Ursus arctos horribilis']) self.assertEqual(data_obj.data, ['Homo sapiens', 'Mus musculus', 'Ursus arctos horribilis']) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_extend_validate_bad_data_error(self): - terms = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') data_obj = Data(name='species', data=['Homo sapiens'], term_set=terms) with self.assertRaises(ValueError): data_obj.extend(['Mus musculus', 'Oryctolagus cuniculus']) diff --git a/tests/unit/test_term_set.py b/tests/unit/test_term_set.py index 18fbc76f0..a44aeafd7 100644 --- a/tests/unit/test_term_set.py +++ b/tests/unit/test_term_set.py @@ -13,24 +13,24 @@ class TestTermSet(TestCase): @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_termset_setup(self): - termset = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') self.assertEqual(list(termset.sources), ['NCBI_TAXON']) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_view_set(self): - termset = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') expected = ['Homo sapiens', 'Mus musculus', 'Ursus arctos horribilis', 'Myrmecophaga tridactyla'] self.assertEqual(list(termset.view_set), expected) @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_get_item(self): - termset = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') self.assertEqual(termset['Homo sapiens'].id, 'NCBI_TAXON:9606') self.assertEqual(termset['Homo sapiens'].description, 'description') self.assertEqual(termset['Homo sapiens'].meaning, 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=9606') @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") def test_get_item_key_error(self): - termset = TermSet(name='species', term_schema_path='tests/unit/example_test_term_set.yaml') + termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') with self.assertRaises(ValueError): termset['Homo Ssapiens']