Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jun 30, 2023
1 parent 3e8cd3d commit 6f9e3c6
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/gallery/example_term_set.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/plot_term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
10 changes: 1 addition & 9 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L21-L28

Added lines #L21 - L28 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L31-L33

Added lines #L31 - L33 were not covered by tests

def _perm_value_key_info(self, perm_values_dict: dict, key: str):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/common/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/common/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='...',
Expand All @@ -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='...',
Expand All @@ -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='...',
Expand All @@ -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='...',
Expand All @@ -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='...',
Expand Down
1 change: 1 addition & 0 deletions tests/unit/example_test_term_set.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 6f9e3c6

Please sign in to comment.