plugins/tools/test_fauna_pack_update.py
2026-11-27 23:43:05 +00:00

40 lines
2.6 KiB
Python

"""Verify the candidate is a narrow immutable extension of the published pack."""
import hashlib, importlib.util, json, os, pathlib, tempfile, unittest, zipfile
ROOT=pathlib.Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('fauna',ROOT/'tools/build-fauna-pack-update.py')
fauna=importlib.util.module_from_spec(spec);spec.loader.exec_module(fauna)
class FaunaPackTest(unittest.TestCase):
def test_item_asset_pairs_resolve_and_chicken_stays_in_planet_layer(self):
base=fauna.add_items({'untouched':b'original'})
self.assertEqual(base['untouched'],b'original')
self.assertEqual(len(base),1+3*len(fauna.ITEMS))
for name in fauna.ITEMS:
root='assets/dunerealms/'
self.assertTrue(base[root+f'textures/item/ecology/{name}.png'].startswith(b'\x89PNG'))
self.assertEqual(json.loads(base[root+f'items/ecology/{name}.json'])['model']['model'],f'dunerealms:item/ecology/{name}')
self.assertFalse(any('textures/entity/chicken' in p for p in base))
planet=fauna.arrakis({'untouched':b'original'})
self.assertEqual(planet['untouched'],b'original')
self.assertTrue(any('textures/entity/chicken' in p for p in planet))
for name in fauna.JERBOAS:
model=json.loads(planet[f'assets/dunerealms/models/entity/{name}.json'])
self.assertGreaterEqual(len(model['elements']),8)
self.assertIn('particle',model['textures'])
@unittest.skipUnless(os.environ.get('DUNE_FAUNA_BASELINE_DIR'),'published PR605 archives required')
def test_candidate_hashes_and_exact_unchanged_entries(self):
baseline=pathlib.Path(os.environ['DUNE_FAUNA_BASELINE_DIR'])
with tempfile.TemporaryDirectory() as tmp:
output=pathlib.Path(tmp);manifest=fauna.build(baseline,output)
self.assertEqual(manifest,json.loads((ROOT/'DuneRealmsGUI/fauna-pack/manifest.json').read_text()))
for category in ('base','planets'):
for scope,record in manifest[category].items():
path=output/record['filename'];self.assertEqual(hashlib.sha256(path.read_bytes()).hexdigest(),record['sha256'])
old=fauna.OLD[category][scope]
entries=fauna.repair.read_pack(baseline/old['filename'],old['sha256'])
expected=fauna.add_items(entries) if category=='base' else fauna.arrakis(entries)
with zipfile.ZipFile(path) as z:
self.assertIsNone(z.testzip());self.assertEqual({n:z.read(n) for n in z.namelist()},expected)
if __name__=='__main__':unittest.main()