Skip to content

Commit 5c12898

Browse files
committed
Test CSV downloads against the values on the page
1 parent da6954e commit 5c12898

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

test_module.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import random
88
import json
99
import csv
10+
import requests
11+
from bs4 import BeautifulSoup
1012
from contextlib import contextmanager
1113

1214

@@ -640,13 +642,14 @@ def test_download_mandates_csv(self):
640642
# Delete the file with a finally block no matter what happens
641643
try:
642644
scholarly.download_mandates_csv(filename)
643-
funder, policy, percentage2020 = [], [], []
645+
funder, policy, percentage2020, percentageOverall = [], [], [], []
644646
with open(filename, "r") as f:
645647
csv_reader = csv.DictReader(f)
646648
for row in csv_reader:
647649
funder.append(row['\ufeffFunder'])
648650
policy.append(row['Policy'])
649651
percentage2020.append(row['2020'])
652+
percentageOverall.append(row['Overall'])
650653

651654
agency_policy = {
652655
"US National Science Foundation": "https://www.nsf.gov/pubs/2015/nsf15052/nsf15052.pdf",
@@ -661,10 +664,16 @@ def test_download_mandates_csv(self):
661664
"Swedish Research Council for Environment, Agricultural Sciences and Spatial Planning": "88%"
662665
}
663666

664-
for agency in agency_policy:
667+
response = requests.get("https://scholar.google.com/citations?view_op=mandates_leaderboard&hl=en")
668+
soup = BeautifulSoup(response.text, "html.parser")
669+
agency_overall = soup.find_all("td", class_="gsc_mlt_n gsc_mlt_bd")
670+
671+
for agency, index in zip(agency_policy, [4-1,10-1, 19-1, 64-1]):
665672
agency_index = funder.index(agency)
666673
self.assertEqual(policy[agency_index], agency_policy[agency])
667674
self.assertEqual(percentage2020[agency_index], agency_2020[agency])
675+
# Check that the percentage values from CSV and on the page agree.
676+
self.assertEqual(percentageOverall[agency_index], agency_overall[index].text)
668677
finally:
669678
if os.path.exists(filename):
670679
os.remove(filename)

0 commit comments

Comments
 (0)