27 lines
1.7 KiB
Python
27 lines
1.7 KiB
Python
import copy,sys,unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/"ops"))
|
|
from spell_modifier_class_metadata import prepare
|
|
class Metadata(unittest.TestCase):
|
|
def setUp(self):
|
|
self.source=[dict(id=10,family=6,mask=2),dict(id=11,family=6,mask=4)]
|
|
self.native=[dict(ID=100,SpellID=10,SpellClassSet=6,SpellClassMask=[2,0,0,0],ModalNextSpell=8)]
|
|
self.closure={i:dict(spell_id=i,complete=True) for i in (10,11)}
|
|
def test_missing_family_row_is_added_without_copying_source_bits(self):
|
|
original=copy.deepcopy(self.native);p=prepare(self.source,self.native,self.closure,[10,11])
|
|
self.assertEqual(p["rows"][0],original[0]);self.assertEqual(self.native,original)
|
|
self.assertEqual(p["rows"][1],dict(ID=101,SpellID=11,SpellClassSet=6,SpellClassMask=[0,0,0,0],ModalNextSpell=0))
|
|
def test_id_allocation_considers_other_families(self):
|
|
self.native.append(dict(ID=900,SpellID=999,SpellClassSet=3,SpellClassMask=[1,0,0,0],ModalNextSpell=0))
|
|
self.assertEqual(prepare(self.source,self.native,self.closure,[11])["added_ids"],[901])
|
|
def test_known_family_correction_preserves_original_mask_and_fields(self):
|
|
self.native[0]["SpellClassSet"]=0
|
|
with self.assertRaises(ValueError):prepare(self.source,self.native,self.closure,[10])
|
|
p=prepare(self.source,self.native,self.closure,[10],family_corrections={10:0})
|
|
expected=dict(self.native[0],SpellClassSet=6);self.assertEqual(p["rows"],[expected])
|
|
def test_incomplete_definition_or_duplicate_parent_is_refused(self):
|
|
self.closure[11]["complete"]=False
|
|
with self.assertRaises(ValueError):prepare(self.source,self.native,self.closure,[11])
|
|
with self.assertRaises(ValueError):prepare(self.source,self.native*2,self.closure,[10])
|
|
if __name__=="__main__":unittest.main()
|