def test_byKeyword_whitespace(self): """ Test that keyword search ignores leading and trailing whitespace """ d = DescSearches() self.assertTrue(len(d.byKeyword(self.single_course, " htm*4080 ", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "\nhtm*4080\n", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "\thtm*4080\t", '=')) == 1)
def test_byKeyword(self): """ Test that keyword search returns correct results """ d = DescSearches() self.assertTrue(len(d.byKeyword(self.single_course, "htm*4080", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "SERVICE", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "hospitality and tourism", '=')) == 1)
def test_byKeyword_case(self): """ Test that keyword search returns correct results regardless of upper/lower case """ upperWord = "TOURISM" lowerWord = "tourism" mixedWord = "tOUrIsM" d = DescSearches() upperResult = d.byKeyword(self.single_course, upperWord, '=') lowerResult = d.byKeyword(self.single_course, lowerWord, '=') mixedResult = d.byKeyword(self.single_course, mixedWord, '=') self.assertTrue(len(upperResult) == 1) self.assertTrue(len(lowerResult) == 1) self.assertTrue(len(mixedResult) == 1)
def test_byKeyword_invalid(self): """ Test that keyword search raises exceptions for invalid keyword """ d = DescSearches() with self.assertRaises(Exception) : d.byKeyword(self.single_course, 5, '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, "", '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, " ", '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, "\n\t", '=')
class TestIntegration(unittest.TestCase): @classmethod def setUpClass(self): self.search = DescSearches() converter = PDFConverter() converter.openPDF("./c12.pdf") parser = CourseParser() self.courses = parser.open_file("converted-pdf.txt") def test_findCIS4250(self): socsCourses = self.search.byDepartment(self.courses, "School of Computer Science", "=") cisCourses = self.search.byCourseCode(socsCourses, "CIS", "=") fourthYearCourses = self.search.byCourseLevel(cisCourses, "4", "=") cis4250 = self.search.byCourseNumber(fourthYearCourses,"4250", "=") self.assertTrue(cis4250[0].code == "CIS" and cis4250[0].number == "4250") def test_findENVS1060(self): oneCreditCourses = self.search.byWeight(self.courses, 0.5, "=") summerCourses = self.search.bySemester(oneCreditCourses, SemesterOffered.S, "=") soesCourses = self.search.byDepartment(summerCourses, "School of Environmental Sciences", "=") firstYearCourses = self.search.byCourseLevel(soesCourses, "1", "=") envsCourses = self.search.byCourseCode(firstYearCourses, "ENVS", "=") envs1060 = self.search.byCourseNumber(envsCourses, "1060", "=") self.assertTrue(envs1060[0].code == "ENVS" and envs1060[0].number == "1060") def test_languageKeyword(self): languageKeywordCourses = self.search.byKeyword(self.courses, "language", "=") englishKeywordCourses = self.search.byKeyword(languageKeywordCourses, "english", "=") frenchKeywordCourses = self.search.byKeyword(englishKeywordCourses, "french", "=") fallCourses = self.search.bySemester(frenchKeywordCourses, SemesterOffered.F, "=") self.assertTrue(fallCourses[0].code == "FREN" and fallCourses[0].number == "3500")
def test_byKeyword_none(self): """ Test that keyword search returns no results for keyword not in courses """ d = DescSearches() self.assertTrue(len(d.byKeyword(self.single_course, "does not exist", '=')) == 0)