Пример #1
0
def test_add_time():
    beg1 = datetime.time(10, 0, 0)
    end1 = datetime.time(12, 0, 0)
    rng1 = TimeRange(beg1, end1)

    beg2 = datetime.time(12, 0, 0)
    end2 = datetime.time(14, 0, 0)
    rng2 = TimeRange(beg2, end2)

    mtime1 = MeetingTime(rng1, [0, 2, 4])
    mtime2 = MeetingTime(rng2, [0, 2, 4])

    course = Course('course', 'C0', 1)
    course.add_time(mtime1)
    course.add_time(mtime2)

    mtime3 = MeetingTime(rng2, [0, 2, 4])

    # Shouldn't allow adding conflicting times
    with pytest.raises(ValueError):
        course.add_time(mtime3)
Пример #2
0
def test_now():
    courses = []

    timerng = TimeRange(datetime.time(0, 0, 0), datetime.time(23, 59, 59))
    course1 = Course('course1', 'C1', 1)

    # This one never meets!
    mtime = MeetingTime(timerng, [0])
    mtime.weekdays = []

    course1.add_time(mtime)
    courses.append(course1)

    assert search.active_now(courses) is None

    course2 = Course('course2', 'C2', 1)

    # This one meets literally all the time
    mtime = MeetingTime(timerng, [0, 1, 2, 3, 4, 5, 6])
    course2.add_time(mtime)
    courses.append(course2)

    # course2 should fit our criteria
    assert course2 == search.active_now(courses)
Пример #3
0
def test_conflicts():
    beg1 = datetime.time(10, 0, 0)
    end1 = datetime.time(12, 0, 0)
    rng1 = TimeRange(beg1, end1)

    beg2 = datetime.time(12, 0, 0)
    end2 = datetime.time(14, 0, 0)
    rng2 = TimeRange(beg2, end2)

    mtime1 = MeetingTime(rng1, [0, 2, 4])
    mtime2 = MeetingTime(rng2, [0, 2, 4])

    course1 = Course('course1', 'C1', 1)
    course1.add_time(mtime1)

    course2 = Course('course2', 'C2', 1)
    course2.add_time(mtime2)

    # Courses 1 and 2 do not conflict
    assert not course1.conflicts(course2)
    assert not course2.conflicts(course1)

    beg3 = datetime.time(10, 0, 0)
    end3 = datetime.time(14, 0, 0)
    rng3 = TimeRange(beg3, end3)

    mtime3 = MeetingTime(rng3, [0, 2, 4])

    course3 = Course('course3', 'C3', 1)
    course3.add_time(mtime3)

    # Course 3 conflicts with both course 1 and courses 2
    assert course3.conflicts(course1)
    assert course3.conflicts(course2)
    assert course1.conflicts(course3)
    assert course2.conflicts(course3)