Skip to content

Commit

Permalink
Allow BioPortal tests to run in GitHub Actions (#256)
Browse files Browse the repository at this point in the history
* Allow passing API key to OntoPortalImplementationBase; check environment for key in test

* Add BIOPORTAL_API_KEY variable to test environment
  • Loading branch information
pkalita-lbl authored Sep 3, 2022
1 parent 9fd6e97 commit af7634b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
#----------------------------------------------
- name: Run tests
run: poetry run python -m unittest discover
env:
BIOPORTAL_API_KEY: ${{ secrets.BIOPORTAL_API_KEY }}

#----------------------------------------------
# coverage report
Expand All @@ -93,6 +95,8 @@ jobs:
poetry run coverage run -m unittest discover
poetry run coverage xml
poetry run coverage report -m
env:
BIOPORTAL_API_KEY: ${{ secrets.BIOPORTAL_API_KEY }}

#----------------------------------------------
# upload coverage results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class OntoPortalImplementationBase(
):

ontoportal_client_class: ClassVar[type[PreconfiguredOntoPortalClient]] = None
api_key: Union[str, None] = None

label_cache: Dict[CURIE, str] = field(default_factory=lambda: {})
ontology_cache: Dict[URI, str] = field(default_factory=lambda: {})
Expand All @@ -52,8 +53,9 @@ def __post_init__(self):
self.focus_ontology = self.resource.slug
if not self.ontoportal_client_class:
raise NotImplementedError("ontoportal_client_class not specified")
api_key = get_apikey_value(self.ontoportal_client_class.name)
self.client = self.ontoportal_client_class(api_key=api_key)
if not self.api_key:
self.api_key = get_apikey_value(self.ontoportal_client_class.name)
self.client = self.ontoportal_client_class(api_key=self.api_key)

def prefix_map(self) -> PREFIX_MAP:
context = load_multi_context(["obo", "bioportal"])
Expand Down
10 changes: 8 additions & 2 deletions tests/test_implementations/test_bioportal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import logging
import os
import unittest

from linkml_runtime.dumpers import yaml_dumper
Expand All @@ -18,11 +19,16 @@ class TestBioportal(unittest.TestCase):

def setUp(self) -> None:
cls = BioportalImplementation
api_key = None
try:
get_apikey_value(cls.ontoportal_client_class.name)
api_key = get_apikey_value(cls.ontoportal_client_class.name)
except ValueError:
envar_key = "BIOPORTAL_API_KEY"
if envar_key in os.environ:
api_key = os.environ[envar_key]
if api_key is None:
self.skipTest("Skipping bioportal tests, no API key set")
impl = cls()
impl = cls(api_key=api_key)
self.impl = impl

def test_text_annotator(self):
Expand Down

0 comments on commit af7634b

Please sign in to comment.