class TestOfflineScheduler(object): def setup(self): self.scheduler = Scheduler() def teardown(self): if self.scheduler.running: self.scheduler.shutdown() def test_add_tentative_job(self): job = self.scheduler.add_date_job(lambda: None, datetime(2200, 7, 24)) assert isinstance(job, Job) eq_(self.scheduler.get_jobs(), []) def test_shutdown_offline(self): self.scheduler.shutdown() def test_configure_no_prefix(self): global_options = {'misfire_grace_time': '2', 'daemonic': 'false'} self.scheduler.configure(global_options) eq_(self.scheduler.misfire_grace_time, 1) eq_(self.scheduler.daemonic, True) def test_configure_prefix(self): global_options = {'napscheduler.misfire_grace_time': 2, 'napscheduler.daemonic': False} self.scheduler.configure(global_options) eq_(self.scheduler.misfire_grace_time, 2) eq_(self.scheduler.daemonic, False) def test_add_listener(self): val = [] self.scheduler.add_listener(val.append) event = SchedulerEvent(EVENT_SCHEDULER_START) self.scheduler.notify_listeners(event) eq_(len(val), 1) eq_(val[0], event) event = SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN) self.scheduler.notify_listeners(event) eq_(len(val), 2) eq_(val[1], event) self.scheduler.remove_listener(val.append) self.scheduler.notify_listeners(event) eq_(len(val), 2) def test_pending_jobs(self): # Tests that pending jobs are properly added to the jobs list when # the scheduler is started (and not before!) self.scheduler.add_date_job(lambda: None, datetime(9999, 9, 9)) eq_(self.scheduler.get_jobs(), []) self.scheduler.start() jobs = self.scheduler.get_jobs() eq_(len(jobs), 1)
class TestRunningScheduler(object): def setup(self): self.scheduler = Scheduler() self.scheduler.start() def teardown(self): if self.scheduler.running: self.scheduler.shutdown() def test_shutdown_timeout(self): self.scheduler.shutdown() @raises(SchedulerAlreadyRunningError) def test_scheduler_double_start(self): self.scheduler.start() @raises(SchedulerAlreadyRunningError) def test_scheduler_configure_running(self): self.scheduler.configure({}) def test_scheduler_double_shutdown(self): self.scheduler.shutdown() self.scheduler.shutdown(False)