"""Tests for daily.holiday.""" from __future__ import annotations import unittest from datetime import date from daily.holiday import is_workday, workday_name # 模拟 2026 节假日表:1/1 元旦(休),1/4 元旦调休(补班) HOLIDAYS = { "2026-01-01": {"rest": True, "name": "元旦节"}, "2026-01-02": {"rest": True, "name": "元旦节"}, "2026-01-03": {"rest": True, "name": "元旦节"}, "2026-01-04": {"rest": False, "name": "元旦节调休"}, "2026-02-16": {"rest": True, "name": "春节"}, "2026-02-14": {"rest": False, "name": "春节调休"}, } class IsWorkdayTests(unittest.TestCase): def test_legal_holiday_is_rest(self): # 2026-01-01 周四,元旦 → 休息 self.assertFalse(is_workday(date(2026, 1, 1), HOLIDAYS)) def test_tiaoxiu_makeup_day_is_workday(self): # 2026-01-04 周日,调休补班 → 上班 self.assertEqual(date(2026, 1, 4).weekday(), 6) self.assertTrue(is_workday(date(2026, 1, 4), HOLIDAYS)) def test_spring_festival_holiday(self): self.assertFalse(is_workday(date(2026, 2, 16), HOLIDAYS)) def test_spring_festival_makeup_saturday(self): # 2026-02-14 周六,调休 → 上班 self.assertEqual(date(2026, 2, 14).weekday(), 5) self.assertTrue(is_workday(date(2026, 2, 14), HOLIDAYS)) def test_normal_weekday(self): # 2026-07-23 周四,非节假日 → 上班 self.assertTrue(is_workday(date(2026, 7, 23), HOLIDAYS)) def test_normal_weekend(self): # 2026-07-25 周六,非节假日 → 休息 self.assertFalse(is_workday(date(2026, 7, 25), HOLIDAYS)) class WorkdayNameTests(unittest.TestCase): def test_holiday_name(self): self.assertEqual(workday_name(date(2026, 1, 1), HOLIDAYS), "元旦节") def test_normal_day_has_no_name(self): self.assertIsNone(workday_name(date(2026, 7, 23), HOLIDAYS)) if __name__ == "__main__": unittest.main()