MC/tools/test_quest_npc_pack.py

24 lines
1.6 KiB
Python

"""Verify the original published fauna artwork is unchanged in quest NPC packs."""
import hashlib, importlib.util, json, os, pathlib, tempfile, unittest, zipfile
ROOT=pathlib.Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('npc',ROOT/'tools/build-quest-npc-pack.py')
npc=importlib.util.module_from_spec(spec);spec.loader.exec_module(npc)
class NPCPackTest(unittest.TestCase):
@unittest.skipUnless(os.environ.get('DUNE_NPC_BASELINE_DIR'),'published PR606 archives required')
def test_exact_additive_pack(self):
baseline=pathlib.Path(os.environ['DUNE_NPC_BASELINE_DIR'])
with tempfile.TemporaryDirectory() as tmp:
output=pathlib.Path(tmp);manifest=npc.build(baseline,output)
self.assertEqual(manifest,json.loads((ROOT/'network/content-assets/npc-skins/manifest.json').read_text()))
for scope,record in manifest['base'].items():
old=npc.OLD['base'][scope];path=output/record['filename']
self.assertEqual(hashlib.sha256(path.read_bytes()).hexdigest(),record['sha256'])
with zipfile.ZipFile(baseline/old['filename']) as before,zipfile.ZipFile(path) as after:
self.assertIsNone(after.testzip())
self.assertTrue(all(before.read(n)==after.read(n) for n in before.namelist()))
additions=set(after.namelist())-set(before.namelist())
self.assertEqual(additions,{f'assets/dunerealms/textures/entity/npc/{p.name}' for p in npc.SKINS.glob('*.png')})
self.assertEqual(len(additions),18)
if __name__=='__main__':unittest.main()