From 74ac932504382922263c4b938cc976460879e130 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Fri, 28 Jul 2023 13:20:47 -0400 Subject: [PATCH] test skips/pyproject --- pyproject.toml | 7 +++-- requirements-opt.txt | 5 +++- src/hdmf/term_set.py | 14 ++++++---- .../expanded_example_dynamic_term_set.yaml | 1 - tests/unit/test_term_set.py | 28 +++++++++---------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 534c10c7f..7a9741ba2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,9 +42,10 @@ dynamic = ["version"] [project.optional-dependencies] zarr = ["zarr>=2.12.0"] tqdm = ["tqdm>=4.41.0"] -linkml = ["linkml-runtime>=1.5.0"] -schemasheets = ["schemasheets>=0.1.23"] -oaklib = ["oaklib>=0.5.12"] +termset_reqs = ["linkml-runtime>=1.5.0", + "schemasheets>=0.1.23", + "oaklib>=0.5.12", + "yaml"] [project.urls] "Homepage" = "https://github.com/hdmf-dev/hdmf" diff --git a/requirements-opt.txt b/requirements-opt.txt index 56e24a6a8..f071e399a 100644 --- a/requirements-opt.txt +++ b/requirements-opt.txt @@ -1,4 +1,7 @@ # pinned dependencies that are optional. used to reproduce an entire development environment to use HDMF tqdm==4.65.0 zarr==2.14.2 -linkml-runtime==1.5.0 +linkml-runtime>=1.5.0 +schemasheets>=0.1.23 +oaklib>=0.5.12 +yaml diff --git a/src/hdmf/term_set.py b/src/hdmf/term_set.py index 614e13fa4..28bb2bb96 100644 --- a/src/hdmf/term_set.py +++ b/src/hdmf/term_set.py @@ -3,11 +3,6 @@ import os from collections import namedtuple from .utils import docval -from linkml_runtime.utils.schemaview import SchemaView -from linkml_runtime.utils.schema_as_dict import schema_as_dict -from schemasheets.schemamaker import SchemaMaker -from oaklib.utilities.subsets.value_set_expander import ValueSetExpander - class TermSet(): @@ -27,6 +22,15 @@ def __init__(self, """ :param term_schema_path: The path to LinkML YAML enumeration schema """ + try: + from linkml_runtime.utils.schemaview import SchemaView + from linkml_runtime.utils.schema_as_dict import schema_as_dict + from schemasheets.schemamaker import SchemaMaker + from oaklib.utilities.subsets.value_set_expander import ValueSetExpander + except ImportError: + msg = "Install TermSet requirements in pyproject.toml" + raise ValueError(msg) + self.term_schema_path = term_schema_path self.schemasheets_folder = schemasheets_folder diff --git a/tests/unit/expanded_example_dynamic_term_set.yaml b/tests/unit/expanded_example_dynamic_term_set.yaml index e89b1c110..dc1674df1 100644 --- a/tests/unit/expanded_example_dynamic_term_set.yaml +++ b/tests/unit/expanded_example_dynamic_term_set.yaml @@ -40,7 +40,6 @@ enums: include_self: false relationship_types: - rdfs:subClassOf - permissible_values: CL:0000705: text: CL:0000705 diff --git a/tests/unit/test_term_set.py b/tests/unit/test_term_set.py index 6e815dc40..a6ed53f4b 100644 --- a/tests/unit/test_term_set.py +++ b/tests/unit/test_term_set.py @@ -7,60 +7,60 @@ CUR_DIR = os.path.dirname(os.path.realpath(__file__)) - try: import linkml_runtime # noqa: F401 - LINKML_INSTALLED = True + import schemasheets + import oaklib + + REQUIREMENTS_INSTALLED = TRUE except ImportError: - LINKML_INSTALLED = False + REQUIREMENTS_INSTALLED = False class TestTermSet(TestCase): - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_termset_setup(self): 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") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_view_set(self): 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") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_termset_validate(self): termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') self.assertEqual(termset.validate('Homo sapiens'), True) - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_termset_validate_false(self): termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') self.assertEqual(termset.validate('missing_term'), False) - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_get_item(self): 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, 'the species is human') 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") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_get_item_key_error(self): termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml') with self.assertRaises(ValueError): termset['Homo Ssapiens'] - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_view_set_sheets(self): folder = os.path.join(CUR_DIR, "test_term_set_input", "schemasheets") termset = TermSet(schemasheets_folder=folder) expected = ['ASTROCYTE', 'INTERNEURON', 'MICROGLIAL_CELL', 'MOTOR_NEURON', 'OLIGODENDROCYTE', 'PYRAMIDAL_NEURON'] self.assertEqual(list(termset.view_set), expected) - @unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed") + @unittest.skipIf(not REQUIREMENTS_INSTALLED, "optional LinkML module is not installed") def test_enum_expander(self): termset = TermSet(term_schema_path='tests/unit/example_dynamic_term_set.yaml', dynamic=True) self.assertEqual(len(termset.view_set), 502) - remove_test_file('./expanded_example_dynamic_term_set.yaml') + remove_test_file('expanded_example_dynamic_term_set.yaml')