Draw a picked photo only with bg=photo, keep bg=satellite to aerial imagery

The operator judged the Commons-photo poster unfit as a default: its crop lands beside the circuit and shows the
track only as an inset. bg=satellite is now the national aerial photo, else EOxCloudless (or the dark map where
"use": "map" is set); the new bg=photo draws the layout's picked photo and without one falls back to what
bg=satellite draws. A picks entry may hold the photo fields, "use": "map", or both; an unknown use and incomplete
photo fields are refused at load. The smallest width is 400 px so the full credit line stays readable, and the
ASCII credit header spells out ß, æ, ø, œ and đ so names stay readable.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 15:18:09 +01:00
parent d514eb57a3
commit 4362e2d10b
7 changed files with 89 additions and 49 deletions
+33 -12
View File
@@ -17,22 +17,37 @@ class SatelliteChainTest(unittest.TestCase):
def test_the_first_source_that_has_the_layout(self):
early = 2016 if ps.EOX_2016_FOR_EARLY_LAYOUTS else 2025 # the one switch for EOX's year
photo, use_map = {"file": "A.jpg", "licence": "CC BY 4.0"}, {"use": "map"}
both = {**photo, **use_map}
cases = [
# (country, circuit, layout, the layout's entry in circuits/photos.json) → (source, year, tint)
(("bahrain", "bahrain-international-circuit", "2004-", photo), ("commons", None, None)),
(("united-states", "miami-international-autodrome", "2022-", None), ("usgs", None, None)),
(("bahrain", "bahrain-international-circuit", "2004-", photo), ("eox", early, None)), # a pick is bg=photo's
(("united-states", "miami-international-autodrome", "2022-", photo), ("usgs", None, None)),
(("netherlands", "circuit-park-zandvoort", "2020-", use_map), ("pdok", None, None)), # national wins
(("france", "circuit-paul-ricard", "2018-", None), ("ign", "2021-2023", None)),
(("bahrain", "bahrain-international-circuit", "2004-", None), ("eox", early, None)), # first raced by 2016
(("bahrain", "bahrain-international-circuit", "2004-", use_map), ("osm", None, "dark")), # the override
(("bahrain", "bahrain-international-circuit", "2004-", both), ("osm", None, "dark")), # a photo beside it
(("united-states", "miami-international-autodrome", "2022-", both), ("usgs", None, None)),
(("spain", "madring", "2026-", None), ("eox", 2025, None)),
]
for given, expected in cases:
chosen = ps.satellite_source(*given)
got = (chosen, None, None) if chosen == ps.COMMONS else (chosen.id, chosen.year, chosen.tint)
self.assertEqual(got, expected, given)
self.assertEqual((chosen.id, chosen.year, chosen.tint), expected, given)
self.assertEqual(ps.satellite_source("bahrain", "x", "2004-", use_map).credit, ps.OSM_CREDIT)
def test_bg_photo_takes_the_pick_else_the_satellite_chain(self):
photo = {"file": "A.jpg", "licence": "CC BY-SA 4.0"}
self.assertEqual(ps.photo_source("united-states", "miami-international-autodrome", "2022-", photo), ps.COMMONS)
self.assertEqual(ps.photo_source("bahrain", "bahrain-international-circuit", "2004-", {**photo, "use": "map"}),
ps.COMMONS) # with use: map beside the photo, bg=photo still draws the photo
for entry, source in ((None, "usgs"), ({"use": "map"}, "usgs")):
self.assertEqual(ps.photo_source("united-states", "miami-international-autodrome", "2022-", entry).id, source)
self.assertEqual(ps.photo_source("bahrain", "bahrain-international-circuit", "2004-", {"use": "map"}).tint, "dark")
options = po.parse_options([("bg", "photo")], "race")
self.assertEqual(options.bg, "photo")
self.assertTrue(all(po.parse_options([("style", style)], kind).bg == "satellite"
for style in po.STYLES for kind in po.FRAME_OF)) # never a style's default
def test_every_french_layout_takes_ign(self):
france = json.loads((ROOT / "circuits" / "circuits.json").read_text(encoding="utf-8"))["france"]
layouts = [(slug, layout) for locality in france["localities"].values()
@@ -48,6 +63,8 @@ class CreditAndLicenceTest(unittest.TestCase):
self.assertEqual(line, "© IGN – BD ORTHO, 2021–2023 · © OpenStreetMap contributors")
self.assertEqual(ps.ascii_header(line), "(c) IGN - BD ORTHO, 2021-2023 | (c) OpenStreetMap contributors")
self.assertEqual(ps.ascii_header("Photo: José Müller — 王 CC BY-SA 4.0"), "Photo: Jose Muller - ? CC BY-SA 4.0")
self.assertEqual(ps.ascii_header("Steffen Prößdorf, Søren Bækgaard, Œuvre, Đorđe"),
"Steffen Prossdorf, Soren Baekgaard, OEuvre, Dorde")
def test_a_pictures_licence_follows_its_sources(self):
by_sa = ps.pick_share({"licence": "CC BY-SA 3.0 de"})
@@ -66,18 +83,22 @@ class CreditAndLicenceTest(unittest.TestCase):
def test_picks_skip_notes_and_refuse_what_they_cannot_use(self):
with tempfile.TemporaryDirectory() as kept:
path = Path(kept) / "photos.json"
def photo(file, licence):
return {"file": file, "licence": licence, "author": "A", "credit": "Photo: A", "date": "2020"}
path.write_text(json.dumps({
"$comment": "a note",
"a/b/c/2004-": {"file": "A.jpg", "licence": "CC BY-SA 4.0", "author": "A"},
"a/b/c/1950-": {"file": "B.jpg", "licence": "CC BY-NC-SA 2.0", "author": "B"},
"a/b/c/2010": {"file": "C.jpg", "licence": "Public domain", "author": "C"},
"a/b/c/2004-": photo("A.jpg", "CC BY-SA 4.0"),
"a/b/c/2010": photo("C.jpg", "Public domain"),
"a/b/c/2020-": {"use": "map"},
"a/b/c/1990": {"use": "satellite"},
"a/b/c/1991": {"use": "map", "file": "D.jpg", "licence": "CC0"},
"a/b/c/2021-": {**photo("D.jpg", "CC0"), "use": "map"},
"a/b/c/1950-": photo("B.jpg", "CC BY-NC-SA 2.0"), # refused: not a free licence
"a/b/c/1990": {"use": "satellite"}, # refused: an unknown use
"a/b/c/1991": {"use": "map", "file": "E.jpg", "licence": "CC0"}, # refused: incomplete photo fields
"a/b/c/1992": {}, # refused: neither
}))
with self.assertLogs(ps.logger, "ERROR") as logged:
self.assertEqual(sorted(ps.read_picks(path)), ["a/b/c/2004-", "a/b/c/2010", "a/b/c/2020-"])
self.assertEqual(len(logged.output), 3)
self.assertEqual(sorted(ps.read_picks(path)), ["a/b/c/2004-", "a/b/c/2010", "a/b/c/2020-", "a/b/c/2021-"])
self.assertEqual(len(logged.output), 4)
for name in ("circuits/photos.json", "seasons/photos.json"):
self.assertEqual(ps.read_picks(ROOT / name).get("$comment"), None, name)
@@ -115,7 +136,7 @@ class OptionsTest(unittest.TestCase):
cases = {
"colour=red": "'colour'", "bg=esri": "'esri'", "photo=duotone": "'duotone'", "show=name,logo": "'logo'",
"track=#fff": "'#fff'", "track=#ffffff,31": "'#ffffff,31'", "dim=1.5": "'1.5'", "dim=nan": "'nan'",
"width=199": "'199'", "width=1001": "'1001'", "format=gif": "'gif'", "bg=osm&bg=dark": "'bg'",
"width=399": "takes 400", "width=1001": "'1001'", "format=gif": "'gif'", "bg=osm&bg=dark": "'bg'",
"locator=yes": "'yes'", "accent=red": "'red'",
}
for query, named in cases.items():