Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b935756697 | ||
|
|
eb4922c8a9 | ||
|
|
0814551cfd | ||
|
|
19400f1fd5 | ||
|
|
43f13a2311 | ||
|
|
7ca2394312 | ||
|
|
83da0011fa | ||
|
|
d51b3bc5eb | ||
|
|
c27846229e | ||
|
|
51b0094395 |
No files matched your search
@@ -11,3 +11,6 @@ wheels/
|
|||||||
|
|
||||||
# env
|
# env
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# pytest
|
||||||
|
.pytest_cache/
|
||||||
@@ -113,7 +113,7 @@ def get_saints_for_today() -> list[dict]:
|
|||||||
def format_mastodon_post(saint: dict) -> str:
|
def format_mastodon_post(saint: dict) -> str:
|
||||||
"""Format a saint's information as a Mastodon post."""
|
"""Format a saint's information as a Mastodon post."""
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
date_str = today.strftime("%B %d")
|
date_str = today.strftime("%B %-d")
|
||||||
|
|
||||||
lines = [
|
lines = [
|
||||||
f"{date_str}: the Feast of Saint {saint['name']}",
|
f"{date_str}: the Feast of Saint {saint['name']}",
|
||||||
@@ -195,7 +195,6 @@ def main():
|
|||||||
print("No saint's day today (or today is a holiday/feast day).")
|
print("No saint's day today (or today is a holiday/feast day).")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
for saint in saints:
|
for saint in saints:
|
||||||
print(f"Saint: {saint['name']}")
|
print(f"Saint: {saint['name']}")
|
||||||
print(f"French: {saint['french_name']}")
|
print(f"French: {saint['french_name']}")
|
||||||
|
|||||||
@@ -10,3 +10,13 @@ dependencies = [
|
|||||||
"python-dotenv>=1.2.1",
|
"python-dotenv>=1.2.1",
|
||||||
"requests>=2.32.5",
|
"requests>=2.32.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pytest>=9.2.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
pythonpath = ["."]
|
||||||
|
addopts = "-v --tb=short"
|
||||||
@@ -0,0 +1,364 @@
|
|||||||
|
"""Tests for download_saint_pictures.py.
|
||||||
|
|
||||||
|
No test here touches the network or the real pics/ folder. Wikipedia is
|
||||||
|
replaced by FakeWikipedia, which answers the same API queries with the same
|
||||||
|
JSON shapes the real one returns, and the script's files are moved into a
|
||||||
|
temporary folder.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import download_saint_pictures as downloader
|
||||||
|
|
||||||
|
CSV_HEADER = "Date,Saint Name,French Name,Notes\n"
|
||||||
|
API_URL = "https://en.wikipedia.org/w/api.php"
|
||||||
|
COMMONS = "https://upload.wikimedia.org/wikipedia/commons"
|
||||||
|
|
||||||
|
|
||||||
|
# --- Fake Wikipedia --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class FakeResponse:
|
||||||
|
def __init__(self, status_code, json_data=None, content=b""):
|
||||||
|
self.status_code = status_code
|
||||||
|
self._json_data = json_data
|
||||||
|
self.content = content
|
||||||
|
|
||||||
|
def raise_for_status(self):
|
||||||
|
if self.status_code >= 400:
|
||||||
|
raise requests.HTTPError(f"{self.status_code} Client Error")
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return self._json_data
|
||||||
|
|
||||||
|
|
||||||
|
class FakeWikipedia:
|
||||||
|
"""Stands in for the Wikipedia API and the Wikimedia image server.
|
||||||
|
|
||||||
|
Tests describe the pages that exist with add_page(). Like the real
|
||||||
|
servers, it refuses requests without a descriptive User-Agent, reports
|
||||||
|
unknown pages as missing, and only returns a resized 'thumburl' when the
|
||||||
|
request asks for a width.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.page_images = {} # article title -> image file name
|
||||||
|
self.image_info = {} # image file name -> imageinfo dict
|
||||||
|
self.image_bytes = {} # image URL -> file contents
|
||||||
|
self.titles_requested = []
|
||||||
|
self.unreachable = False
|
||||||
|
|
||||||
|
def add_page(self, title, image_name=None, thumb_url=None, original_url=None):
|
||||||
|
self.page_images[title] = image_name
|
||||||
|
if image_name:
|
||||||
|
info = {"url": original_url, "descriptionurl": f"{COMMONS}/{image_name}"}
|
||||||
|
if thumb_url:
|
||||||
|
info |= {"thumburl": thumb_url, "thumbwidth": 500}
|
||||||
|
self.image_info[image_name] = info
|
||||||
|
self.image_bytes[thumb_url or original_url] = f"<{image_name}>".encode()
|
||||||
|
|
||||||
|
def get(self, session, url, params=None, headers=None, timeout=None):
|
||||||
|
if self.unreachable:
|
||||||
|
raise requests.ConnectionError("Failed to establish a new connection")
|
||||||
|
if not session.headers.get("User-Agent", "").startswith(
|
||||||
|
"SaintsPictureDownloader/"
|
||||||
|
):
|
||||||
|
return FakeResponse(403)
|
||||||
|
if url == API_URL and params["prop"] == "pageimages":
|
||||||
|
return FakeResponse(200, self._page_query(params["titles"]))
|
||||||
|
if url == API_URL and params["prop"] == "imageinfo":
|
||||||
|
return FakeResponse(200, self._file_query(params))
|
||||||
|
if url in self.image_bytes:
|
||||||
|
return FakeResponse(200, content=self.image_bytes[url])
|
||||||
|
return FakeResponse(404)
|
||||||
|
|
||||||
|
def _page_query(self, title):
|
||||||
|
self.titles_requested.append(title)
|
||||||
|
if title not in self.page_images:
|
||||||
|
return {
|
||||||
|
"query": {"pages": {"-1": {"ns": 0, "title": title, "missing": ""}}}
|
||||||
|
}
|
||||||
|
page = {"pageid": 4242, "ns": 0, "title": title}
|
||||||
|
if self.page_images[title]:
|
||||||
|
page["pageimage"] = self.page_images[title]
|
||||||
|
return {"batchcomplete": "", "query": {"pages": {"4242": page}}}
|
||||||
|
|
||||||
|
def _file_query(self, params):
|
||||||
|
image_name = params["titles"].removeprefix("File:")
|
||||||
|
info = dict(self.image_info[image_name])
|
||||||
|
if "iiurlwidth" not in params:
|
||||||
|
info.pop("thumburl", None)
|
||||||
|
info.pop("thumbwidth", None)
|
||||||
|
# Commons files show as "missing" (-1) from English Wikipedia.
|
||||||
|
page = {
|
||||||
|
"ns": 6,
|
||||||
|
"title": params["titles"],
|
||||||
|
"missing": "",
|
||||||
|
"known": "",
|
||||||
|
"imagerepository": "shared",
|
||||||
|
"imageinfo": [info],
|
||||||
|
}
|
||||||
|
return {"query": {"pages": {"-1": page}}}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def wikipedia(monkeypatch):
|
||||||
|
"""Route every requests.Session.get call to a FakeWikipedia."""
|
||||||
|
wiki = FakeWikipedia()
|
||||||
|
|
||||||
|
def fake_get(session, url, **kwargs):
|
||||||
|
return wiki.get(session, url, **kwargs)
|
||||||
|
|
||||||
|
monkeypatch.setattr(requests.Session, "get", fake_get)
|
||||||
|
return wiki
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def project_dir(tmp_path, monkeypatch):
|
||||||
|
"""Make the script read its CSV and write pics/ inside tmp_path."""
|
||||||
|
monkeypatch.setattr(
|
||||||
|
downloader, "__file__", str(tmp_path / "download_saint_pictures.py")
|
||||||
|
)
|
||||||
|
(tmp_path / "pics").mkdir()
|
||||||
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def no_waiting(monkeypatch):
|
||||||
|
"""Skip the polite pauses between requests so tests run instantly."""
|
||||||
|
monkeypatch.setattr(downloader.time, "sleep", lambda seconds: None)
|
||||||
|
|
||||||
|
|
||||||
|
def write_csv(project_dir, rows):
|
||||||
|
(project_dir / "saints_days_france.csv").write_text(
|
||||||
|
CSV_HEADER + "".join(row + "\n" for row in rows), encoding="utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def thumb(name):
|
||||||
|
return f"{COMMONS}/thumb/a/ab/{name}/500px-{name}"
|
||||||
|
|
||||||
|
|
||||||
|
# --- get_all_saints --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_all_saints_are_unique_sorted_and_exclude_feast_days(project_dir):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 21,Agnes,Sainte Agnès,",
|
||||||
|
"January 6,Epiphany,Épiphanie,Solemnity",
|
||||||
|
"January 20,Sebastian,Saint Sébastien,",
|
||||||
|
"January 20,Fabian,Saint Fabien,",
|
||||||
|
"December 21,Agnes,Sainte Agnès,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert downloader.get_all_saints() == ["Agnes", "Fabian", "Sebastian"]
|
||||||
|
|
||||||
|
|
||||||
|
# --- get_wikipedia_image_url -----------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_is_500px_thumbnail_of_page_image(wikipedia):
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Agnes of Rome",
|
||||||
|
image_name="Saint_Agnes.jpg",
|
||||||
|
thumb_url=thumb("Saint_Agnes.jpg"),
|
||||||
|
original_url=f"{COMMONS}/a/ab/Saint_Agnes.jpg",
|
||||||
|
)
|
||||||
|
|
||||||
|
image_url = downloader.get_wikipedia_image_url(
|
||||||
|
downloader.create_session(), "Agnes of Rome"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert image_url == f"{COMMONS}/thumb/a/ab/Saint_Agnes.jpg/500px-Saint_Agnes.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_falls_back_to_original_when_no_thumbnail(wikipedia):
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Bede",
|
||||||
|
image_name="Bede.jpg",
|
||||||
|
original_url=f"{COMMONS}/b/bb/Bede.jpg",
|
||||||
|
)
|
||||||
|
|
||||||
|
image_url = downloader.get_wikipedia_image_url(downloader.create_session(), "Bede")
|
||||||
|
|
||||||
|
assert image_url == f"{COMMONS}/b/bb/Bede.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_is_none_when_page_does_not_exist(wikipedia):
|
||||||
|
image_url = downloader.get_wikipedia_image_url(
|
||||||
|
downloader.create_session(), "No Such Saint"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert image_url is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_is_none_when_page_has_no_image(wikipedia):
|
||||||
|
wikipedia.add_page("Agnes") # e.g. a disambiguation page
|
||||||
|
|
||||||
|
image_url = downloader.get_wikipedia_image_url(downloader.create_session(), "Agnes")
|
||||||
|
|
||||||
|
assert image_url is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_is_none_when_wikipedia_is_unreachable(wikipedia, capsys):
|
||||||
|
wikipedia.unreachable = True
|
||||||
|
|
||||||
|
image_url = downloader.get_wikipedia_image_url(downloader.create_session(), "Bede")
|
||||||
|
|
||||||
|
assert image_url is None
|
||||||
|
assert "Error fetching Wikipedia API" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_url_is_none_when_wikipedia_refuses_request(wikipedia):
|
||||||
|
# A plain session has no User-Agent, so the fake refuses it with a 403.
|
||||||
|
image_url = downloader.get_wikipedia_image_url(requests.Session(), "Bede")
|
||||||
|
|
||||||
|
assert image_url is None
|
||||||
|
|
||||||
|
|
||||||
|
# --- download_image --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_saves_image_bytes_to_file(wikipedia, tmp_path):
|
||||||
|
wikipedia.add_page("Bede", image_name="Bede.jpg", thumb_url=thumb("Bede.jpg"))
|
||||||
|
filepath = tmp_path / "Bede.jpg"
|
||||||
|
|
||||||
|
saved = downloader.download_image(
|
||||||
|
downloader.create_session(), thumb("Bede.jpg"), filepath
|
||||||
|
)
|
||||||
|
|
||||||
|
assert saved is True
|
||||||
|
assert filepath.read_bytes() == b"<Bede.jpg>"
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_writes_nothing_when_image_is_missing(wikipedia, tmp_path, capsys):
|
||||||
|
filepath = tmp_path / "Bede.jpg"
|
||||||
|
|
||||||
|
saved = downloader.download_image(
|
||||||
|
downloader.create_session(), thumb("Gone.jpg"), filepath
|
||||||
|
)
|
||||||
|
|
||||||
|
assert saved is False
|
||||||
|
assert not filepath.exists()
|
||||||
|
assert "Error downloading image: 404" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
# --- main (running the script) ---------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_saves_each_saints_picture_named_after_saint(
|
||||||
|
project_dir, wikipedia, no_waiting
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 13,Hilary of Poitiers,Saint Hilaire,"])
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Hilary of Poitiers", image_name="Hilary.jpg", thumb_url=thumb("Hilary.jpg")
|
||||||
|
)
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
picture = project_dir / "pics" / "Hilary_of_Poitiers.jpg"
|
||||||
|
assert picture.read_bytes() == b"<Hilary.jpg>"
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_skips_saints_that_already_have_a_picture(
|
||||||
|
project_dir, wikipedia, no_waiting
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 13,Hilary of Poitiers,Saint Hilaire,"])
|
||||||
|
(project_dir / "pics" / "Hilary_of_Poitiers.png").write_bytes(b"my own picture")
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
assert wikipedia.titles_requested == []
|
||||||
|
assert (project_dir / "pics" / "Hilary_of_Poitiers.png").read_bytes() == (
|
||||||
|
b"my own picture"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_tries_alternate_titles_and_stops_at_first_with_image(
|
||||||
|
project_dir, wikipedia, no_waiting, monkeypatch
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["June 29,Peter and Paul,Saints Pierre et Paul,"])
|
||||||
|
monkeypatch.setattr(
|
||||||
|
downloader,
|
||||||
|
"ALTERNATE_TITLES",
|
||||||
|
{"Peter and Paul": ["Saint Peter", "Paul the Apostle"]},
|
||||||
|
)
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Saint Peter", image_name="Peter.jpg", thumb_url=thumb("Peter.jpg")
|
||||||
|
)
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Paul the Apostle", image_name="Paul.jpg", thumb_url=thumb("Paul.jpg")
|
||||||
|
)
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
assert wikipedia.titles_requested == ["Peter and Paul", "Saint Peter"]
|
||||||
|
picture = project_dir / "pics" / "Peter_and_Paul.jpg"
|
||||||
|
assert picture.read_bytes() == b"<Peter.jpg>"
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_reports_saint_with_no_image_anywhere(
|
||||||
|
project_dir, wikipedia, no_waiting, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["November 23,Clement I,Saint Clément Ier,"])
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
assert list((project_dir / "pics").iterdir()) == []
|
||||||
|
assert " No image found on Wikipedia\n" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_summary_counts_downloaded_skipped_and_failed(
|
||||||
|
project_dir, wikipedia, no_waiting, capsys
|
||||||
|
):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 13,Hilary of Poitiers,Saint Hilaire,",
|
||||||
|
"January 20,Fabian,Saint Fabien,",
|
||||||
|
"January 21,Agnes,Sainte Agnès,",
|
||||||
|
"November 23,Clement I,Saint Clément Ier,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
(project_dir / "pics" / "Agnes.jpg").write_bytes(b"already here")
|
||||||
|
wikipedia.add_page(
|
||||||
|
"Hilary of Poitiers", image_name="Hilary.jpg", thumb_url=thumb("Hilary.jpg")
|
||||||
|
)
|
||||||
|
wikipedia.add_page("Fabian", image_name="Fabian.jpg", thumb_url=thumb("Fabian.jpg"))
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
last_line = capsys.readouterr().out.splitlines()[-1]
|
||||||
|
assert last_line == "Done! Downloaded: 2, Skipped: 1, Failed: 1"
|
||||||
|
|
||||||
|
|
||||||
|
# `parametrize` runs the same test once per row below, so each URL shape
|
||||||
|
# gets its own pass/fail line in the report.
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"image_url, expected_file",
|
||||||
|
[
|
||||||
|
(f"{COMMONS}/thumb/a/ab/Bede.png/500px-Bede.png", "Bede.png"),
|
||||||
|
(f"{COMMONS}/thumb/a/ab/Bede.jpeg/500px-Bede.jpeg", "Bede.jpeg"),
|
||||||
|
# Thumbnails of SVGs are PNGs.
|
||||||
|
(f"{COMMONS}/thumb/a/ab/Bede.svg/500px-Bede.svg.png", "Bede.png"),
|
||||||
|
# Upper-case extensions are saved lower-case, because the daily
|
||||||
|
# script only looks for lower-case ones.
|
||||||
|
(f"{COMMONS}/a/ab/Bede.JPG", "Bede.jpg"),
|
||||||
|
# Anything unrecognised falls back to .jpg.
|
||||||
|
(f"{COMMONS}/a/ab/Bede.tiff", "Bede.jpg"),
|
||||||
|
],
|
||||||
|
ids=["png", "jpeg", "svg-thumbnail", "upper-case-jpg", "unknown-tiff"],
|
||||||
|
)
|
||||||
|
def test_script_names_picture_file_with_extension_from_image_url(
|
||||||
|
project_dir, wikipedia, no_waiting, image_url, expected_file
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["May 25,Bede,Saint Bède le Vénérable,"])
|
||||||
|
wikipedia.add_page("Bede", image_name="Bede", original_url=image_url)
|
||||||
|
|
||||||
|
downloader.main()
|
||||||
|
|
||||||
|
assert [p.name for p in (project_dir / "pics").iterdir()] == [expected_file]
|
||||||
@@ -0,0 +1,515 @@
|
|||||||
|
"""Tests for get_saint_of_the_day.py.
|
||||||
|
|
||||||
|
These tests never touch the real CSV, the real pics/ folder, the real .env,
|
||||||
|
the real clock, or the real Mastodon server. Fixtures below swap each of
|
||||||
|
those for a stand-in the test controls.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from mastodon import MastodonNetworkError
|
||||||
|
|
||||||
|
import get_saint_of_the_day as saint_of_the_day
|
||||||
|
|
||||||
|
CSV_HEADER = "Date,Saint Name,French Name,Notes\n"
|
||||||
|
|
||||||
|
|
||||||
|
# --- Fixtures ---------------------------------------------------------------
|
||||||
|
# A fixture is a function pytest runs before a test that asks for it by name
|
||||||
|
# (as a parameter). `monkeypatch` and `tmp_path` are built-in fixtures:
|
||||||
|
# `tmp_path` is a fresh empty folder per test, and `monkeypatch` swaps an
|
||||||
|
# attribute for the length of one test, then puts the original back.
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def project_dir(tmp_path, monkeypatch):
|
||||||
|
"""Make the script look for its CSV, pics/ and .env inside tmp_path.
|
||||||
|
|
||||||
|
The script finds its files with Path(__file__).parent, so pointing the
|
||||||
|
module's __file__ into tmp_path moves all three at once.
|
||||||
|
"""
|
||||||
|
monkeypatch.setattr(
|
||||||
|
saint_of_the_day, "__file__", str(tmp_path / "get_saint_of_the_day.py")
|
||||||
|
)
|
||||||
|
(tmp_path / "pics").mkdir()
|
||||||
|
# Start with no Mastodon credentials in the environment, so values from
|
||||||
|
# your shell can't leak in. Setting each variable before deleting it
|
||||||
|
# makes monkeypatch remember the original state, so afterwards it also
|
||||||
|
# undoes anything load_dotenv() wrote during the test.
|
||||||
|
for name in ("MASTODON_INSTANCE_URL", "MASTODON_ACCESS_TOKEN"):
|
||||||
|
monkeypatch.setenv(name, "placeholder")
|
||||||
|
monkeypatch.delenv(name)
|
||||||
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
|
def write_csv(project_dir, rows):
|
||||||
|
"""Write a small saints CSV into the test's project folder."""
|
||||||
|
(project_dir / "saints_days_france.csv").write_text(
|
||||||
|
CSV_HEADER + "".join(row + "\n" for row in rows), encoding="utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def set_today(monkeypatch):
|
||||||
|
"""Return a function that freezes 'now' to a chosen date."""
|
||||||
|
|
||||||
|
def _set_today(year, month, day):
|
||||||
|
class FrozenDatetime(datetime):
|
||||||
|
@classmethod
|
||||||
|
def now(cls, tz=None):
|
||||||
|
return cls(year, month, day, 8, 0)
|
||||||
|
|
||||||
|
monkeypatch.setattr(saint_of_the_day, "datetime", FrozenDatetime)
|
||||||
|
|
||||||
|
return _set_today
|
||||||
|
|
||||||
|
|
||||||
|
# --- get_standardized_name / get_wikipedia_url -----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_standardized_name_replaces_spaces_with_underscores():
|
||||||
|
assert (
|
||||||
|
saint_of_the_day.get_standardized_name("Francis de Sales") == "Francis_de_Sales"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_wikipedia_url_points_at_english_wikipedia_article():
|
||||||
|
assert (
|
||||||
|
saint_of_the_day.get_wikipedia_url("Francis de Sales")
|
||||||
|
== "https://en.wikipedia.org/wiki/Francis_de_Sales"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_wikipedia_url_percent_encodes_accents_and_apostrophes():
|
||||||
|
assert (
|
||||||
|
saint_of_the_day.get_wikipedia_url("Mary Magdalene de' Pazzi of Ávila")
|
||||||
|
== "https://en.wikipedia.org/wiki/Mary_Magdalene_de%27_Pazzi_of_%C3%81vila"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# --- get_saint_picture_path ------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_picture_path_finds_jpg_named_after_saint(project_dir):
|
||||||
|
picture = project_dir / "pics" / "Francis_de_Sales.jpg"
|
||||||
|
picture.write_bytes(b"fake image")
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saint_picture_path("Francis de Sales") == picture
|
||||||
|
|
||||||
|
|
||||||
|
def test_picture_path_finds_png_named_after_saint(project_dir):
|
||||||
|
picture = project_dir / "pics" / "Aloysius_Gonzaga.png"
|
||||||
|
picture.write_bytes(b"fake image")
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saint_picture_path("Aloysius Gonzaga") == picture
|
||||||
|
|
||||||
|
|
||||||
|
def test_picture_path_is_none_when_saint_has_no_picture(project_dir):
|
||||||
|
(project_dir / "pics" / "Someone_Else.jpg").write_bytes(b"fake image")
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saint_picture_path("Francis de Sales") is None
|
||||||
|
|
||||||
|
|
||||||
|
# --- get_saints_for_today --------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_returns_todays_saint_with_details(project_dir, set_today):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 21,Agnes,Sainte Agnès,Virgin and Martyr",
|
||||||
|
"January 22,Vincent of Saragossa,Saint Vincent,Deacon and Martyr",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
picture = project_dir / "pics" / "Agnes.jpg"
|
||||||
|
picture.write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saints_for_today() == [
|
||||||
|
{
|
||||||
|
"name": "Agnes",
|
||||||
|
"french_name": "Sainte Agnès",
|
||||||
|
"notes": "Virgin and Martyr",
|
||||||
|
"wikipedia_url": "https://en.wikipedia.org/wiki/Agnes",
|
||||||
|
"picture_path": picture,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_returns_every_saint_sharing_the_date(project_dir, set_today):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 20,Fabian,Saint Fabien,",
|
||||||
|
"January 20,Sebastian,Saint Sébastien,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
set_today(2026, 1, 20)
|
||||||
|
|
||||||
|
names = [saint["name"] for saint in saint_of_the_day.get_saints_for_today()]
|
||||||
|
|
||||||
|
assert names == ["Fabian", "Sebastian"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_skips_feast_days_that_are_not_people(project_dir, set_today):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"December 8,Immaculate Conception,Immaculée Conception,Solemnity",
|
||||||
|
"December 9,Juan Diego,Saint Juan Diego,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
set_today(2026, 12, 8)
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saints_for_today() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_matches_single_digit_day_exactly(project_dir, set_today):
|
||||||
|
# "January 2" must match "January 2" only: not "January 02",
|
||||||
|
# and not "January 20" or "January 21".
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 2,Basil the Great and Gregory Nazianzen,Saints Basile et Grégoire,",
|
||||||
|
"January 20,Fabian,Saint Fabien,",
|
||||||
|
"January 21,Agnes,Sainte Agnès,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
set_today(2026, 1, 2)
|
||||||
|
|
||||||
|
names = [saint["name"] for saint in saint_of_the_day.get_saints_for_today()]
|
||||||
|
|
||||||
|
assert names == ["Basil the Great and Gregory Nazianzen"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_is_empty_when_no_saint_has_the_date(project_dir, set_today):
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,"])
|
||||||
|
set_today(2026, 3, 1)
|
||||||
|
|
||||||
|
assert saint_of_the_day.get_saints_for_today() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_saints_for_today_has_no_picture_path_when_picture_missing(
|
||||||
|
project_dir, set_today
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,"])
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
[saint] = saint_of_the_day.get_saints_for_today()
|
||||||
|
|
||||||
|
assert saint["picture_path"] is None
|
||||||
|
|
||||||
|
|
||||||
|
# --- format_mastodon_post --------------------------------------------------
|
||||||
|
|
||||||
|
AGNES = {
|
||||||
|
"name": "Agnes",
|
||||||
|
"french_name": "Sainte Agnès",
|
||||||
|
"notes": "Virgin and Martyr",
|
||||||
|
"wikipedia_url": "https://en.wikipedia.org/wiki/Agnes",
|
||||||
|
"picture_path": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_mastodon_post_names_date_saint_link_and_hashtags(set_today):
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
assert saint_of_the_day.format_mastodon_post(AGNES) == (
|
||||||
|
"January 21: the Feast of Saint Agnes\n"
|
||||||
|
"https://en.wikipedia.org/wiki/Agnes\n"
|
||||||
|
"\n"
|
||||||
|
"#saints #hagiography"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mastodon_post_does_not_zero_pad_single_digit_days(set_today):
|
||||||
|
set_today(2026, 11, 8)
|
||||||
|
|
||||||
|
first_line = saint_of_the_day.format_mastodon_post(AGNES).splitlines()[0]
|
||||||
|
|
||||||
|
assert first_line == "November 8: the Feast of Saint Agnes"
|
||||||
|
|
||||||
|
|
||||||
|
# --- Fake Mastodon ---------------------------------------------------------
|
||||||
|
# The real Mastodon client talks to a server. These fixtures swap it for a
|
||||||
|
# fake that records what it was asked to do, so tests can check exactly what
|
||||||
|
# would have been posted, and nothing ever reaches a real account.
|
||||||
|
|
||||||
|
INSTANCE_URL = "https://example.social"
|
||||||
|
ACCESS_TOKEN = "test-token-123"
|
||||||
|
POSTED_URL = "https://example.social/@saints/222"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mastodon_calls(monkeypatch):
|
||||||
|
"""Replace Mastodon with a fake; return the list of calls it receives."""
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
class FakeMastodon:
|
||||||
|
def __init__(self, access_token=None, api_base_url=None):
|
||||||
|
calls.append(("connect", access_token, api_base_url))
|
||||||
|
|
||||||
|
def media_post(self, media_file, mime_type=None, description=None):
|
||||||
|
calls.append(("media_post", media_file, description))
|
||||||
|
return {"id": "111", "type": "image", "description": description}
|
||||||
|
|
||||||
|
def status_post(self, status, media_ids=None, visibility=None):
|
||||||
|
calls.append(("status_post", status, media_ids, visibility))
|
||||||
|
return {"id": "222", "url": POSTED_URL, "visibility": visibility}
|
||||||
|
|
||||||
|
monkeypatch.setattr(saint_of_the_day, "Mastodon", FakeMastodon)
|
||||||
|
return calls
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mastodon_that_fails(monkeypatch):
|
||||||
|
"""Replace Mastodon with a fake whose server can't be reached."""
|
||||||
|
|
||||||
|
class UnreachableMastodon:
|
||||||
|
def __init__(self, access_token=None, api_base_url=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def media_post(self, media_file, mime_type=None, description=None):
|
||||||
|
return {"id": "111", "type": "image", "description": description}
|
||||||
|
|
||||||
|
def status_post(self, status, media_ids=None, visibility=None):
|
||||||
|
raise MastodonNetworkError("Could not connect to server")
|
||||||
|
|
||||||
|
monkeypatch.setattr(saint_of_the_day, "Mastodon", UnreachableMastodon)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def credentials(project_dir, monkeypatch):
|
||||||
|
monkeypatch.setenv("MASTODON_INSTANCE_URL", INSTANCE_URL)
|
||||||
|
monkeypatch.setenv("MASTODON_ACCESS_TOKEN", ACCESS_TOKEN)
|
||||||
|
|
||||||
|
|
||||||
|
# --- post_to_mastodon ------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_sends_public_status_without_media_when_no_picture(
|
||||||
|
credentials, mastodon_calls, set_today
|
||||||
|
):
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES)
|
||||||
|
|
||||||
|
assert mastodon_calls == [
|
||||||
|
("connect", ACCESS_TOKEN, INSTANCE_URL),
|
||||||
|
(
|
||||||
|
"status_post",
|
||||||
|
"January 21: the Feast of Saint Agnes\n"
|
||||||
|
"https://en.wikipedia.org/wiki/Agnes\n"
|
||||||
|
"\n"
|
||||||
|
"#saints #hagiography",
|
||||||
|
None,
|
||||||
|
"public",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_uploads_picture_and_attaches_it_to_status(
|
||||||
|
project_dir, credentials, mastodon_calls, set_today
|
||||||
|
):
|
||||||
|
picture = project_dir / "pics" / "Agnes.jpg"
|
||||||
|
picture.write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES | {"picture_path": picture})
|
||||||
|
|
||||||
|
assert mastodon_calls[1:] == [
|
||||||
|
("media_post", str(picture), "Image of Agnes"),
|
||||||
|
(
|
||||||
|
"status_post",
|
||||||
|
"January 21: the Feast of Saint Agnes\n"
|
||||||
|
"https://en.wikipedia.org/wiki/Agnes\n"
|
||||||
|
"\n"
|
||||||
|
"#saints #hagiography",
|
||||||
|
["111"],
|
||||||
|
"public",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_reads_credentials_from_env_file_next_to_script(
|
||||||
|
project_dir, mastodon_calls
|
||||||
|
):
|
||||||
|
(project_dir / ".env").write_text(
|
||||||
|
"MASTODON_INSTANCE_URL=https://from-env-file.social\n"
|
||||||
|
"MASTODON_ACCESS_TOKEN=token-from-env-file\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES)
|
||||||
|
|
||||||
|
assert mastodon_calls[0] == (
|
||||||
|
"connect",
|
||||||
|
"token-from-env-file",
|
||||||
|
"https://from-env-file.social",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_refuses_when_instance_url_is_missing(
|
||||||
|
project_dir, monkeypatch, mastodon_calls
|
||||||
|
):
|
||||||
|
monkeypatch.setenv("MASTODON_ACCESS_TOKEN", ACCESS_TOKEN)
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="Missing Mastodon credentials"):
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES)
|
||||||
|
assert mastodon_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_refuses_when_access_token_is_missing(
|
||||||
|
project_dir, monkeypatch, mastodon_calls
|
||||||
|
):
|
||||||
|
monkeypatch.setenv("MASTODON_INSTANCE_URL", INSTANCE_URL)
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="Missing Mastodon credentials"):
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES)
|
||||||
|
assert mastodon_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_refuses_placeholder_access_token(
|
||||||
|
project_dir, monkeypatch, mastodon_calls
|
||||||
|
):
|
||||||
|
monkeypatch.setenv("MASTODON_INSTANCE_URL", INSTANCE_URL)
|
||||||
|
monkeypatch.setenv("MASTODON_ACCESS_TOKEN", "your_access_token_here")
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="update the MASTODON_ACCESS_TOKEN"):
|
||||||
|
saint_of_the_day.post_to_mastodon(AGNES)
|
||||||
|
assert mastodon_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
# --- main (running the script) ---------------------------------------------
|
||||||
|
# These call main() the way the command line does: by setting sys.argv.
|
||||||
|
# `capsys` is a built-in fixture that captures what the script prints.
|
||||||
|
|
||||||
|
|
||||||
|
def run_script(monkeypatch, *args):
|
||||||
|
monkeypatch.setattr(sys, "argv", ["get_saint_of_the_day.py", *args])
|
||||||
|
saint_of_the_day.main()
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_prints_todays_saint_and_does_not_post(
|
||||||
|
project_dir, set_today, mastodon_calls, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,Virgin and Martyr"])
|
||||||
|
picture = project_dir / "pics" / "Agnes.jpg"
|
||||||
|
picture.write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
run_script(monkeypatch)
|
||||||
|
|
||||||
|
assert capsys.readouterr().out == (
|
||||||
|
"Saint: Agnes\n"
|
||||||
|
"French: Sainte Agnès\n"
|
||||||
|
"Notes: Virgin and Martyr\n"
|
||||||
|
"Wikipedia: https://en.wikipedia.org/wiki/Agnes\n"
|
||||||
|
f"Picture: {picture}\n"
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
assert mastodon_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_leaves_out_notes_and_says_when_no_picture(
|
||||||
|
project_dir, set_today, mastodon_calls, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 20,Fabian,Saint Fabien,"])
|
||||||
|
set_today(2026, 1, 20)
|
||||||
|
|
||||||
|
run_script(monkeypatch)
|
||||||
|
|
||||||
|
assert capsys.readouterr().out == (
|
||||||
|
"Saint: Fabian\n"
|
||||||
|
"French: Saint Fabien\n"
|
||||||
|
"Wikipedia: https://en.wikipedia.org/wiki/Fabian\n"
|
||||||
|
"Picture: (none available)\n"
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_says_so_when_there_is_no_saint_today(
|
||||||
|
project_dir, set_today, mastodon_calls, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,"])
|
||||||
|
set_today(2026, 3, 1)
|
||||||
|
|
||||||
|
run_script(monkeypatch, "--post")
|
||||||
|
|
||||||
|
assert capsys.readouterr().out == (
|
||||||
|
"No saint's day today (or today is a holiday/feast day).\n"
|
||||||
|
)
|
||||||
|
assert mastodon_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_with_post_flag_posts_saint_and_prints_link(
|
||||||
|
project_dir, credentials, set_today, mastodon_calls, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,"])
|
||||||
|
(project_dir / "pics" / "Agnes.jpg").write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
run_script(monkeypatch, "--post")
|
||||||
|
|
||||||
|
assert [call[0] for call in mastodon_calls] == [
|
||||||
|
"connect",
|
||||||
|
"media_post",
|
||||||
|
"status_post",
|
||||||
|
]
|
||||||
|
assert f" Posted! URL: {POSTED_URL}\n" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_with_post_flag_posts_every_saint_sharing_the_date(
|
||||||
|
project_dir, credentials, set_today, mastodon_calls, monkeypatch
|
||||||
|
):
|
||||||
|
write_csv(
|
||||||
|
project_dir,
|
||||||
|
[
|
||||||
|
"January 20,Fabian,Saint Fabien,",
|
||||||
|
"January 20,Sebastian,Saint Sébastien,",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
(project_dir / "pics" / "Fabian.jpg").write_bytes(b"fake image")
|
||||||
|
(project_dir / "pics" / "Sebastian.jpg").write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 20)
|
||||||
|
|
||||||
|
run_script(monkeypatch, "--post")
|
||||||
|
|
||||||
|
posted = [call[1] for call in mastodon_calls if call[0] == "status_post"]
|
||||||
|
assert posted == [
|
||||||
|
"January 20: the Feast of Saint Fabian\n"
|
||||||
|
"https://en.wikipedia.org/wiki/Fabian\n"
|
||||||
|
"\n"
|
||||||
|
"#saints #hagiography",
|
||||||
|
"January 20: the Feast of Saint Sebastian\n"
|
||||||
|
"https://en.wikipedia.org/wiki/Sebastian\n"
|
||||||
|
"\n"
|
||||||
|
"#saints #hagiography",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_with_post_flag_skips_saint_without_picture(
|
||||||
|
project_dir, credentials, set_today, mastodon_calls, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
write_csv(project_dir, ["January 20,Fabian,Saint Fabien,"])
|
||||||
|
set_today(2026, 1, 20)
|
||||||
|
|
||||||
|
run_script(monkeypatch, "--post")
|
||||||
|
|
||||||
|
assert mastodon_calls == []
|
||||||
|
assert "Skipping Mastodon post (no picture available)" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_fails_loudly_when_mastodon_post_fails(
|
||||||
|
project_dir, credentials, set_today, mastodon_that_fails, monkeypatch, capsys
|
||||||
|
):
|
||||||
|
# The error must escape main() so the script exits non-zero: otherwise
|
||||||
|
# systemd treats the run as a success and never triggers OnFailure.
|
||||||
|
write_csv(project_dir, ["January 21,Agnes,Sainte Agnès,"])
|
||||||
|
(project_dir / "pics" / "Agnes.jpg").write_bytes(b"fake image")
|
||||||
|
set_today(2026, 1, 21)
|
||||||
|
|
||||||
|
with pytest.raises(MastodonNetworkError):
|
||||||
|
run_script(monkeypatch, "--post")
|
||||||
|
assert " Error posting: Could not connect to server\n" in capsys.readouterr().out
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
"""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()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
version = 1
|
version = 1
|
||||||
revision = 5
|
revision = 3
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -162,6 +162,15 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/31/7d/164b7ffc8624fe9efb4221bf9af485d5c1e41b9ae118045d2b6dc5457d8b/click-8.5.1-py3-none-any.whl", hash = "sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37", size = 126163, upload-time = "2026-11-06T17:36:59.287Z" },
|
{ url = "https://files.pythonhosted.org/packages/31/7d/164b7ffc8624fe9efb4221bf9af485d5c1e41b9ae118045d2b6dc5457d8b/click-8.5.1-py3-none-any.whl", hash = "sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37", size = 126163, upload-time = "2026-11-06T17:36:59.287Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorama"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "decorator"
|
name = "decorator"
|
||||||
version = "5.3.1"
|
version = "5.3.1"
|
||||||
@@ -180,6 +189,15 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" },
|
{ url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iniconfig"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mastodon-py"
|
name = "mastodon-py"
|
||||||
version = "2.3.3"
|
version = "2.3.3"
|
||||||
@@ -230,6 +248,40 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/7c/ae/ecbbbfd0e4343a6a521d49b3c8656fb4643dee2a4f6eaf941cf3280391a8/platformdirs-4.14.5-py3-none-any.whl", hash = "sha256:8e778c6fa421516f4d3369449f8df3b0e1b72c0e0005fe88e3ec772d0a14e750", size = 35402, upload-time = "2026-11-04T16:54:48.875Z" },
|
{ url = "https://files.pythonhosted.org/packages/7c/ae/ecbbbfd0e4343a6a521d49b3c8656fb4643dee2a4f6eaf941cf3280391a8/platformdirs-4.14.5-py3-none-any.whl", hash = "sha256:8e778c6fa421516f4d3369449f8df3b0e1b72c0e0005fe88e3ec772d0a14e750", size = 35402, upload-time = "2026-11-04T16:54:48.875Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pluggy"
|
||||||
|
version = "1.7.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pygments"
|
||||||
|
version = "2.21.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pytest"
|
||||||
|
version = "9.2.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||||
|
{ name = "iniconfig" },
|
||||||
|
{ name = "packaging" },
|
||||||
|
{ name = "pluggy" },
|
||||||
|
{ name = "pygments" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/79/42/bb4641652e58dedeac2ec51abc1f8cae4fee4ec63899a0999016229a0f2a/pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b", size = 1797555, upload-time = "2026-10-27T21:30:20.728Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-dateutil"
|
name = "python-dateutil"
|
||||||
version = "4.0.0"
|
version = "4.0.0"
|
||||||
@@ -301,6 +353,11 @@ dependencies = [
|
|||||||
{ name = "requests" },
|
{ name = "requests" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[package.dev-dependencies]
|
||||||
|
dev = [
|
||||||
|
{ name = "pytest" },
|
||||||
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "black", specifier = ">=26.1.0" },
|
{ name = "black", specifier = ">=26.1.0" },
|
||||||
@@ -309,6 +366,9 @@ requires-dist = [
|
|||||||
{ name = "requests", specifier = ">=2.32.5" },
|
{ name = "requests", specifier = ">=2.32.5" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[package.metadata.requires-dev]
|
||||||
|
dev = [{ name = "pytest", specifier = ">=9.2.0" }]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tzdata"
|
name = "tzdata"
|
||||||
version = "2026.6"
|
version = "2026.6"
|
||||||
|
|||||||
Reference in new issue
Block a user