def test_get_next_run_times(schedule: IntervalSchedule, timezone: DstTzInfo):
    now = timezone.localize(datetime(2016, 7, 31, 5, 17))
    previous_run_time = timezone.localize(datetime(2016, 7, 31, 5, 9, 55))
    expected = [
        timezone.localize(datetime(2016, 7, 31, 5, 12, 0)),
        timezone.localize(datetime(2016, 7, 31, 5, 14, 5)),
        timezone.localize(datetime(2016, 7, 31, 5, 16, 10))
    ]
    run_times = list(schedule.get_run_times(now, previous_run_time))
    assert run_times == expected
def schedule(start_time: datetime, end_time: datetime, timezone: DstTzInfo):
    return IntervalSchedule(task_id='taskname',
                            id='testschedule',
                            start_time=start_time,
                            end_time=end_time,
                            minutes=2,
                            seconds=5,
                            timezone=timezone,
                            args=[1, 6],
                            kwargs={'argument': 'value'})
def test_get_next_run_time(schedule: IntervalSchedule, previous_time, now,
                           expected, timezone: DstTzInfo):
    previous_time = convert_to_timezone(previous_time, timezone)
    now = convert_to_timezone(now, timezone)
    expected = convert_to_timezone(expected, timezone)
    assert schedule.get_next_run_time(now, previous_time) == expected
def test_dst_backward(schedule: IntervalSchedule, timezone: DstTzInfo):
    previous_time = timezone.localize(datetime(2016, 10, 30, 2, 58),
                                      is_dst=True)
    now = timezone.localize(datetime(2016, 10, 30, 2, 59), is_dst=True)
    expected = timezone.localize(datetime(2016, 10, 30, 2, 0, 5), is_dst=False)
    assert schedule.get_next_run_time(now, previous_time) == expected
def test_dst_forward(schedule: IntervalSchedule, timezone: DstTzInfo):
    previous_time = timezone.localize(datetime(2016, 3, 27, 1, 58))
    now = timezone.localize(datetime(2016, 3, 27, 1, 59))
    expected = timezone.localize(datetime(2016, 3, 27, 3, 0, 5))
    assert schedule.get_next_run_time(now, previous_time) == expected
def test_end_time(schedule: IntervalSchedule, timezone: DstTzInfo):
    """Test that end_time is respected."""
    now = timezone.localize(datetime(2020, 12, 31))
    assert schedule.get_next_run_time(now) is None
def test_start_time(schedule: IntervalSchedule, timezone: DstTzInfo,
                    start_time: datetime):
    """Test that start_time is respected."""
    now = timezone.localize(datetime(2016, 1, 15))
    assert schedule.get_next_run_time(now) == start_time
def test_resume_schedule(now: datetime, timezone: DstTzInfo):
    """Test that when resuming the schedule, the current time is returned."""
    schedule = IntervalSchedule(task_id='task', timezone=timezone, seconds=1)
    assert schedule.get_next_run_time(now) == now