Skip to content

Commit

Permalink
Add the empty timetable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avkirilishin committed Dec 8, 2023
1 parent 474e485 commit 29d02c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions airflow/timetables/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ def __init__(
self.event_dates.sort()
self.restrict_to_events = restrict_to_events
if description is None:
self.description = (
f"{len(self.event_dates)} Events between {self.event_dates[0]} and {self.event_dates[-1]}"
)
self._summary = f"{len(self.event_dates)} Events"
if self.event_dates:
self.description = (
f"{len(self.event_dates)} events between {self.event_dates[0]} and {self.event_dates[-1]}"
)
else:
self.description = "No events"
self._summary = f"{len(self.event_dates)} events"
else:
self._summary = description
self.description = description
Expand Down Expand Up @@ -106,7 +109,7 @@ def next_dagrun_info(

def infer_manual_data_interval(self, *, run_after: DateTime) -> DataInterval:
# If Timetable not restricted to events, run for the time specified
if not self.restrict_to_events:
if not self.restrict_to_events or not self.event_dates:
return DataInterval.exact(run_after)

# If restricted to events, run for the most recent past event
Expand Down
15 changes: 15 additions & 0 deletions tests/timetables/test_events_timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,18 @@ def test_no_catchup_first_starts(
restriction=TimeRestriction(earliest=START_DATE, latest=None, catchup=False),
)
assert next_info == expected_info


def test_empty_timetable() -> None:
empty_timetable = EventsTimetable(event_dates=[])
next_info = empty_timetable.next_dagrun_info(
last_automated_data_interval=None,
restriction=TimeRestriction(earliest=START_DATE, latest=None, catchup=False),
)
assert next_info is None


def test_empty_timetable_manual_run() -> None:
empty_timetable = EventsTimetable(event_dates=[])
manual_run_data_interval = empty_timetable.infer_manual_data_interval(run_after=START_DATE)
assert manual_run_data_interval == DataInterval(start=START_DATE, end=START_DATE)

0 comments on commit 29d02c5

Please sign in to comment.