Exemple #1
0
def test_section_int():
    d1 = ct.DayTime(9, 0)
    d2 = ct.DayTime(9, 50)
    s = courses.Section('LEC', 'John Doe', 'MWF', d1, d2)

    assert 'LEC' == s.kind
    assert 'John Doe' == s.instructor
    assert ['M', 'W', 'F'] == s.days
    assert d1 == s.start
    assert d2 == s.end
Exemple #2
0
    def parse_course_json(self, json):
        """Given the full json dictionary for a given course, returns a Course
        object appropriately filled."""
        dept_short = json['subject']
        department = self.dept_keys[dept_short]
        number = json['catalogNbr']
        title = json['titleLong']

        # Whether different enrollment patterns are truly divided into different
        # enrollGroups seems to vary widely by department and course. I would
        # just pull all the meetings from all enrollGroups, but the required
        # items could theoretically change between enrollGroups. I'm not sure
        # if that happens. We check for it here. TODO: figure this out.
        required = None
        for e in json['enrollGroups']:
            if required == None:
                required = e['componentsRequired']
            elif sorted(required) != sorted(e['componentsRequired']):
                raise RuntimeError('enrollGroups have different demands')
        if sorted(required) != sorted(list(set(required))):
            raise RuntimeError('API query yielded non-unique requirements')

        sections = []
        for eg in json['enrollGroups']:
            for cs in eg['classSections']:
                kind = cs['ssrComponent']

                for sec in cs['meetings']:
                    instructor = []
                    for i in sec['instructors']:
                        instructor.append(i['firstName'] + ' ' + i['lastName'])
                    instructor = ', '.join(instructor)

                    days = sec['pattern']

                    try:
                        start = ct.DayTime.parse_time_string(sec['timeStart'])
                        end = ct.DayTime.parse_time_string(sec['timeEnd'])
                    except ValueError:
                        continue

                    try:
                        sections.append(
                            courses.Section(kind, instructor, days, start,
                                            end))
                    except ValueError:
                        continue

        try:
            return courses.Course(department, dept_short, number, title,
                                  required, sections)
        except ValueError:
            return None
Exemple #3
0
def test_course_init():
    d1 = ct.DayTime(9, 0)
    d2 = ct.DayTime(9, 50)
    s = courses.Section('LEC', 'John Doe', 'MWF', d1, d2)
    c1 = courses.Course('Mathematics', 'MATH', 4130, 'Analysis', ['LEC'], [s])
    c2 = courses.Course('Mathematics', 'MATH', '4130', 'Analysis', ['LEC'], [s])

    assert c1 == c2
    assert (c1.as_json() == {
        'department' : 'Mathematics',
        'dept_short' : 'MATH',
        'number' : '4130',
        'title' : 'Analysis',
        'required' : ['LEC'],
        'sections' : [s.as_json()]
    })
Exemple #4
0
def test_section_as_json():
    d1 = ct.DayTime(9, 0)
    d2 = ct.DayTime(9, 50)
    s = courses.Section('LEC', 'John Doe', 'MWF', d1, d2)

    start_row = 1 + ((d1.hour - 8) * 12) + (d1.minute / 5)
    end_row = 1 + ((d2.hour - 8) * 12) + (d2.minute / 5)

    assert (s.as_json() == {
        'kind' : 'LEC',
        'instructor' : 'John Doe',
        'ref' : 'MWF 09:00 - 09:50',
        'day_idxs' : [1, 3, 5],
        'start_row' : start_row,
        'end_row' : end_row
    })
Exemple #5
0
def test_section_repr():
    d1 = ct.DayTime(9, 0)
    d2 = ct.DayTime(9, 50)
    s = courses.Section('LEC', 'John Doe', 'MWF', d1, d2)
    assert s == eval('courses.' + s.__repr__())