"""What `sds melee` counts, and what it refuses to count.""" import gzip import json import unittest from pathlib import Path from tempfile import TemporaryDirectory from sds.melee import scan # One round of MegaMek's own log: a kick that lands, a punch that misses, and a # weapon attack that must not be mistaken for either. REPORT = """
Weapon Attack Phase Weapons fire for Atlas AS7-D (sds North) Medium Laser at Dragon DRG-1N (princess South); needs 8, rolls 9 :hits CT Physical Attack Phase------------------- Physical attacks for Atlas AS7-D (sds North) Kick (Left leg) at Dragon DRG-1N (princess South); needs 5, rolls 7 :hits (using Left Side Kick table) LL Physical attacks for Dragon DRG-1N (princess South) Punch (Right Arm) at Atlas AS7-D (sds North); needs 6, rolls 3 :misses Heat Phase------------------- """ SEAT = { "name": "sds North", "kind": "sds", "sds": { "decisions": 10, "answered": 9, "defaulted": 1, "illegal": 0, "phases": {"physical": {"decisions": 2, "answered": 2}}, }, } class MeleeCounts(unittest.TestCase): def _run(self, name="m1.report.html", body=REPORT, compress=False): tmp = TemporaryDirectory() self.addCleanup(tmp.cleanup) run = Path(tmp.name) path = run / (name + ".gz" if compress else name) if compress: path.write_bytes(gzip.compress(body.encode())) else: path.write_text(body, encoding="utf-8") (run / "m1-sds_North.seat.json").write_text(json.dumps(SEAT), encoding="utf-8") return run def test_counts_each_side_separately(self): found = scan(self._run()) self.assertEqual(found.matches, 1) self.assertEqual(found.side("sds North"), 1) self.assertEqual(found.hits("sds North"), 1) self.assertEqual(found.side("princess South"), 1) self.assertEqual(found.hits("princess South"), 0, "a miss is a swing, not a hit") def test_a_weapon_attack_is_not_a_physical(self): """The Medium Laser in the fixture is the whole point of it. A looser pattern - anything that "hits" - counts the gun as a kick and every rate this tool prints becomes a firing rate wearing melee's name. """ found = scan(self._run()) kinds = {kind for (_side, kind, _outcome) in found.swings} self.assertEqual(kinds, {"Kick", "Punch"}) def test_a_run_with_no_physicals_reads_nought_rather_than_failing(self): quiet = REPORT[: REPORT.index("Physical attacks")] + "