From f0b765f67c77b57e3b1393bbc80fa2c2c11c439c Mon Sep 17 00:00:00 2001 From: Milo Thurston Date: Tue, 20 Aug 2024 15:50:41 +0100 Subject: [PATCH 1/4] Mocked one test, mock seems to apply to others. #557 --- tests/utils/test_isatools_utils.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/utils/test_isatools_utils.py b/tests/utils/test_isatools_utils.py index b7f1a8b2..3da371be 100644 --- a/tests/utils/test_isatools_utils.py +++ b/tests/utils/test_isatools_utils.py @@ -10,6 +10,7 @@ from io import StringIO from jsonschema.exceptions import ValidationError +from unittest.mock import Mock from isatools import isajson from isatools import isatab @@ -168,17 +169,22 @@ def test_create_isatab_archive_filter_on_transcription_profiling(self): class TestPubMedIDUtil(unittest.TestCase): + return_values = { + 'doi': 'abc123', + 'authors': ['A', 'B'], + 'year': 1912, + 'journal': 'shipping news', + 'title': 'surprise' + } def test_get_pubmed_article(self): - J = pubmed.get_pubmed_article('25520553') - self.assertEqual(J['doi'], '10.4137/CIN.S13895') - self.assertEqual(J['authors'], ['Johnson D', 'Connor AJ', 'McKeever S', - 'Wang Z', 'Deisboeck TS', 'Quaiser T', - 'Shochat E']) - self.assertEqual(J['year'], '2014') - self.assertEqual(J['journal'], 'Cancer Inform') - self.assertEqual( - J['title'], 'Semantically linking in silico cancer models.') + pubmed.get_pubmed_article = Mock(return_value = return_values) + j = pubmed.get_pubmed_article('25520553') + self.assertEqual(j['doi'], return_values['doi']) + self.assertEqual(j['authors'], return_values['authors']) + self.assertEqual(j['year'], return_values['year']) + self.assertEqual(j['journal'], return_values['journal']) + self.assertEqual(j['title'], return_values['title']) def test_set_pubmed_article(self): p = Publication(pubmed_id='25520553') From a0adc992f977934ede3c9eddcb1098ebc347cc55 Mon Sep 17 00:00:00 2001 From: Milo Thurston Date: Tue, 27 Aug 2024 11:10:17 +0100 Subject: [PATCH 2/4] Mocked tests and fixed test_isatools_utils #557 --- tests/utils/test_isatools_utils.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/utils/test_isatools_utils.py b/tests/utils/test_isatools_utils.py index 3da371be..a3b4c324 100644 --- a/tests/utils/test_isatools_utils.py +++ b/tests/utils/test_isatools_utils.py @@ -85,10 +85,9 @@ def test_get_ontology(self): self.assertEqual(ontology_source.name, 'efo') self.assertEqual( ontology_source.file, - 'https://www.ebi.ac.uk/ols/api/ontologies/efo') + 'https://www.ebi.ac.uk/ols4/api/ontologies/efo?lang=en') self.assertIsInstance(ontology_source.version, str) - self.assertEqual( - ontology_source.description, '') + self.assertEqual(ontology_source.description, 'Experimental Factor Ontology') def test_search_for_term(self): ontology_source = ols.get_ols_ontology('efo') @@ -178,26 +177,24 @@ class TestPubMedIDUtil(unittest.TestCase): } def test_get_pubmed_article(self): - pubmed.get_pubmed_article = Mock(return_value = return_values) + pubmed.get_pubmed_article = Mock(return_value = self.return_values) j = pubmed.get_pubmed_article('25520553') - self.assertEqual(j['doi'], return_values['doi']) - self.assertEqual(j['authors'], return_values['authors']) - self.assertEqual(j['year'], return_values['year']) - self.assertEqual(j['journal'], return_values['journal']) - self.assertEqual(j['title'], return_values['title']) + self.assertEqual(j['doi'], self.return_values['doi']) + self.assertEqual(j['authors'], self.return_values['authors']) + self.assertEqual(j['year'], self.return_values['year']) + self.assertEqual(j['journal'], self.return_values['journal']) + self.assertEqual(j['title'], self.return_values['title']) def test_set_pubmed_article(self): + pubmed.get_pubmed_article = Mock(return_value=self.return_values) p = Publication(pubmed_id='25520553') pubmed.set_pubmed_article(p) - self.assertEqual(p.doi, '10.4137/CIN.S13895') - self.assertEqual(p.author_list, 'Johnson D, Connor AJ, McKeever S, ' - 'Wang Z, Deisboeck TS, Quaiser T, ' - 'Shochat E') - self.assertEqual( - p.title, 'Semantically linking in silico cancer models.') + self.assertEqual(p.doi, self.return_values['doi']) + self.assertEqual(p.author_list, ", ".join(self.return_values['authors'])) + self.assertEqual(p.title, self.return_values['title']) self.assertIsInstance(p.comments[0], Comment) self.assertEqual(p.comments[0].name, 'Journal') - self.assertEqual(p.comments[0].value, 'Cancer Inform') + self.assertEqual(p.comments[0].value, self.return_values['journal']) class TestIsaTabFixer(unittest.TestCase): From 7467ffb0cb1e0108a9b019fb3134a96b94f0d052 Mon Sep 17 00:00:00 2001 From: Milo Thurston Date: Tue, 27 Aug 2024 11:48:52 +0100 Subject: [PATCH 3/4] Removed tests not needed due to mocking. #557 --- tests/utils/test_isatools_utils.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/utils/test_isatools_utils.py b/tests/utils/test_isatools_utils.py index 34bac9eb..80a50d00 100644 --- a/tests/utils/test_isatools_utils.py +++ b/tests/utils/test_isatools_utils.py @@ -186,22 +186,10 @@ def test_get_pubmed_article(self): self.assertEqual(j['journal'], self.return_values['journal']) self.assertEqual(j['title'], self.return_values['title']) - J1 = pubmed.get_pubmed_article('890406') - self.assertEqual(J1['doi'], '') - - J2 = pubmed.get_pubmed_article('14909816') - self.assertEqual(J2['doi'], "") - - J3 = pubmed.get_pubmed_article('2872386') - self.assertEqual(J3['doi'], "10.1016/s0025-7125(16)30931-2") - - J4 = pubmed.get_pubmed_article('14870036') - self.assertEqual(J4['doi'], "") def test_set_pubmed_article(self): pubmed.get_pubmed_article = Mock(return_value=self.return_values) p = Publication(pubmed_id='25520553') - prs = Person(first_name="bob") pubmed.set_pubmed_article(p) self.assertEqual(p.doi, self.return_values['doi']) self.assertEqual(p.author_list, ", ".join(self.return_values['authors'])) From 0b4afe6d21dcec3a7404b21bbee3b6b6dbcb256b Mon Sep 17 00:00:00 2001 From: Milo Thurston Date: Fri, 30 Aug 2024 11:22:36 +0100 Subject: [PATCH 4/4] Fix ols test. --- tests/utils/test_isatools_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/utils/test_isatools_utils.py b/tests/utils/test_isatools_utils.py index 80a50d00..826fd3d9 100644 --- a/tests/utils/test_isatools_utils.py +++ b/tests/utils/test_isatools_utils.py @@ -83,9 +83,8 @@ def test_get_ontology(self): ontology_source = ols.get_ols_ontology('efo') self.assertIsInstance(ontology_source, OntologySource) self.assertEqual(ontology_source.name, 'efo') - self.assertEqual( - ontology_source.file, - 'https://www.ebi.ac.uk/ols4/api/ontologies/efo?lang=en') + self.assertIn("https://www.ebi.ac.uk/ols", ontology_source.file) + self.assertIn("/api/ontologies/efo?lang=en", ontology_source.file) self.assertIsInstance(ontology_source.version, str) self.assertEqual(ontology_source.description, 'Experimental Factor Ontology')