Skip to content

Commit

Permalink
test skips/pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jul 28, 2023
1 parent ede2e7a commit 74ac932
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion requirements-opt.txt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 9 additions & 5 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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

Check failure on line 27 in src/hdmf/term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/hdmf/term_set.py:27:61: F401 `linkml_runtime.utils.schema_as_dict.schema_as_dict` imported but unused; consider using `importlib.util.find_spec` to test for availability
from schemasheets.schemamaker import SchemaMaker

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

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/hdmf/term_set.py:28:50: F401 `schemasheets.schemamaker.SchemaMaker` imported but unused; consider using `importlib.util.find_spec` to test for availability
from oaklib.utilities.subsets.value_set_expander import ValueSetExpander

Check failure on line 29 in src/hdmf/term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/hdmf/term_set.py:29:69: F401 `oaklib.utilities.subsets.value_set_expander.ValueSetExpander` imported but unused; consider using `importlib.util.find_spec` to test for availability
except ImportError:
msg = "Install TermSet requirements in pyproject.toml"
raise ValueError(msg)

self.term_schema_path = term_schema_path
self.schemasheets_folder = schemasheets_folder

Expand Down
1 change: 0 additions & 1 deletion tests/unit/expanded_example_dynamic_term_set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ enums:
include_self: false
relationship_types:
- rdfs:subClassOf

permissible_values:
CL:0000705:
text: CL:0000705
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test_term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,60 @@

CUR_DIR = os.path.dirname(os.path.realpath(__file__))


try:
import linkml_runtime # noqa: F401
LINKML_INSTALLED = True
import schemasheets

Check failure on line 12 in tests/unit/test_term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tests/unit/test_term_set.py:12:12: F401 `schemasheets` imported but unused; consider using `importlib.util.find_spec` to test for availability
import oaklib

Check failure on line 13 in tests/unit/test_term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tests/unit/test_term_set.py:13:12: F401 `oaklib` imported but unused; consider using `importlib.util.find_spec` to test for availability

REQUIREMENTS_INSTALLED = TRUE

Check failure on line 15 in tests/unit/test_term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

tests/unit/test_term_set.py:15:30: F821 Undefined name `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']

Check failure on line 59 in tests/unit/test_term_set.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

tests/unit/test_term_set.py:59:121: E501 Line too long (121 > 120 characters)
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')

0 comments on commit 74ac932

Please sign in to comment.