Пример #1
0
def test_no_interval_with_start_is_one_shot():
    """Specifying start should not affect number of times."""
    e = ScheduleEntry(name='t', action='logger', start=1)
    remaining_times = list(e.get_remaining_times())
    assert len(remaining_times) == 1

    times = list(e.take_until(remaining_times[0] + 1000))
    assert len(times) == 1

    # when interval is None, consuming the single task time unsets `active`
    assert not e.is_active
    assert not list(e.get_remaining_times())
    assert not list(e.take_until(remaining_times[0] + 1000))
Пример #2
0
def test_no_interval_is_one_shot():
    """Leaving `interval` blank should indicate "one-shot" entry."""
    e = ScheduleEntry(name='t', action='logger')
    remaining_times = list(e.get_remaining_times())
    assert len(remaining_times) == 1

    times = list(e.take_until(remaining_times[0] + 1000))
    assert len(times) == 1

    # when interval is None, consuming the single task time unsets `active`
    assert not e.is_active
    assert not list(e.get_remaining_times())
    assert not list(e.take_until(remaining_times[0] + 1000))
Пример #3
0
def test_take_until(test_input, future_t, expected):
    start, stop, interval = test_input
    entry = ScheduleEntry(name='t', start=start, stop=stop, interval=interval,
                          action='logger')
    initial_times = list(entry.get_remaining_times())
    r = []
    for t in count(future_t, future_t):
        ts = list(entry.take_until(t))
        if not ts:
            break
        r.append(ts)

    assert r == expected
    assert initial_times == list(flatten(r))
Пример #4
0
def test_no_interval():
    e1 = ScheduleEntry(name='t', action='logger')
    remaining_times = list(e1.get_remaining_times())
    assert len(remaining_times) == 1

    times = list(e1.take_until(remaining_times[0] + 1000))
    assert len(times) == 1

    # when interval is None, consuming the single task time unsets `active`
    assert not e1.is_active
    assert not list(e1.get_remaining_times())
    assert not list(e1.take_until(remaining_times[0] + 1000))

    e2 = ScheduleEntry(name='t', action='logger', start=1)
    remaining_times = list(e2.get_remaining_times())
    assert len(remaining_times) == 1

    times = list(e2.take_until(remaining_times[0] + 1000))
    assert len(times) == 1

    # when interval is None, consuming the single task time unsets `active`
    assert not e2.is_active
    assert not list(e2.get_remaining_times())
    assert not list(e2.take_until(remaining_times[0] + 1000))