72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
"""Checks on the real saints calendar and the lists that refer to it.
|
|
|
|
Unlike the other test files, these read the real saints_days_france.csv,
|
|
so they catch typos that would make a saint silently never be posted.
|
|
They check properties of every row, never row counts, so they keep passing
|
|
as the calendar grows.
|
|
"""
|
|
|
|
import csv
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
import download_saint_pictures
|
|
import get_saint_of_the_day
|
|
|
|
CSV_PATH = Path(__file__).parent.parent / "saints_days_france.csv"
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def calendar_rows():
|
|
with open(CSV_PATH, encoding="utf-8") as f:
|
|
return list(csv.DictReader(f))
|
|
|
|
|
|
def is_real_day(date_text):
|
|
"""True for dates like "January 22". 2024 is a leap year, so
|
|
"February 29" counts as real."""
|
|
try:
|
|
datetime.strptime(f"{date_text} 2024", "%B %d %Y")
|
|
except ValueError:
|
|
return False
|
|
return True
|
|
|
|
|
|
def test_every_date_in_calendar_is_a_real_day(calendar_rows):
|
|
# A typo like "Febuary 3" or "April 31" would never match today's date.
|
|
bad_dates = [row["Date"] for row in calendar_rows if not is_real_day(row["Date"])]
|
|
|
|
assert bad_dates == []
|
|
|
|
|
|
def test_every_calendar_row_has_a_saint_name(calendar_rows):
|
|
blank_rows = [row for row in calendar_rows if not row["Saint Name"].strip()]
|
|
|
|
assert blank_rows == []
|
|
|
|
|
|
def test_every_feast_day_entry_matches_a_calendar_name(calendar_rows):
|
|
# A misspelled entry here means the real feast day is posted as
|
|
# "the Feast of Saint Epiphany".
|
|
calendar_names = {row["Saint Name"] for row in calendar_rows}
|
|
|
|
assert get_saint_of_the_day.NON_PERSON_ENTRIES - calendar_names == set()
|
|
|
|
|
|
def test_both_scripts_agree_on_which_entries_are_feast_days():
|
|
assert (
|
|
download_saint_pictures.NON_PERSON_ENTRIES
|
|
== get_saint_of_the_day.NON_PERSON_ENTRIES
|
|
)
|
|
|
|
|
|
def test_every_alternate_title_is_for_a_saint_in_the_calendar(calendar_rows):
|
|
# A misspelled key means its alternate titles are never tried.
|
|
calendar_names = {row["Saint Name"] for row in calendar_rows}
|
|
|
|
unknown = set(download_saint_pictures.ALTERNATE_TITLES) - calendar_names
|
|
|
|
assert unknown == set()
|