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))
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))
def test_relative_stop_becomes_absolute(): e = ScheduleEntry(name='t', start=20, relative_stop=10, interval=1, action='logger') assert e.start == 20 assert e.stop == 30 assert list(e.get_remaining_times()) == list(range(20, 30, 1))
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))
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))
def test_stop_before_start(): e = ScheduleEntry(name='t', start=20, stop=10, interval=1, action='logger') assert list(e.get_remaining_times()) == list(range(0))
def test_undefined_stop_is_never(): entry = ScheduleEntry(name='t', action='logger', interval=1) assert entry.stop is None assert type(entry.get_remaining_times()) is itertools.count