示例#1
0
def test_scheduler_unschedule():
    event = Event()
    scheduler = Scheduler()
    scheduler.schedule(event, 6)
    scheduler.schedule(Event(), 5)
    scheduler.schedule(Event(), 7)

    scheduler.unschedule(event)

    for priority, scheduled_event in scheduler.priority_queue._queue:
        assert scheduled_event is not event
示例#2
0
class TestScheduler(unittest.TestCase):
    def setUp(self):
        self.s = Scheduler()

    def test_schedule(self):
        schedules = self.s.schedule([{
            "department": "ART",
            "course_number": 210
        }, {
            "department": "GEOL",
            "course_number": 102
        }])
示例#3
0
def test_scheduler_tick_multiple_events():
    executed_events = set()

    scheduler = Scheduler()
    scheduler.schedule(TrackedEvent("event one", executed_events), 1)
    scheduler.schedule(TrackedEvent("event two", executed_events), 2)
    scheduler.schedule(TrackedEvent("event three", executed_events), 2)
    scheduler.schedule(TrackedEvent("event four", executed_events), 3)

    scheduler.tick()
    assert len(scheduler.priority_queue._queue) == 3
    assert executed_events == {"event one"}

    scheduler.tick()
    assert len(scheduler.priority_queue._queue) == 2
    assert executed_events == {"event one", "event two"}

    scheduler.tick()
    assert len(scheduler.priority_queue._queue) == 1
    assert executed_events == {"event one", "event two", "event three"}

    scheduler.tick()
    assert len(scheduler.priority_queue._queue) == 0
    assert executed_events == {
        "event one", "event two", "event three", "event four"
    }
示例#4
0
def test_scheduler_tick():
    scheduler = Scheduler()
    scheduler.schedule(TrackedEvent("event one", set()), 1)

    latest_event = scheduler.tick()
    assert latest_event.id == "event one"
示例#5
0
def test_scheduler_schedule():
    scheduler = Scheduler()
    scheduler.schedule(Event(), 5)
    assert len(scheduler.priority_queue._queue) == 1