def test_dst_backward(args: Dict[str, Any], now: datetime, now_dst: bool,
                      expected: datetime, expected_dst: bool,
                      timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, **args)
    now = timezone.localize(now, is_dst=now_dst)
    expected = timezone.localize(expected, is_dst=expected_dst)
    assert schedule.get_next_run_time(now) == expected
Пример #2
0
def test_range_step(timezone: DstTzInfo):
    """Test that a range expression with a step value produces the correct values."""
    schedule = CronSchedule(task_id='task', timezone=timezone, day='5-24/3')
    previous_run_time = timezone.localize(datetime(2016, 2, 23))
    now = timezone.localize(datetime(2016, 3, 31))
    expected = [timezone.localize(datetime(2016, 3, day)) for day in (5, 8, 11, 14, 17, 20, 23)]
    run_times = list(schedule.get_run_times(now, previous_run_time))
    assert run_times == expected
Пример #3
0
def test_weekday_increment_rollover(timezone: DstTzInfo):
    """
    Test that if a field's value exceeds the maximum value during a calculation, that field along
    with all the less significant ones are reset to their minimum values.

    """
    schedule = CronSchedule(task_id='task', timezone=timezone, day='8', day_of_week='fri')
    now = timezone.localize(datetime(2016, 3, 1))
    expected = timezone.localize(datetime(2016, 4, 8))
    assert schedule.get_next_run_time(now) == expected
def test_range_step(timezone: DstTzInfo):
    """Test that a range expression with a step value produces the correct values."""
    schedule = CronSchedule(task_id='task', timezone=timezone, day='5-24/3')
    previous_run_time = timezone.localize(datetime(2016, 2, 23))
    now = timezone.localize(datetime(2016, 3, 31))
    expected = [
        timezone.localize(datetime(2016, 3, day))
        for day in (5, 8, 11, 14, 17, 20, 23)
    ]
    run_times = list(schedule.get_run_times(now, previous_run_time))
    assert run_times == expected
def test_weekday_increment_rollover(timezone: DstTzInfo):
    """
    Test that if a field's value exceeds the maximum value during a calculation, that field along
    with all the less significant ones are reset to their minimum values.

    """
    schedule = CronSchedule(task_id='task',
                            timezone=timezone,
                            day='8',
                            day_of_week='fri')
    now = timezone.localize(datetime(2016, 3, 1))
    expected = timezone.localize(datetime(2016, 4, 8))
    assert schedule.get_next_run_time(now) == expected
def test_repr(kwargs, result, timezone):
    schedule = CronSchedule(task_id='taskname',
                            id='testschedule',
                            timezone=timezone,
                            **kwargs)
    assert repr(
        schedule
    ) == "<CronSchedule (id='testschedule', task_id='taskname', %s)>" % result
def test_fields_equality(kwargs: Dict[str, Any], timezone: DstTzInfo):
    """Test the equality of fields and their string forms for extra test coverage."""
    schedules = [
        CronSchedule(task_id='task', timezone=timezone, **kwargs)
        for _ in range(2)
    ]
    assert schedules[0].fields == schedules[1].fields
    for field1, field2 in zip(schedules[0].fields, schedules[1].fields):
        assert str(field1) == str(field2)
def schedule(timezone: DstTzInfo):
    return CronSchedule(task_id='taskname',
                        id='testschedule',
                        start_time=datetime(2016, 7, 20, 16, 40),
                        end_time=datetime(2016, 12, 25, 6, 16),
                        hour='*/2',
                        minute=5,
                        timezone=timezone,
                        args=[1, 6],
                        kwargs={'argument': 'value'})
Пример #9
0
def test_end_time(schedule: CronSchedule, timezone: DstTzInfo):
    """Test that end_time is respected."""
    now = timezone.localize(datetime(2020, 12, 31))
    assert schedule.get_next_run_time(now) is None
Пример #10
0
def test_start_time(schedule: CronSchedule, timezone: DstTzInfo):
    """Test that start_time is respected."""
    now = timezone.localize(datetime(2016, 1, 15))
    expected = timezone.localize(datetime(2016, 7, 20, 18, 5))
    assert schedule.get_next_run_time(now) == expected
Пример #11
0
def test_last_day_of_month(month: int, expected_day: int, timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, day='last')
    now = timezone.localize(datetime(2016, month, 1))
    expected = timezone.localize(datetime(2016, month, expected_day))
    assert schedule.get_next_run_time(now) == expected
def test_last_day_of_month(month: int, expected_day: int, timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, day='last')
    now = timezone.localize(datetime(2016, month, 1))
    expected = timezone.localize(datetime(2016, month, expected_day))
    assert schedule.get_next_run_time(now) == expected
def test_start_time(schedule: CronSchedule, timezone: DstTzInfo):
    """Test that start_time is respected."""
    now = timezone.localize(datetime(2016, 1, 15))
    expected = timezone.localize(datetime(2016, 7, 20, 18, 5))
    assert schedule.get_next_run_time(now) == expected
def test_end_time(schedule: CronSchedule, timezone: DstTzInfo):
    """Test that end_time is respected."""
    now = timezone.localize(datetime(2020, 12, 31))
    assert schedule.get_next_run_time(now) is None
Пример #15
0
def test_get_next_run_time(schedule: CronSchedule, previous_time, now, expected,
                           timezone: DstTzInfo):
    previous_time = convert_to_datetime(previous_time, timezone)
    now = convert_to_datetime(now, timezone)
    expected = convert_to_datetime(expected, timezone)
    assert schedule.get_next_run_time(now, previous_time) == expected
Пример #16
0
def test_dst_forward(timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, minute='*/5')
    previous_time = timezone.localize(datetime(2016, 3, 27, 1, 55))
    now = timezone.localize(datetime(2016, 3, 27, 1, 59))
    expected = timezone.localize(datetime(2016, 3, 27, 3))
    assert schedule.get_next_run_time(now, previous_time) == expected
def test_dst_forward(args: Dict[str, Any], now: datetime, expected: datetime,
                     timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, **args)
    now = timezone.localize(now)
    expected = timezone.localize(expected)
    assert schedule.get_next_run_time(now) == expected
Пример #18
0
def test_dst_backward(timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, minute='*/5')
    previous_time = timezone.localize(datetime(2016, 10, 30, 2, 55), is_dst=True)
    now = timezone.localize(datetime(2016, 10, 30, 2, 59), is_dst=True)
    expected = timezone.localize(datetime(2016, 10, 30, 2), is_dst=False)
    assert schedule.get_next_run_time(now, previous_time) == expected
def test_get_next_run_time(schedule: CronSchedule, 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
Пример #20
0
def test_month_rollover(timezone: DstTzInfo):
    """Test that if the maximum value in a field is reached, the previous field is incremented."""
    schedule = CronSchedule(task_id='task', timezone=timezone, day=30)
    now = timezone.localize(datetime(2016, 2, 1))
    expected = timezone.localize(datetime(2016, 3, 30))
    assert schedule.get_next_run_time(now) == expected
def test_month_rollover(timezone: DstTzInfo):
    """Test that if the maximum value in a field is reached, the previous field is incremented."""
    schedule = CronSchedule(task_id='task', timezone=timezone, day=30)
    now = timezone.localize(datetime(2016, 2, 1))
    expected = timezone.localize(datetime(2016, 3, 30))
    assert schedule.get_next_run_time(now) == expected
Пример #22
0
def test_weekday_position(month: int, expression: str, expected_day: int, timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, day=expression)
    now = timezone.localize(datetime(2016, month, 1))
    expected = timezone.localize(datetime(2016, month, expected_day))
    assert schedule.get_next_run_time(now) == expected
def test_weekday_position(month: int, expression: str, expected_day: int,
                          timezone: DstTzInfo):
    schedule = CronSchedule(task_id='task', timezone=timezone, day=expression)
    now = timezone.localize(datetime(2016, month, 1))
    expected = timezone.localize(datetime(2016, month, expected_day))
    assert schedule.get_next_run_time(now) == expected