def test_weekend(): func.mock.reset_mock() s = scheduler.DayOfWeekScheduledCallback(func) s.weekdays('weekend') s.set_next_run_time(datetime(2001, 1, 1, 12, 30)) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 6) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 7) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 13)
def test_every_day(): func.mock.reset_mock() s = scheduler.DayOfWeekScheduledCallback(func) s.weekdays('all') s.time(time(hour=0, minute=0)) now = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) assert s.get_next_call() == now + timedelta(days=1) s._calculate_next_call() assert s.get_next_call() == now + timedelta(days=2) s._calculate_next_call() assert s.get_next_call() == now + timedelta(days=3)
def test_workday(): func.mock.reset_mock() s = scheduler.DayOfWeekScheduledCallback(func) s.weekdays('workday') s.set_next_run_time(datetime(2001, 1, 1, 12, 30)) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 2) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 3) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 4) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 5) s._calculate_next_call() assert s._next_call.date() == date(2001, 1, 8)
def test_weekend(): func.mock.reset_mock() s = scheduler.DayOfWeekScheduledCallback(func) s.weekdays('weekend') s.time(datetime(year=2001, month=1, day=1, hour=12)) assert s.get_next_call() == datetime(2001, 1, 6, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 7, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 13, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 14, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 20, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 21, 12)
def test_workday(): func.mock.reset_mock() s = scheduler.DayOfWeekScheduledCallback(func) s.weekdays('workday') s.time(datetime(year=2000, month=12, day=30, hour=12)) assert s.get_next_call() == datetime(2001, 1, 1, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 2, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 3, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 4, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 5, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 8, 12) s._calculate_next_call() assert s.get_next_call() == datetime(2001, 1, 9, 12)