Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock pubmed 557 #567

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions tests/utils/test_isatools_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,11 +83,12 @@ def test_get_ontology(self):
ontology_source = ols.get_ols_ontology('efo')
self.assertIsInstance(ontology_source, OntologySource)
self.assertEqual(ontology_source.name, 'efo')
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knirirr I recall that we coded it this way with @terazus to guard against version change, ( which makes the assumption that the service would keep the pattern and can not be guaranteed)

ontology_source.description, 'Experimental Factor Ontology')
ontology_source.file,
'https://www.ebi.ac.uk/ols4/api/ontologies/efo?lang=en')
self.assertIsInstance(ontology_source.version, str)
self.assertEqual(ontology_source.description, 'Experimental Factor Ontology')


def test_search_for_term(self):
ontology_source = ols.get_ols_ontology('efo')
Expand Down Expand Up @@ -167,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 = self.return_values)
j = pubmed.get_pubmed_article('25520553')
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'])

J1 = pubmed.get_pubmed_article('890406')
self.assertEqual(J1['doi'], '')
Expand All @@ -192,20 +199,16 @@ def test_get_pubmed_article(self):
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, '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')
with self.assertRaises(Exception) as context:
pubmed.set_pubmed_article(prs)
self.assertTrue("Can only set PubMed details on a Publication object" in context.exception)
self.assertEqual(p.comments[0].value, self.return_values['journal'])


class TestIsaTabFixer(unittest.TestCase):
Expand Down
Loading