Skip to content

Commit

Permalink
Merge pull request #3494 from PrefectHQ/label-update
Browse files Browse the repository at this point in the history
Allow for None as labels attribute of clocks
  • Loading branch information
cicdw authored Oct 13, 2020
2 parents 4d1b521 + d370d9b commit a78e025
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/prefect/schedules/clocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
) -> None:
self.start_time = start_time
self.parameter_defaults = parameter_defaults or dict()
self.labels = labels or []
self.labels = labels

def __eq__(self, other: Any) -> bool:
if not isinstance(other, (ClockEvent, datetime)):
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(
self.start_date = start_date
self.end_date = end_date
self.parameter_defaults = parameter_defaults or dict()
self.labels = labels or []
self.labels = labels

def events(self, after: datetime = None) -> Iterable[ClockEvent]:
"""
Expand Down
16 changes: 8 additions & 8 deletions tests/schedules/test_clocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def test_clock_event_requires_start_time(self):

assert e.start_time == now
assert e.parameter_defaults == dict()
assert e.labels == []
assert e.labels is None

def test_clock_event_accepts_parameters(self):
now = pendulum.now("UTC")
e = clocks.ClockEvent(now, parameter_defaults=dict(x=42, z=[1, 2, 3]))

assert e.start_time == now
assert e.parameter_defaults == dict(x=42, z=[1, 2, 3])
assert e.labels == []
assert e.labels is None

def test_clock_event_accepts_labels(self):
now = pendulum.now("UTC")
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_create_interval_clock(self):
start_date=pendulum.now("UTC"), interval=timedelta(days=1)
)
assert c.parameter_defaults == dict()
assert c.labels == []
assert c.labels is None

def test_create_interval_clock_with_parameters(self):
c = clocks.IntervalClock(
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_start_date_can_be_none(self):
assert c.interval == timedelta(hours=1)
assert c.end_date is None
assert c.parameter_defaults == dict()
assert c.labels == []
assert c.labels is None

def test_end_date(self):
c = clocks.IntervalClock(
Expand All @@ -155,7 +155,7 @@ def test_end_date(self):
assert c.interval == timedelta(hours=1)
assert c.end_date == pendulum.datetime(2020, 1, 1)
assert c.parameter_defaults == dict()
assert c.labels == []
assert c.labels is None

def test_interval_clock_interval_must_be_positive(self):
with pytest.raises(ValueError, match="greater than 0"):
Expand Down Expand Up @@ -384,7 +384,7 @@ class TestCronClock:
def test_create_cron_clock(self):
c = clocks.CronClock("* * * * *")
assert c.parameter_defaults == dict()
assert c.labels == []
assert c.labels is None

def test_create_cron_clock_with_parameters(self):
c = clocks.CronClock("* * * * *", parameter_defaults=dict(x=42))
Expand Down Expand Up @@ -625,15 +625,15 @@ def test_create_dates_clock_one_date(self):
clock = clocks.DatesClock(dates=[now])
assert clock.start_date == clock.end_date == now
assert clock.parameter_defaults == dict()
assert clock.labels == []
assert clock.labels is None

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()
assert clock.labels == []
assert clock.labels is None

def test_create_dates_clock_multiple_dates_with_parameters(self):
now = pendulum.now("UTC")
Expand Down
1 change: 1 addition & 0 deletions tests/serialization/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_serialize_schedule_with_parameters():

output = s2.next(3, after=dt, return_events=True)

assert all([e.labels is None for e in output])
assert all([isinstance(e, clocks.ClockEvent) for e in output])


Expand Down

0 comments on commit a78e025

Please sign in to comment.