Skip to content

Commit 04cd545

Browse files
committed
Move keyword tests to TestScholarly
1 parent 834098e commit 04cd545

1 file changed

Lines changed: 67 additions & 67 deletions

File tree

test_module.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,73 @@ def test_search_keywords(self):
129129
self.assertEqual(author['name'], 'Arpita Ghosh')
130130
self.assertEqual(author['affiliation'], 'Cornell University')
131131

132+
def test_search_keyword_empty_keyword(self):
133+
"""
134+
As of 2020-04-30, there are 6 individuals that match the name 'label'
135+
"""
136+
# TODO this seems like undesirable functionality for
137+
# scholarly.search_keyword() with empty string. Surely, no authors
138+
# should be returned. Consider modifying the method itself.
139+
authors = [a for a in scholarly.search_keyword('')]
140+
self.assertGreaterEqual(len(authors), 6)
141+
142+
def test_search_keyword(self):
143+
"""
144+
Test that we can search based on specific keywords
145+
146+
When we search for the keyword "3d shape" the author
147+
Steven A. Cholewiak should be among those listed.
148+
When we search for the keyword "Haptics", Oussama Khatib
149+
should be listed first.
150+
"""
151+
# Example 1
152+
authors = [a['name'] for a in scholarly.search_keyword('3d shape')]
153+
self.assertIsNot(len(authors), 0)
154+
self.assertIn(u'Steven A. Cholewiak, PhD', authors)
155+
156+
# Example 2
157+
expected_author = {'affiliation': 'Stanford University',
158+
'citedby': 43856,
159+
'email_domain': '@cs.stanford.edu',
160+
'filled': [],
161+
'interests': ['Robotics',
162+
'Haptics',
163+
'Human Motion Understanding'],
164+
'name': 'Oussama Khatib',
165+
'scholar_id': '4arkOLcAAAAJ',
166+
'source': 'SEARCH_AUTHOR_SNIPPETS',
167+
'url_picture': 'https://scholar.google.com/citations?view_op=medium_photo&user=4arkOLcAAAAJ'
168+
}
169+
search_query = scholarly.search_keyword('Haptics')
170+
author = next(search_query)
171+
for key in author:
172+
if (key not in {"citedby", "container_type", "interests"}) and (key in expected_author):
173+
self.assertEqual(author[key], expected_author[key])
174+
self.assertEqual(set(author["interests"]), set(expected_author["interests"]))
175+
176+
# Example 3
177+
expected_author = {'affiliation': "CEA, Département d'Astrophysique",
178+
'citedby': 98936,
179+
'email_domain': '@cea.fr',
180+
'filled': [],
181+
'interests': ['Cosmology (CMB',
182+
'weak-lensing',
183+
'large scale structure)',
184+
'Statistics',
185+
'Image Processing'],
186+
'name': 'Jean-Luc Starck',
187+
'scholar_id': 'IAaAiXgAAAAJ',
188+
'source': 'SEARCH_AUTHOR_SNIPPETS',
189+
'url_picture': 'https://scholar.google.com/citations?view_op=medium_photo&user=IAaAiXgAAAAJ'
190+
}
191+
search_query = scholarly.search_keyword('large-scale structure')
192+
author = next(search_query)
193+
for key in author:
194+
if (key not in {"citedby", "container_type", "interests"}) and (key in expected_author):
195+
self.assertEqual(author[key], expected_author[key])
196+
scholarly.pprint(author)
197+
self.assertEqual(set(author["interests"]), set(expected_author["interests"]))
198+
132199
def test_search_author_single_author(self):
133200
query = 'Steven A. Cholewiak'
134201
authors = [a for a in scholarly.search_author(query)]
@@ -548,16 +615,6 @@ def setUpClass(cls):
548615

549616
scholarly.use_proxy(proxy_generator, secondary_proxy_generator)
550617

551-
def test_search_keyword_empty_keyword(self):
552-
"""
553-
As of 2020-04-30, there are 6 individuals that match the name 'label'
554-
"""
555-
# TODO this seems like undesirable functionality for
556-
# scholarly.search_keyword() with empty string. Surely, no authors
557-
# should be returned. Consider modifying the method itself.
558-
authors = [a for a in scholarly.search_keyword('')]
559-
self.assertGreaterEqual(len(authors), 6)
560-
561618
def test_search_pubs_empty_publication(self):
562619
"""
563620
Test that searching for an empty publication returns zero results
@@ -622,63 +679,6 @@ def test_bibtex(self):
622679
result = scholarly.bibtex(pub)
623680
self.assertEqual(result, expected_result.replace("\n ", "\n"))
624681

625-
def test_search_keyword(self):
626-
"""
627-
Test that we can search based on specific keywords
628-
629-
When we search for the keyword "3d shape" the author
630-
Steven A. Cholewiak should be among those listed.
631-
When we search for the keyword "Haptics", Oussama Khatib
632-
should be listed first.
633-
"""
634-
# Example 1
635-
authors = [a['name'] for a in scholarly.search_keyword('3d shape')]
636-
self.assertIsNot(len(authors), 0)
637-
self.assertIn(u'Steven A. Cholewiak, PhD', authors)
638-
639-
# Example 2
640-
expected_author = {'affiliation': 'Stanford University',
641-
'citedby': 43856,
642-
'email_domain': '@cs.stanford.edu',
643-
'filled': [],
644-
'interests': ['Robotics',
645-
'Haptics',
646-
'Human Motion Understanding'],
647-
'name': 'Oussama Khatib',
648-
'scholar_id': '4arkOLcAAAAJ',
649-
'source': 'SEARCH_AUTHOR_SNIPPETS',
650-
'url_picture': 'https://scholar.google.com/citations?view_op=medium_photo&user=4arkOLcAAAAJ'
651-
}
652-
search_query = scholarly.search_keyword('Haptics')
653-
author = next(search_query)
654-
for key in author:
655-
if (key not in {"citedby", "container_type", "interests"}) and (key in expected_author):
656-
self.assertEqual(author[key], expected_author[key])
657-
self.assertEqual(set(author["interests"]), set(expected_author["interests"]))
658-
659-
# Example 3
660-
expected_author = {'affiliation': "CEA, Département d'Astrophysique",
661-
'citedby': 98936,
662-
'email_domain': '@cea.fr',
663-
'filled': [],
664-
'interests': ['Cosmology (CMB',
665-
'weak-lensing',
666-
'large scale structure)',
667-
'Statistics',
668-
'Image Processing'],
669-
'name': 'Jean-Luc Starck',
670-
'scholar_id': 'IAaAiXgAAAAJ',
671-
'source': 'SEARCH_AUTHOR_SNIPPETS',
672-
'url_picture': 'https://scholar.google.com/citations?view_op=medium_photo&user=IAaAiXgAAAAJ'
673-
}
674-
search_query = scholarly.search_keyword('large-scale structure')
675-
author = next(search_query)
676-
for key in author:
677-
if (key not in {"citedby", "container_type", "interests"}) and (key in expected_author):
678-
self.assertEqual(author[key], expected_author[key])
679-
scholarly.pprint(author)
680-
self.assertEqual(set(author["interests"]), set(expected_author["interests"]))
681-
682682
def test_search_pubs(self):
683683
"""
684684
As of May 12, 2020 there are at least 29 pubs that fit the search term:

0 commit comments

Comments
 (0)