A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
"""The Steam achievement icons (#2449): the script's ICONS keys, the API names in docs/steam/README.md, the names in
AchievementRules.cs and the committed PNGs must all be the same five names, and the generated icons must have the
size and colour mode Steam gets."""
import re
from pathlib import Path
from PIL import Image, ImageChops
import steam_achievement_icons as icons
ROOT = Path(__file__).resolve().parents[2]
COMMITTED = ROOT / "docs" / "steam" / "achievements"
def readme_api_names():
# Table rows of "Achievements" in docs/steam/README.md start with the API name in backticks.
text = (ROOT / "docs" / "steam" / "README.md").read_text(encoding="utf-8")
text = text.split("### Achievements", 1)[1].split("\n#", 1)[0] # only that section: a later table must not count
return set(re.findall(r"^\| `([A-Z][A-Z0-9_]+)` \|", text, re.M))
def rules_api_names():
# ForObjective values and CampaignDone are the only upper-case string assignments in the file.
text = (ROOT / "unity" / "Assets" / "Scripts" / "Platform" / "AchievementRules.cs").read_text(encoding="utf-8")
return set(re.findall(r'=\s*"([A-Z][A-Z0-9_]+)"', text))
def test_icon_keys_match_readme_table_and_achievement_rules():
keys = set(icons.ICONS)
assert len(keys) == 5
assert readme_api_names() == keys
assert rules_api_names() == keys
def test_every_api_name_has_both_committed_pngs():
for api in icons.ICONS:
for state in ("unlocked", "locked"):
assert (COMMITTED / f"{api}_{state}.png").is_file(), f"{api}_{state}.png is missing"
def test_generated_icons_are_256_rgb_and_locked_ones_are_grey(tmp_path):
icons.main(["steam_achievement_icons.py", str(tmp_path)])
for api in icons.ICONS:
with Image.open(tmp_path / f"{api}_unlocked.png") as unlocked, Image.open(tmp_path / f"{api}_locked.png") as locked:
assert unlocked.size == locked.size == (256, 256)
assert unlocked.mode == locked.mode == "RGB"
r, g, b = locked.split()
assert ImageChops.difference(r, g).getbbox() is None and ImageChops.difference(g, b).getbbox() is None, f"{api}_locked.png is not greyscale"
def test_committed_icons_match_what_the_script_draws_now(tmp_path):
# #2737: an edit to the drawing code, or a hand-edited PNG, must not leave the committed icons stale. Decoded pixels
# are compared, not PNG bytes, since compression may differ.
# Exact pixels depend on the Pillow version: CI pins pillow==12.3.0, as the script header does.
icons.main(["steam_achievement_icons.py", str(tmp_path)])
for api in icons.ICONS:
for state in ("unlocked", "locked"):
name = f"{api}_{state}.png"
with Image.open(tmp_path / name) as fresh, Image.open(COMMITTED / name) as committed:
assert fresh.size == committed.size and fresh.mode == committed.mode, name
assert ImageChops.difference(fresh, committed).getbbox() is None, f"{name} differs from what the script draws"