def test_next_n_with_no_next(self): start_date = pendulum.datetime(2018, 1, 1) now = pendulum.now("UTC") s = schedules.IntervalSchedule(start_date, timedelta(days=1)) t = schedules.OneTimeSchedule(start_date=now.add(hours=-1)) main = schedules.UnionSchedule([s, t]) assert main.next(2) == s.next(2)
def test_next_n(self): start_date = pendulum.datetime(2018, 1, 1) now = pendulum.now("UTC") s = schedules.IntervalSchedule(start_date, timedelta(days=1)) t = schedules.OneTimeSchedule(start_date=s.next(1)[0].add(minutes=-1)) main = schedules.UnionSchedule([s, t]) assert main.next(2) == [t.next(1)[0], s.next(1)[0]]
def test_serialize_union_schedule(cron_schedule, interval_schedule): schedule = schedules.UnionSchedule([cron_schedule, interval_schedule]) schema = schemas.UnionScheduleSchema() serialized = schema.dump(schedule) assert serialized["schedules"] == [ cron_schedule.serialize(), interval_schedule.serialize(), ]
def test_roundtrip_serialization_of_union_schedule(cron_schedule, interval_schedule): schedule = schedules.UnionSchedule([cron_schedule, interval_schedule]) schema = schemas.UnionScheduleSchema() new = schema.load(schema.dump(schedule)) assert isinstance(new, schedules.UnionSchedule) assert len(new.schedules) == 2 assert [type(s) for s in new.schedules] == [type(s) for s in schedule.schedules]
def test_next_n_with_different_timezones(self): east = schedules.CronSchedule("0 9 * * 1-5", start_date=pendulum.parse( "2019-03-14", tz="US/Eastern")) west = schedules.CronSchedule("30 6 * * 1-5", start_date=pendulum.parse( "2019-03-14", tz="US/Pacific")) main = schedules.UnionSchedule([east, west]) ## have to do some additional work so this test passes ## regardless of what time it is now = pendulum.now("US/Pacific") after = east.next(1, after=now)[0] + pendulum.duration(minutes=-1) expected = [ east.next(1, after=after)[0], west.next(1, after=after)[0], east.next(2, after=after)[1], west.next(2, after=after)[1], ] assert main.next(4, after=after) == expected
def test_next_n_with_repeated_schedule_values(self): start_date = pendulum.datetime(2018, 1, 1) now = pendulum.now("UTC") s = schedules.IntervalSchedule(start_date, timedelta(days=1)) main = schedules.UnionSchedule([s, s, s, s]) assert main.next(3) == s.next(3)
def test_initialization_with_schedules(self, list_of_schedules): s = schedules.UnionSchedule(list_of_schedules) assert s.start_date == pendulum.datetime(2000, 1, 1) assert s.end_date == pendulum.datetime(2017, 1, 1)
def test_initialization(self): s = schedules.UnionSchedule() assert s.start_date is None assert s.end_date is None