Skip to content

Commit

Permalink
Refactor TC4
Browse files Browse the repository at this point in the history
Issue #17
  • Loading branch information
mrksbrg committed Jul 24, 2022
1 parent 4359edd commit 4c6183b
Showing 1 changed file with 13 additions and 53 deletions.
66 changes: 13 additions & 53 deletions test/test_5_runningnumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,40 @@
@author: Markus Borg
"""

import pytest
import os.path
from datetime import date
from swesesci.scholar import SSSScholar
from swesesci.affiliation import SSSAffiliation
from swesesci.scholar_reader import ScholarReader
from swesesci.scholar_miner import ScholarMiner
from swesesci.scholar_analyzer import ScholarAnalyzer
from swesesci.scholar_tabulator import ScholarTabulator

def string_splitter(scholar_string):
affiliation = scholar_string[0]
name = scholar_string[1]
running_number = scholar_string[2]
url = scholar_string[3]

try:
split1 = url.split("pid/")
split2 = split1[1].split(".xml")
pid = split2[0]
except IndexError:
print("Invalid format of input XML URL. (" + name + ")")
raise IndexError

return affiliation, name, running_number, pid, url

class TestClass_RunningNumber:

def setup_method(self):
self.scholars = []
self.affiliations = []
self.sss_scholars = []
self.sss_affiliations = []
subdirectory = "output"
try:
os.mkdir(subdirectory)
except Exception:
pass
self.filename_prefix = os.path.join(subdirectory, str(date.today()) + "_sss_")
self.test_scholar = [("Thomas Olsson", "0001", "https://dblp.org/pid/31/5587-1.xml")]

def add_sss_scholars(self, process_list, affiliation):
for person in process_list:
name = person[0]
running_number = person[1]
url = person[2]
# extract the pid from the url by substringing
try:
split1 = url.split("pid/")
split2 = split1[1].split(".xml")
pid = split2[0]
except IndexError:
print("Invalid format of input XML URL.")
return

self.scholars.append(SSSScholar(name, running_number, pid, url, affiliation, -1))
tmp_aff = SSSAffiliation(affiliation)
if tmp_aff not in self.affiliations:
tmp_aff.nbr_scholars += 1
self.affiliations.append(tmp_aff)
else:
curr = next((x for x in self.affiliations if affiliation == x.name), None)
curr.nbr_scholars += 1
reader = ScholarReader("test/test_5_runningnumber.csv")
self.sss_scholars, self.sss_affiliations = reader.read_candidate_scholars()
self.miner = ScholarMiner(self.filename_prefix, self.sss_scholars, self.sss_affiliations)
self.miner.parse_scholars()
self.sss_scholars = self.miner.get_scholars()

def test_thomas_olsson(self):
self.add_sss_scholars(self.test_scholar, "N/A")
self.miner = ScholarMiner(self.filename_prefix, self.scholars, self.affiliations)
self.miner.parse_scholars()
self.scholars = self.miner.get_scholars()
thomas = None
for scholar in self.scholars:
for scholar in self.sss_scholars:
if scholar.name == "Thomas Olsson":
thomas = scholar

# TC1: Test that DBLP returns a result
assert self.scholars != None
assert len(self.scholars) == 1
assert self.sss_scholars != None
assert len(self.sss_scholars) == 1

# TC2: Test that Thomas Olsson has at least 40 DBLP entries
assert thomas.dblp_entries >= 40
Expand Down Expand Up @@ -108,11 +68,11 @@ def test_thomas_olsson(self):
assert file_stats_csv.st_size > 0

# TC8: Test analyzer
analyzer = ScholarAnalyzer(self.filename_prefix, self.scholars, self.affiliations)
analyzer = ScholarAnalyzer(self.filename_prefix, self.sss_scholars, self.sss_affiliations)
analyzer.analyze_individual_research_interests()
assert thomas.sss_contrib >= 1.50
assert thomas.sss_rating >= 1.00

# TC10: Test tabulator
tabulator = ScholarTabulator(self.filename_prefix, self.scholars, self.affiliations)
tabulator = ScholarTabulator(self.filename_prefix, self.sss_scholars, self.sss_affiliations)
tabulator.write_tables()

0 comments on commit 4c6183b

Please sign in to comment.