def main(): reqs = read_requirements() prereqs = get_prereqs(reqs) coreqs = get_coreqs(reqs) courses = read_courses() sifted_prereqs = sift_reqs(prereqs) sifted_coreqs = sift_reqs(coreqs) grouped_courses = group_courses(courses) readable_prereqs = replace_course_ids_with_names(sifted_prereqs, grouped_courses) readable_coreqs = replace_course_ids_with_names(sifted_coreqs, grouped_courses) courses_with_reqs = match_reqs_to_courses(readable_prereqs, readable_coreqs, courses) ungrouped_courses_with_reqs = ungroup_courses(courses_with_reqs) sorted_courses_with_reqs = sorted(ungrouped_courses_with_reqs, key=lambda c: c['course']) write_pretty(sorted_courses_with_reqs, 'output/requirements.json') write_minified(sorted_courses_with_reqs, 'output/requirements.min.json')
def test_nested_group(self): requirements = ( Requirement(rq_group="123", line="1", line_type="RQ", rqs_typ="PRE", operator="EQ", rqrmnt="456"), Requirement(rq_group="456", line="1", line_type="RQ", rqs_typ="PRE", operator="EQ", rqrmnt="789"), Requirement(rq_group="789", line="1", line_type="CRSE", rqs_typ="PRE", operator="EQ", course_id="444444") ) self.assertEqual({"123": "444444", "456": "444444", "789": "444444"}, sift_reqs(requirements))
def test_course_and_group(self): requirements = ( Requirement(rq_group="123", line="2", line_type="RQ", rqs_typ="PRE", operator="EQ", conn="AND", rqrmnt="456"), Requirement(rq_group="123", line="1", line_type="CRSE", rqs_typ="PRE", operator="EQ", course_id="123456"), Requirement(rq_group="456", line="1", line_type="CRSE", rqs_typ="PRE", operator="EQ", course_id="444444") ) self.assertEqual({"123": "(123456 & 444444)", "456": "444444"}, sift_reqs(requirements))
def test_parens(self): requirements = ( Requirement(rq_group="34", line="1", line_type="COND", value="AMR2MAJ", operator="EQ", parenth="("), Requirement(rq_group="34", line="2", line_type="COND", value="AMRBA", operator="EQ", conn="OR", parenth=")"), Requirement(rq_group="34", line="3", line_type="COND", value="U4", operator="EQ", conn="AND"), ) self.assertEqual({"34": "((AMR2MAJ | AMRBA) & U4)"}, sift_reqs(requirements))
def test_one_course(self): requirements = ( Requirement(rq_group="123", line="1", line_type="CRSE", rqs_typ="PRE", course_id="123456", operator="EQ"), ) self.assertEqual({"123": "123456"}, sift_reqs(requirements))
def test_condition(self): requirements = ( Requirement(rq_group="123", line="1", line_type="COND", cond_code="LVL", value="U4", operator="EQ"), ) self.assertEqual({"123": "U4"}, sift_reqs(requirements))
def test_two_courses(self): requirements = ( Requirement(rq_group="123", line="1", line_type="CRSE", rqs_typ="PRE", course_id="123456", operator="EQ"), Requirement(rq_group="123", line="2", line_type="CRSE", rqs_typ="PRE", course_id="789012", operator="EQ", conn="AND"), ) self.assertEqual({"123": "(123456 & 789012)"}, sift_reqs(requirements))