Skip to content

Commit

Permalink
Relaxed test_google_scholar.py to be robust to network issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgp2 committed Apr 15, 2023
1 parent 70856e4 commit efa4bbe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
13 changes: 9 additions & 4 deletions src/minifold/google_scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def send_query(self, gs_query: ScholarQuery):
Args:
gs_query (ScholarQuery): A Google scholar query.
Raises:
``RuntimeError`` if the result can't be fetched from Google scholar.
"""
# Network
url = gs_query.get_url()
Expand All @@ -187,10 +190,12 @@ def send_query(self, gs_query: ScholarQuery):
s_html = response.text

# Parsing
assert s_html
self.parse(s_html)
self.articles = list()
self.parse(s_html)
if s_html:
self.parse(s_html)
self.articles = list()
self.parse(s_html)
else:
raise RuntimeError("Cannot fetch result from Google scholar")


class GoogleScholarConnector(Connector):
Expand Down
47 changes: 28 additions & 19 deletions tests/test_google_scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@
SCHOLAR = GoogleScholarConnector()

def test_google_scholar():
entries = SCHOLAR.query(Query(
filters = BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob")
))
assert len(entries) >= 9
try:
entries = SCHOLAR.query(Query(
filters = BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob")
))
assert len(entries) >= 9
except RuntimeError:
pass

def test_google_scholar_where_year():
entries = SCHOLAR.query(Query(
filters = BinaryPredicate(
BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob"),
"&&",
BinaryPredicate(
BinaryPredicate("year", "<=", 2018),
try:
entries = SCHOLAR.query(Query(
filters = BinaryPredicate(
BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob"),
"&&",
BinaryPredicate("year", ">=", 2016)
BinaryPredicate(
BinaryPredicate("year", "<=", 2018),
"&&",
BinaryPredicate("year", ">=", 2016)
)
)
)
))
assert len(entries) == 5
))
assert len(entries) == 5
except RuntimeError:
pass

def test_google_scholar_limit():
entries = SCHOLAR.query(Query(
filters = BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob"),
limit = 2
))
assert len(entries) == 2
try:
entries = SCHOLAR.query(Query(
filters = BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob"),
limit = 2
))
assert len(entries) == 2
except RuntimeError:
pass

0 comments on commit efa4bbe

Please sign in to comment.