- versions: require entire normalized string to be numeric so dates and hotfix suffixes compare as incomparable instead of eq/gt - hosts: exact host or dot-suffix match rejects lookalikes like notmediafire.com and evilmega.nz; GitHub stays exact-set - census: lazy extractor loop so a later OSError no longer discards an earlier sidecar changelog hit - jobs: watchlist parses only table rows whose vault-note cell is a bare wikilink (skips parenthetical related/complete notes); wanted also matches bold names in Wanted.md tables with Pokemon prefix stripped and casefolded - cli: validate-scouts and judge raise SystemExit when jobs.json has jobs but scouts/ has zero valid files - fetch: download forwards timeout=60 to urlopen and writes to a .part file then os.replace, removing the partial on any failure
74 lines
3.2 KiB
Python
74 lines
3.2 KiB
Python
import hashlib, os, sys, tempfile, unittest, zipfile
|
|
from unittest.mock import patch
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
|
from update_swarm.census import census_job
|
|
|
|
FIX = os.path.join(os.path.dirname(__file__), "fixtures", "library")
|
|
|
|
def job(stem, note_version=None):
|
|
return {"stem": stem, "library_path": None, "note_version": note_version}
|
|
|
|
class TestCensus(unittest.TestCase):
|
|
def test_changelog_current_version_line(self):
|
|
rec = census_job(job("C"), os.path.join(FIX, "changelog-game", "dummy.bin"))
|
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
|
self.assertEqual(rec["source"], "file")
|
|
|
|
def test_game_ini_version(self):
|
|
rec = census_job(job("I"), os.path.join(FIX, "ini-game", "dummy.bin"))
|
|
self.assertEqual(rec["installed_version"], "1.74.1")
|
|
self.assertEqual(rec["source"], "file")
|
|
|
|
@patch(
|
|
"update_swarm.census.os.listdir",
|
|
return_value=["Game.ini", "changelog.txt", "dummy.bin"],
|
|
)
|
|
def test_sidecar_prefers_changelog_over_game_ini(self, _listdir):
|
|
rec = census_job(job("B"), os.path.join(FIX, "both-sidecars", "dummy.bin"))
|
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
|
self.assertEqual(rec["source"], "file")
|
|
self.assertEqual(rec["evidence"], "sidecar")
|
|
|
|
def test_filename_token(self):
|
|
rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip"))
|
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
|
|
|
def test_zip_inner_changelog(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
zpath = os.path.join(td, "game.zip")
|
|
with zipfile.ZipFile(zpath, "w") as z:
|
|
z.writestr("README.txt", "Current Version: 2.13\n")
|
|
rec = census_job(job("Z"), zpath)
|
|
self.assertEqual(rec["installed_version"], "2.13")
|
|
|
|
def test_note_fallback_then_unknown(self):
|
|
rec = census_job(job("X", note_version="9.9"), None)
|
|
self.assertEqual(rec["source"], "note")
|
|
self.assertEqual(rec["installed_version"], "9.9")
|
|
rec2 = census_job(job("Y"), None)
|
|
self.assertEqual(rec2["source"], "unknown")
|
|
self.assertIsNone(rec2["installed_version"])
|
|
|
|
@patch(
|
|
"update_swarm.census.os.listdir",
|
|
return_value=["changelog.txt", "dummy.bin"],
|
|
)
|
|
def test_rom_version_oserror_keeps_sidecar(self, _listdir):
|
|
# A later OSError must not discard an earlier sidecar hit.
|
|
with tempfile.TemporaryDirectory() as td:
|
|
cpath = os.path.join(td, "changelog.txt")
|
|
with open(cpath, "w", encoding="utf-8") as fh:
|
|
fh.write("Current Version: 3.3.1\n")
|
|
rom_path = os.path.join(td, "dummy.bin")
|
|
with open(rom_path, "wb") as fh:
|
|
fh.write(b"\x00")
|
|
with patch("update_swarm.census._rom_version", side_effect=OSError("boom")):
|
|
rec = census_job(job("S"), rom_path)
|
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
|
self.assertEqual(rec["source"], "file")
|
|
self.assertEqual(rec["evidence"], "sidecar")
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|