def test_create_dates_clock_multiple_dates(self): now = pendulum.now("UTC") clock = clocks.DatesClock( dates=[now.add(days=1), now.add(days=2), now]) assert clock.start_date == now assert clock.end_date == now.add(days=2) assert clock.parameter_defaults == dict()
def test_dates_clock_sorted_events(self): dt = pendulum.now("UTC").add(days=1) clock = clocks.DatesClock(dates=[dt.add(days=1), dt.add(days=2), dt]) assert islice(clock.events(), 3) == [dt, dt.add(days=1), dt.add(days=2)]
def test_create_dates_clock_multiple_dates_with_labels(self): now = pendulum.now("UTC") clock = clocks.DatesClock( dates=[now.add(days=1), now.add(days=2), now], labels=["dev", "staging"]) assert clock.start_date == now assert clock.end_date == now.add(days=2) assert clock.parameter_defaults == dict() assert clock.labels == ["dev", "staging"]
def test_dates_clock_events_with_labels(self, labels): """Test that default after is *now*""" start_date = pendulum.today("UTC").add(days=1) c = clocks.DatesClock([start_date], labels=labels) output = islice(c.events(), 3) assert all(isinstance(e, clocks.ClockEvent) for e in output) assert all(e.labels == labels for e in output) assert output == [start_date] assert islice(c.events(), 1) == [start_date]
def test_create_schedule_multiple_overlapping_clocks_distinguishes_parameters( ): dt = pendulum.datetime(2019, 1, 1) special_day = pendulum.datetime(2020, 3, 1) s = schedules.Schedule(clocks=[ clocks.DatesClock([special_day]), clocks.DatesClock([special_day]), ]) output = s.next(2, after=dt, return_events=True) assert len(output) == 1 assert output[0].start_time == special_day s = schedules.Schedule(clocks=[ clocks.DatesClock([special_day], parameter_defaults=dict(a=1)), clocks.DatesClock([special_day], parameter_defaults=dict(a=2)), ]) output = s.next(2, after=dt, return_events=True) assert len(output) == 2 assert [e.start_time for e in output] == [special_day] * 2 assert set(e.parameter_defaults["a"] for e in output) == {1, 2}
def test_dates_clock_events(self, params): """Test that default after is *now*""" start_date = pendulum.today("UTC").add(days=1) c = clocks.DatesClock([start_date], parameter_defaults=params) output = islice(c.events(), 3) assert all([isinstance(e, clocks.ClockEvent) for e in output]) assert all([e.parameter_defaults == params for e in output]) assert output == [start_date] assert islice(c.events(), 1) == [start_date]
def test_serialize_schedule_with_dateclock(): dt = pendulum.datetime(2099, 1, 1) s = schedules.Schedule(clocks=[clocks.DatesClock(dates=[dt, dt.add(days=1)])]) s2 = serialize_and_deserialize(s) assert s2.next(2) == [dt, dt.add(days=1)]
def test_dates_clock_events_with_after_argument(self): dt = pendulum.today("UTC").add(days=1) c = clocks.DatesClock([dt]) assert islice(c.events(after=dt - timedelta(seconds=1)), 1) == [dt] assert islice(c.events(after=dt.add(days=-1)), 1) == [dt] assert islice(c.events(after=dt.add(days=1)), 1) == []
def test_start_date_must_be_provided(self): with pytest.raises(TypeError): clocks.DatesClock()
def test_create_dates_clock_one_date(self): now = pendulum.now("UTC") clock = clocks.DatesClock(dates=[now]) assert clock.start_date == clock.end_date == now assert clock.parameter_defaults == dict() assert clock.labels is None
def test_dates_clock_events(self): """Test that default after is *now*""" start_date = pendulum.today("UTC").add(days=1) c = clocks.DatesClock([start_date]) assert islice(c.events(), 3) == [start_date] assert islice(c.events(), 1) == [start_date]
def test_create_dates_clock_one_date(self): now = pendulum.now("UTC") clock = clocks.DatesClock(dates=[now]) assert clock.start_date == clock.end_date == now