883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
137 lines
5.5 KiB
Python
137 lines
5.5 KiB
Python
from copy import deepcopy
|
|
import json
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
import spell_item_enchantment_compat as subject
|
|
|
|
FIXTURE = Path(__file__).parent / 'fixtures/item-permanent-enchantment.json'
|
|
|
|
class PermanentEnchantment(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.fixture = json.loads(FIXTURE.read_text())
|
|
|
|
def setUp(self):
|
|
self.data = deepcopy(self.fixture)
|
|
self.source = self.data['sources'][1]
|
|
|
|
def review(self):
|
|
return subject.positive(self.source, self.data['native'],
|
|
semantics=self.data['semantics'],
|
|
scalar_children=self.data['scalar_children'])
|
|
|
|
def row(self, table):
|
|
return next(r for r in self.data['native'][table]
|
|
if (r['ID'] if table in ('Spell', 'SpellName') else r['SpellID']) == self.source['entry'])
|
|
|
|
def test_all_22_captured_positive_contexts(self):
|
|
for source in self.data['sources']:
|
|
with self.subTest(spell=source['entry']):
|
|
self.source = source
|
|
result, _ = self.review()
|
|
self.assertEqual(result['source_enchantment_id'], source['effectMiscValue1'])
|
|
self.assertFalse(result['engine_accepted'])
|
|
|
|
def test_unreviewed_child_does_not_admit_parent(self):
|
|
self.data['scalar_children'].remove(self.source['effectMiscValue1'])
|
|
with self.assertRaisesRegex(ValueError, 'scalar enchantment child'):
|
|
self.review()
|
|
|
|
def test_source_second_effect_never_ignored(self):
|
|
self.source['effect2'] = 6
|
|
with self.assertRaises(ValueError):
|
|
self.review()
|
|
|
|
def test_source_script_condition_never_ignored(self):
|
|
self.source['script_name'] = 'unreviewed'
|
|
with self.assertRaises(ValueError):
|
|
self.review()
|
|
|
|
def test_unused_source_column_cannot_replace_condition(self):
|
|
self.source['unreviewed'] = self.source.pop('stancesNot')
|
|
with self.assertRaisesRegex(ValueError, 'Complete captured'):
|
|
self.review()
|
|
|
|
def test_temporary_enchant_is_distinct(self):
|
|
self.source['effect1'] = 54
|
|
with self.assertRaises(ValueError):
|
|
self.review()
|
|
|
|
def test_no_nondefault_damage_coefficient(self):
|
|
self.source['effectBonusCoefficient1'] = 1
|
|
with self.assertRaises(ValueError):
|
|
self.review()
|
|
|
|
def test_native_extra_effect_fails_after_valid_first(self):
|
|
extra = dict(self.row('SpellEffect'), ID=2147483000, EffectIndex=1, Effect=3)
|
|
self.data['native']['SpellEffect'].append(extra)
|
|
with self.assertRaisesRegex(ValueError, 'duplicate'):
|
|
self.review()
|
|
|
|
def test_native_wrong_enchant_child(self):
|
|
self.row('SpellEffect')['EffectMiscValue'][0] += 1
|
|
with self.assertRaisesRegex(ValueError, 'effect differs'):
|
|
self.review()
|
|
|
|
def test_native_conditions_are_not_erased(self):
|
|
self.row('SpellTargetRestrictions')['TargetCreatureType'] = 1
|
|
with self.assertRaisesRegex(ValueError, 'context differs'):
|
|
self.review()
|
|
|
|
def test_native_attribute_difference_is_not_cleared(self):
|
|
self.row('SpellMisc')['Attributes'][1] = 1024
|
|
with self.assertRaisesRegex(ValueError, 'attribute semantics'):
|
|
self.review()
|
|
|
|
def test_native_equipment_subclass_is_exact(self):
|
|
self.row('SpellEquippedItems')['EquippedItemSubclass'] ^= 1
|
|
with self.assertRaisesRegex(ValueError, 'context differs'):
|
|
self.review()
|
|
|
|
def test_native_unknown_effect_column_is_held(self):
|
|
self.row('SpellEffect')['FutureColumn'] = 0
|
|
with self.assertRaisesRegex(ValueError, 'effect differs'):
|
|
self.review()
|
|
|
|
def test_missing_native_parent_is_not_synthesized(self):
|
|
self.data['native']['SpellName'].remove(self.row('SpellName'))
|
|
with self.assertRaisesRegex(ValueError, 'Missing'):
|
|
self.review()
|
|
|
|
def test_native_visual_conditions_are_held(self):
|
|
self.row('SpellXSpellVisual')['CasterPlayerConditionID'] = 1
|
|
with self.assertRaisesRegex(ValueError, 'context differs'):
|
|
self.review()
|
|
|
|
def test_source_boolean_is_not_integer(self):
|
|
self.source['effectMiscValue1'] = True
|
|
with self.assertRaisesRegex(ValueError, 'scalar'):
|
|
self.review()
|
|
|
|
def test_enum_arithmetic_cannot_fabricate_literal_equality(self):
|
|
for initializer in ('53 + 1', '53 | 1', '530'):
|
|
with self.subTest(initializer=initializer):
|
|
text = 'enum X { SPELL_EFFECT_ENCHANT_ITEM = ' + initializer + ', };'
|
|
if initializer == '530':
|
|
self.assertNotEqual(subject.literal(text, 'SPELL_EFFECT_ENCHANT_ITEM'), 53)
|
|
else:
|
|
with self.assertRaises(ValueError):
|
|
subject.literal(text, 'SPELL_EFFECT_ENCHANT_ITEM')
|
|
|
|
def test_commented_enum_is_not_the_semantic_witness(self):
|
|
text = '// SPELL_EFFECT_ENCHANT_ITEM = 53,\nenum X { SPELL_EFFECT_ENCHANT_ITEM = 54, };'
|
|
self.assertEqual(subject.literal(text, 'SPELL_EFFECT_ENCHANT_ITEM'), 54)
|
|
|
|
def test_duplicate_enum_witness_is_not_unique(self):
|
|
with self.assertRaisesRegex(ValueError, 'Unique'):
|
|
subject.literal('enum A { X = 53, }; enum B { X = 53, };', 'X')
|
|
|
|
def test_contract_mutation_is_not_name_only_admission(self):
|
|
self.data['semantics']['contract']['native_effect'] = 54
|
|
with self.assertRaisesRegex(ValueError, 'contract'):
|
|
self.review()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|