65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
from datetime import date
|
|
|
|
from schedule import is_rest_day, select_column
|
|
from timetable import KIND_REST_DAY, KIND_SPECIAL, KIND_WORKDAY, Column
|
|
|
|
|
|
def col(kind, valid_from, dates=()):
|
|
return Column(label=f"{kind} {valid_from}", kind=kind, valid_from=valid_from, dates=tuple(dates), departures=())
|
|
|
|
|
|
WORK_OLD = col(KIND_WORKDAY, date(2026, 3, 1))
|
|
WORK_NEW = col(KIND_WORKDAY, date(2026, 10, 1))
|
|
REST = col(KIND_REST_DAY, date(2026, 10, 3))
|
|
SPECIAL = col(
|
|
KIND_SPECIAL, date(2026, 10, 29), [date(2026, 10, 29), date(2026, 10, 30), date(2026, 12, 23)]
|
|
)
|
|
|
|
|
|
def test_is_rest_day(cz):
|
|
assert not is_rest_day(date(2026, 10, 6), cz) # Tuesday
|
|
assert is_rest_day(date(2026, 10, 10), cz) # Saturday
|
|
assert is_rest_day(date(2026, 10, 11), cz) # Sunday
|
|
assert is_rest_day(date(2026, 10, 28), cz) # Wednesday, Statehood Day
|
|
assert is_rest_day(date(2026, 12, 24), cz) # Thursday, Christmas Eve
|
|
|
|
|
|
def test_workday_uses_workday_column():
|
|
assert select_column([WORK_NEW, REST], date(2026, 10, 6), rest_day=False) is WORK_NEW
|
|
|
|
|
|
def test_rest_day_uses_rest_column():
|
|
assert select_column([WORK_NEW, REST], date(2026, 10, 10), rest_day=True) is REST
|
|
|
|
|
|
def test_latest_started_column_of_a_kind_wins():
|
|
assert select_column([WORK_OLD, WORK_NEW], date(2026, 10, 6), rest_day=False) is WORK_NEW
|
|
assert select_column([WORK_OLD, WORK_NEW], date(2026, 9, 15), rest_day=False) is WORK_OLD
|
|
|
|
|
|
def test_column_not_valid_yet_is_used_when_nothing_else_exists():
|
|
assert select_column([WORK_NEW], date(2026, 9, 1), rest_day=False) is WORK_NEW
|
|
assert select_column([WORK_NEW, REST], date(2026, 9, 27), rest_day=True) is REST
|
|
|
|
|
|
def test_special_date_replaces_workday_column():
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=False) is SPECIAL
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 12, 23), rest_day=False) is SPECIAL
|
|
|
|
|
|
def test_special_column_ignored_on_other_days():
|
|
# 28.10. is a holiday right before the special dates: must use the rest column.
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 28), rest_day=True) is REST
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 31), rest_day=True) is REST
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 11, 2), rest_day=False) is WORK_NEW
|
|
|
|
|
|
def test_special_date_beats_rest_day():
|
|
# Default precedence (your call to change): a special date wins even on a rest day.
|
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=True) is SPECIAL
|
|
|
|
|
|
def test_no_column_of_the_needed_kind_returns_none():
|
|
assert select_column([WORK_NEW], date(2026, 10, 10), rest_day=True) is None
|
|
assert select_column([], date(2026, 10, 6), rest_day=False) is None
|