"""Step 3e part 2: what each piece on the map says (p02/briefs.py). Pure: no Panda3D needed.""" import unittest from p02 import briefs as B from p02 import campaign as K from p02 import data as D class Briefs(unittest.TestCase): def setUp(self): self.c = K.new_campaign(4) self.c.intel = 100 while len(self.c.missions) < 3: K.scout(self.c) def test_missions_numbered_soonest_first(self): c = self.c c.missions[0].expires = c.day + 9 order = B.mission_order(c) self.assertEqual(sorted(order, key=lambda m: m.expires), order) self.assertEqual(set(m.id for m in order), set(m.id for m in c.missions)) self.assertEqual(order[-1], c.missions[0]) def test_mission_brief_an_incursion_both_sides_and_your_standing(self): c = self.c m = c.missions[0] self.assertIsNone(m.group) a, b = m.sides() c.affinity[f"{m.region}:0"] = 30 t = B.mission_brief(c, m) for part in (m.about(), "Pick a side", f"Back {a}", f"fight {b}", f"Back {b}", f"fight {a}", f"Your standing: {a}: 30 (trade); {b}: 0.", f"+{D.AFFINITY_WON}", f"{m.expires - c.day} days left", f"{K.travel_days(m.region, 'on foot')} days on foot"): self.assertIn(part, t) def test_mission_brief(self): c = self.c m = c.missions[0] m.group, m.pods = 1, [["raider", "raider"]] # a side picked helped, fought = m.names() t = B.mission_brief(c, m) for part in (D.REGIONS[m.region]["name"], m.about(), D.REGIONS[m.region]["dilemma"], f"+{D.MISSION_KINDS[m.kind]['supplies']} supplies", f"toward {helped}", f"toward {fought}", f"Expect {len(m.pods)} groups", f"{m.expires - c.day} days left", f"{K.travel_days(m.region, 'on foot')} days on foot"): self.assertIn(part, t) def test_region_brief_says_who_holds_it(self): c = self.c rid = next(iter(D.REGIONS)) info, reg = D.REGIONS[rid], c.regions[rid] a, b = (g["name"] for g in info["groups"]) reg.lean, reg.owner, reg.ally = 0, None, None c.missions = [m for m in c.missions if m.region != rid] self.assertIn(f"Undecided between {a} and {b}", B.region_brief(c, rid)) self.assertNotIn("waiting", B.region_brief(c, rid)) reg.lean = 30 self.assertIn(f"leaning to {a} (30 of 100)", B.region_brief(c, rid)) reg.lean = -55 self.assertIn(f"leaning to {b} (55 of 100)", B.region_brief(c, rid)) reg.owner, reg.ally = 1, True self.assertIn(f"ALLY: {b} hold it", B.region_brief(c, rid)) reg.owner, reg.ally = 0, False self.assertIn(f"HOSTILE: {a} hold it", B.region_brief(c, rid)) self.assertIn(info["dilemma"], B.region_brief(c, rid)) self.assertIn(f"Its town: {info['town']}", B.region_brief(c, rid)) self.assertIn(f"Your standing: {a}: 0; {b}: 0.", B.region_brief(c, rid)) m = c.missions[0] m.region = rid self.assertIn("1 mission waiting", B.region_brief(c, rid)) def test_fort_brief(self): c = self.c c.supplies, c.intel, c.recruits = 123, 45, 6 t = B.fort_brief(c) for part in ("Fort Leonard Wood", f"{D.HOME} County", f"Day {c.day}", "Supplies 123", "intel 45", "recruits waiting 6", f"{c.weekly()['supplies']:+} supplies", "Facilities: none yet"): self.assertIn(part, t) c.facilities["drill yard"] = 1 self.assertIn("drill yard 1", B.fort_brief(c)) def test_unit_brief(self): c = self.c alive = [s for s in c.roster if not s.dead] t = B.unit_brief(c) self.assertIn(f"{len(alive)} of {len(alive)} soldiers ready", t) self.assertIn(alive[0].name, t) alive[0].wounded_until = c.day + 3 self.assertIn(f"{len(alive) - 1} of {len(alive)} soldiers ready", B.unit_brief(c)) self.assertNotIn(alive[0].name + " (", B.unit_brief(c)) m = c.missions[0] c.trip = {"mission": m.id, "travel": "on foot", "days": 3} self.assertEqual(B.unit_brief(c), f"The unit is out, on foot, bound for {D.REGIONS[m.region]['name']}.") class TheMemorial(unittest.TestCase): """Dillon, 2026-11-16: the rec area's memorial, everyone lost and how.""" def setUp(self): self.c = K.new_campaign(4) a, b, d = self.c.roster[:3] a.dead, a.rank, a.missions, a.kills, a.xp, a.skills = True, 2, 2, 3, 14, ["Drilled"] a.record = [{"day": 4, "region": "Lake of the Ozarks", "kind": "raid", "for": "The Marina Lords", "against": "The Dam Keepers", "won": True, "kills": 3, "hurt": "wounded"}, {"day": 19, "region": "The Rolla Plateau", "kind": "escort", "for": "The Miners' College", "against": "The Iron Road Syndicate", "won": False, "kills": 0, "hurt": "downed"}] a.fate = {"how": "missing in action", "day": 19, "where": "The Rolla Plateau", "story": "shot by a raider with machete, turn 4. The field was lost and they were left on it"} b.dead = True # fell before records were kept (an old save) self.a, self.b, self.d = a, b, d def test_the_wall_has_everyone_lost_newest_first(self): self.assertEqual(B.fallen(self.c), [self.a, self.b]) e = self.c.roster[4] e.dead, e.fate = True, dict(self.a.fate, day=30) # later in the roster, fell later self.assertEqual(B.fallen(self.c), [e, self.a, self.b]) e.fate["day"] = 2 self.assertEqual(B.fallen(self.c), [self.a, e, self.b]) self.assertNotIn(self.d, B.fallen(self.c)) self.assertEqual(B.memorial_line(self.a), f"{D.RANK_NAMES[2]} {self.a.name}, {self.a.cls}: missing in action, day 19") self.assertEqual(B.memorial_line(self.b), f"Private {self.b.name}, {self.b.cls}: killed in action") def test_an_entry_has_the_service_and_the_end(self): e = B.memorial_entry(self.a) self.assertIn("2 missions, 3 kills, 14 XP.", e) self.assertIn("Skills: Drilled.", e) self.assertIn("Day 4: a raid in Lake of the Ozarks for The Marina Lords against The Dam Keepers: won, 3 kills, wounded.", e) self.assertIn("Day 19: a convoy escort in The Rolla Plateau for The Miners' College against The Iron Road " "Syndicate: lost, went down.", e) self.assertTrue(e.endswith("Missing in action, day 19, The Rolla Plateau: shot by a raider with machete, " "turn 4. The field was lost and they were left on it.")) self.assertIn("1 mission, 0 kills", B.memorial_entry(self.d.__class__(name="X", cls="medic", missions=1))) self.assertTrue(B.memorial_entry(self.b).endswith("Killed in action, before the fort kept its records.")) def test_the_real_thing_end_to_end(self): c = K.new_campaign(7) m = c.missions[0] s = c.roster[0] b = K.launch(c, m.id, [[s.name], []], side=0) b.outcome = "lost" u = next(u for u in b.units if u.name == s.name) u.hp, u.downed = 0, "shot by a militiaman with pre-war surplus rifle, turn 2" K.finish(c, m.id, b) e = B.memorial_entry(s) self.assertIn(B.memorial_line(s), [B.memorial_line(x) for x in B.fallen(c)]) self.assertIn(": lost, went down.", e) self.assertIn("shot by a militiaman with pre-war surplus rifle, turn 2", e.splitlines()[-1]) if __name__ == "__main__": unittest.main()