diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index acbf2ab..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "tests/ols-docker"] - path = tests/ols-docker - url = https://github.com/Ensembl/OLS-docker.git - branch = master diff --git a/.travis.yml b/.travis.yml index 6329fb6..d7bd084 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,25 @@ language: python python: - - "3.6" - - "3.7" + - "3.8" services: - docker before_install: - - git submodule sync - - git submodule update --init --recursive --remote - - docker build -t ols tests/ols-docker - - docker run -d -p 127.0.0.1:8080:8080 -t ols - - docker ps -a + - docker run -it -d -v /var/run/docker.sock:/var/run/docker.sock ensemblorg/ensembl-ols-docker:latest install: - pip install -e . - pip install -r requirements-test.txt script: + - | + # Wait for the ols4-backend to be up + until [ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/api)" -eq "200" ]; do + echo 'Waiting for the service to be available...' + sleep 30 + done - nosetests tests.test_basic --verbose --with-coverage --cover-package=ebi.ols after_success: - coveralls +after_script: + - docker stop $(docker ps -q) notifications: email: on_success: change diff --git a/ebi/ols/api/base.py b/ebi/ols/api/base.py index 291e19d..21e1ffb 100644 --- a/ebi/ols/api/base.py +++ b/ebi/ols/api/base.py @@ -549,6 +549,7 @@ def pages(self): return self._get_pages() def _get_data(self, path, document): + logger.debug(f"Getting data {path} {document}") return document.data[path]['docs'] @property diff --git a/ebi/ols/api/helpers.py b/ebi/ols/api/helpers.py index 98c1442..2c6a877 100644 --- a/ebi/ols/api/helpers.py +++ b/ebi/ols/api/helpers.py @@ -173,7 +173,8 @@ class OntologyConfig(OLSHelper): skos = None def __init__(self, **kwargs): - annotations = OntologyAnnotation(**kwargs.pop("annotations", {})) + kwargs.pop("annotations", {}) + annotations = OntologyAnnotation(**kwargs) super().__init__(annotations=annotations, **kwargs) def __repr__(self): diff --git a/requirements.txt b/requirements.txt index dadf60e..fda8bcc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ inflection~=0.3.1 coreapi~=2.3.3 hal_codec~=1.0.2 requests~=2.22 +urllib3==1.26.6 diff --git a/tests/ols-docker b/tests/ols-docker deleted file mode 160000 index 5f33506..0000000 --- a/tests/ols-docker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f335069840600329ab33b18d83b0df3cf18eec2 diff --git a/tests/test_basic.py b/tests/test_basic.py index 10fd15a..ae4cae5 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -116,7 +116,7 @@ def test_ontology_terms(self): ontology = self.client.ontology("aero") terms = ontology.terms() self.assertEqual(terms.index, 0) - self.assertGreaterEqual(len(terms), ontology.number_of_terms) + self.assertGreaterEqual(ontology.number_of_terms, len(terms)) self._checkTerms(terms) def test_ontology_individuals(self): @@ -128,7 +128,7 @@ def test_ontology_individuals(self): def test_ontology_properties(self): ontology = self.client.ontology("aero") properties = ontology.properties() - self.assertGreaterEqual(len(properties), ontology.number_of_properties) + self.assertGreaterEqual(ontology.number_of_properties, len(properties)) self._checkProperties(properties) def test_list_range(self): @@ -157,24 +157,23 @@ def test_list_filters(self): Test ontology terms api filtering options :return: """ - filters = {'short_form': 'DUO_0000024'} - ontology = self.client.ontology('duo') - ontologies = self.client.ontologies(filters={'fake_filter': 'fake_value'}) + filters = {'short_form': 'BFO_0000030"'} + ontology = self.client.ontology('bfo') terms = ontology.terms(filters=filters) for term in terms: - self.assertEqual(term.short_form, 'DUO_0000024') - filters = {'obo_id': 'DUO:0000024'} + self.assertEqual(term.short_form, 'BFO_0000030') + filters = {'obo_id': 'BFO:0000030'} terms = ontology.terms(filters=filters) for term in terms: - self.assertEqual(term.obo_id, 'DUO:0000024') + self.assertEqual(term.obo_id, 'BFO:0000030') - filters = {'iri': 'http://purl.obolibrary.org/obo/DUO_0000017'} + filters = {'iri': 'http://purl.obolibrary.org/obo/BFO_0000034'} terms = ontology.terms(filters=filters) for term in terms: - self.assertEqual(term.short_form, 'DUO_0000017') - self.assertEqual(term.obo_id, 'DUO:0000017') - self.assertEqual(term.iri, 'http://purl.obolibrary.org/obo/DUO_0000017') + self.assertEqual(term.short_form, 'BFO_0000034') + self.assertEqual(term.obo_id, 'BFO:0000034') + self.assertEqual(term.iri, 'http://purl.obolibrary.org/obo/BFO_0000034') def test_terms(self): """ @@ -182,10 +181,13 @@ def test_terms(self): Should warn that test may be long according to the nnumber of terms involved :return: """ - term_1 = helpers.Term(ontology_name='duo', iri='http://purl.obolibrary.org/obo/DUO_0000026') + term_1 = helpers.Term(ontology_name='bfo', iri='http://purl.obolibrary.org/obo/BFO_0000028') ancestors = term_1.load_relation('ancestors') + ancestors_obo_ids = [] for ancestor in ancestors: + ancestors_obo_ids.append(ancestors.obo_id) self._checkTerm(ancestor) + self.assertTrue('BFO:0000004' in ancestors_obo_ids) self._checkTerm(term_1) def test_dynamic_links(self): @@ -231,7 +233,7 @@ def test_search_filters(self): def test_childrenOf_is_valid_response_filter(self): # Given - filters = {'childrenOf':'A'} + filters = {'childrenOf': 'A'} expected_filters = filters.copy() # When actual_filters = self.client.search.filters_response(filters) @@ -240,7 +242,7 @@ def test_childrenOf_is_valid_response_filter(self): def test_childrenOf_value_can_be_set(self): # Given - filters = {'childrenOf':{'A','B'}} + filters = {'childrenOf': {'A', 'B'}} expected_filters = filters.copy() # When actual_filters = self.client.search.filters_response(filters) @@ -257,24 +259,24 @@ def test_childrenOf_value_cannot_be_list(self): def test_single_childrenOf_filters_search_results(self): # Given query = 'chemical' - ontology = 'phi' + ontology = 'bfo' filters = { 'fieldList': {'iri'}, - 'childrenOf': 'http://purl.obolibrary.org/obo/PHI_1000000' - } + 'childrenOf': 'http://purl.obolibrary.org/obo/BFO_123456' + } # When actual_terms = self.client.search( - query=query, + query=query, ontology=ontology, filters=filters) - actual_iris = { term.iri for term in actual_terms } + actual_iris = {term.iri for term in actual_terms} # Then expected_iris = { - 'http://purl.obolibrary.org/obo/PHI_1000003', - 'http://purl.obolibrary.org/obo/PHI_1000002' + 'http://purl.obolibrary.org/obo/PHI_1000003', + 'http://purl.obolibrary.org/obo/PHI_1000002' } self.assertEqual(actual_iris, expected_iris) - + def test_multiple_childrenOf_filters_search_results(self): # Given query = 'chemical' @@ -288,15 +290,15 @@ def test_multiple_childrenOf_filters_search_results(self): } # When actual_terms = self.client.search( - query=query, + query=query, ontology=ontology, filters=filters) - actual_iris = { term.iri for term in actual_terms } + actual_iris = {term.iri for term in actual_terms} # Then expected_iris = { - 'http://purl.obolibrary.org/obo/PHI_1000003', - 'http://purl.obolibrary.org/obo/PHI_1000002', - 'http://purl.obolibrary.org/obo/PHI_2000004' + 'http://purl.obolibrary.org/obo/PHI_1000003', + 'http://purl.obolibrary.org/obo/PHI_1000002', + 'http://purl.obolibrary.org/obo/PHI_2000004' } self.assertEqual(actual_iris, expected_iris) @@ -310,10 +312,10 @@ def test_childrenOf_non_existant_parent_yields_no_search_results(self): } # When actual_terms = self.client.search( - query=query, + query=query, ontology=ontology, filters=filters) - actual_iris = { term.iri for term in actual_terms } + actual_iris = {term.iri for term in actual_terms} # Then expected_iris = set() self.assertEqual(actual_iris, expected_iris) @@ -322,7 +324,7 @@ def test_search_kwargs(self): """ Test Search feature : - kwargs passed """ - mixed = self.client.search(query='go', type='property') + mixed = self.client.search(query='bfo', type='property') self.assertGreaterEqual(len(mixed), 15) clazz = [] @@ -439,23 +441,20 @@ def test_namespace(self): self.assertEqual(h_term.namespace, 'aero') # retrieved from obo_name_space annotation - h_term = helpers.Term(ontology_name='duo', iri='http://purl.obolibrary.org/obo/DUO_0000017') + h_term = helpers.Term(ontology_name='bfo', iri='http://purl.obolibrary.org/obo/BFO_0000034') self.client.detail(h_term) - self.assertEqual(h_term.namespace, 'duo') + self.assertEqual(h_term.namespace, 'bfo') def test_term_description(self): h_term = self.client.detail(iri="http://www.w3.org/2002/07/owl#Thing", - ontology_name='duo', type=helpers.Term) + ontology_name='aero', type=helpers.Term) self.assertEqual('', h_term.description) def test_properties_retrieval(self): subsets = "is quality measurement of" - - s_subsets = self.client.search(query=subsets, ontology='aero', type='property', - exact='true') - seen = set() - self.assertEqual(len(s_subsets), 1) - subset = s_subsets[0] + s_subsets = self.client.search(query=subsets, ontology='aero', type='property', exact='true') + self.assertEqual(len(s_subsets), 2) + subset = s_subsets[1] d_subset = self.client.property(identifier=subset.iri) self.assertEqual(d_subset.definition, subset.definition) self.assertEqual(d_subset.accession, 'IAO:0000221') @@ -463,7 +462,6 @@ def test_properties_retrieval(self): def test_term_definition(self): o_term = self.client.detail(iri="http://purl.obolibrary.org/obo/BFO_0000015", ontology_name='bfo', type=helpers.Term) - self.assertEqual(o_term.description, o_term.obo_definition_citation[0]['definition']) self.assertEqual(o_term.description, 'p is a process = Def. p is an occurrent that has temporal proper parts ' 'and for some time t, p s-depends_on some material entity at t. (axiom ' 'label in BFO2 Reference: [083-003])')