def test_run_all(self): mock_job = make_mock_job() every().minute.do(mock_job) every().hour.do(mock_job) every().day.at("11:00").do(mock_job) sche.run_all() assert mock_job.call_count == 3
def test_cancel_jobs(self): def stop_job(): return sche.CancelJob every().second.do(stop_job) every().second.do(stop_job) every().second.do(stop_job) assert len(sche.jobs) == 3 sche.run_all() assert len(sche.jobs) == 0
def test_clear_by_tag(self): every().second.do(make_mock_job(name="job1")).tag("tag1") every().second.do(make_mock_job(name="job2")).tag("tag1", "tag2") every().second.do(make_mock_job(name="job3")).tag( "tag3", "tag3", "tag3", "tag2") assert len(sche.jobs) == 3 sche.run_all() assert len(sche.jobs) == 3 sche.clear("tag3") assert len(sche.jobs) == 2 sche.clear("tag1") assert len(sche.jobs) == 0 every().second.do(make_mock_job(name="job1")) every().second.do(make_mock_job(name="job2")) every().second.do(make_mock_job(name="job3")) sche.clear() assert len(sche.jobs) == 0
def test_cancel_job(self): def stop_job(): return sche.CancelJob mock_job = make_mock_job() every().second.do(stop_job) mj = every().second.do(mock_job) assert len(sche.jobs) == 2 sche.run_all() assert len(sche.jobs) == 1 assert sche.jobs[0] == mj sche.cancel_job("Not a job") assert len(sche.jobs) == 1 sche.default_scheduler.cancel_job("Not a job") assert len(sche.jobs) == 1 sche.cancel_job(mj) assert len(sche.jobs) == 0
def test_job_func_args_are_passed_on(self): mock_job = make_mock_job() every().second.do(mock_job, 1, 2, "three", foo=23, bar={}) sche.run_all() mock_job.assert_called_once_with(1, 2, "three", foo=23, bar={})