100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
from datetime import date
|
|
|
|
from backfill_summaries import has_missing_report_tag, missing_message_dates
|
|
|
|
|
|
def test_backfill_skips_empty_days_and_existing_nonempty_summaries(tmp_path):
|
|
messages = {date(2024, 6, 2), date(2024, 6, 3), date(2024, 6, 4)}
|
|
existing = tmp_path / "2024-06-03.md"
|
|
existing.write_text("已有日报", encoding="utf-8")
|
|
empty = tmp_path / "2024-06-04.md"
|
|
empty.touch()
|
|
|
|
days = list(missing_message_dates(
|
|
date(2024, 6, 1),
|
|
date(2024, 6, 5),
|
|
lambda day: day in messages,
|
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
|
))
|
|
|
|
assert days == [date(2024, 6, 2), date(2024, 6, 4)]
|
|
|
|
|
|
def test_backfill_overwrite_still_skips_days_without_messages(tmp_path):
|
|
output = tmp_path / "2024-06-02.md"
|
|
output.write_text("旧日报", encoding="utf-8")
|
|
|
|
days = list(missing_message_dates(
|
|
date(2024, 6, 2),
|
|
date(2024, 6, 2),
|
|
lambda day: True,
|
|
lambda day: output,
|
|
overwrite=True,
|
|
))
|
|
|
|
assert days == [date(2024, 6, 2)]
|
|
|
|
|
|
def test_backfill_refreshes_only_tagged_reports_from_requested_date(tmp_path):
|
|
tagged = tmp_path / "2024-11-27.md"
|
|
tagged.write_text(
|
|
"---\ntags:\n- no_previous_weekly\n---\n旧日报", encoding="utf-8"
|
|
)
|
|
later = tmp_path / "2024-11-28.md"
|
|
later.write_text("---\ntags:\n- no_previous_monthly\n---\n旧日报", encoding="utf-8")
|
|
ordinary = tmp_path / "2024-11-29.md"
|
|
ordinary.write_text("已有日报", encoding="utf-8")
|
|
|
|
days = list(missing_message_dates(
|
|
date(2024, 11, 27),
|
|
date(2024, 11, 29),
|
|
lambda day: True,
|
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
|
refresh_tagged_from=date(2024, 11, 28),
|
|
))
|
|
|
|
assert days == [date(2024, 11, 28)]
|
|
assert has_missing_report_tag(tagged)
|
|
assert has_missing_report_tag(later)
|
|
assert not has_missing_report_tag(ordinary)
|
|
|
|
|
|
def test_backfill_force_refreshes_all_daily_notes_from_requested_date(tmp_path):
|
|
before = tmp_path / "2026-10-07.md"
|
|
before.write_text("保留日报", encoding="utf-8")
|
|
first = tmp_path / "2026-10-08.md"
|
|
first.write_text("旧日报", encoding="utf-8")
|
|
second = tmp_path / "2026-10-09.md"
|
|
second.write_text("旧日报", encoding="utf-8")
|
|
|
|
days = list(missing_message_dates(
|
|
date(2026, 10, 7),
|
|
date(2026, 10, 9),
|
|
lambda day: True,
|
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
|
daily_overwrite_from=date(2026, 10, 8),
|
|
))
|
|
|
|
assert days == [date(2026, 10, 8), date(2026, 10, 9)]
|
|
|
|
|
|
def test_backfill_does_not_probe_days_that_do_not_need_regeneration(tmp_path):
|
|
probes = []
|
|
|
|
def has_messages(day):
|
|
probes.append(day)
|
|
return True
|
|
|
|
for day in (date(2026, 2, 17), date(2026, 2, 18)):
|
|
(tmp_path / f"{day.isoformat()}.md").write_text("已有日报", encoding="utf-8")
|
|
|
|
days = list(missing_message_dates(
|
|
date(2026, 2, 17),
|
|
date(2026, 2, 18),
|
|
has_messages,
|
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
|
))
|
|
|
|
assert days == []
|
|
assert probes == [] # 已存在且无需重生成的日子不应触发拉取判断
|