883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
56 lines
3.6 KiB
Python
56 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
import copy
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
sys.path.insert(0,str(Path(__file__).resolve().parent))
|
|
import quest_objective_locations as q
|
|
import quest_objective_locations_batch as b
|
|
from quest_objective_locations_test import snapshot
|
|
|
|
class BatchTest(unittest.TestCase):
|
|
def test_one_capture_per_table_no_mutation_and_shared_build(self):
|
|
quest=['60141','0','0','0','0','0','0','0','0','0','0','0','0','51868','0','0','0','8','0','0','0']
|
|
outputs=iter([([['1','fixture','host']],'server'),([quest],'quests'),
|
|
([['524','524','51868','-100','0','1','1','0']],'loot'),
|
|
([['524','524','0']],'templates'),
|
|
([['3','524','0','0','0','0','-9700','-10','40','2','1','0','0.5']],'spawns'),
|
|
([], 'pools'),([], 'template-pools'),([], 'events')]);queries=[]
|
|
def select(container,sql,maximum):
|
|
self.assertEqual(container,'fixture');self.assertEqual(maximum,b.LIMIT)
|
|
self.assertTrue(sql.startswith('SELECT '));self.assertNotIn(';',sql[:-1]);queries.append(sql)
|
|
return next(outputs)
|
|
with patch.object(q,'_select',side_effect=select):snap=b.capture_all('fixture')
|
|
self.assertEqual(len(queries),8);self.assertEqual(len(snap['source']['queries_sha256']),8)
|
|
self.assertEqual(sum('FROM creature WHERE' in x for x in queries),0)
|
|
result=q.build(snap,'hash',max_quests=b.QUEST_LIMIT,max_rows=b.LIMIT)
|
|
obj=result['quests'][0]['objectives'][0]
|
|
self.assertEqual((obj['presentation_index'],obj['native_storage_index'],obj['target']),(0,4,51868))
|
|
report=b.census(result);self.assertEqual(report['objectives_with_source_anchors'],1)
|
|
self.assertIn('no rows are native-ready',report['native_map_assignment_and_delivery'])
|
|
def test_many_quests_and_preserve_holds_indices(self):
|
|
s=snapshot();base=s['quests'][0]
|
|
s['quests']=[dict(copy.deepcopy(base),id=10000+i) for i in range(129)]
|
|
with self.assertRaisesRegex(ValueError,'quest bound'):q.build(s,'hash')
|
|
data=q.build(s,'hash',max_quests=b.QUEST_LIMIT,max_rows=b.LIMIT)
|
|
self.assertEqual(len(data['quests']),129);obj=data['quests'][0]['objectives'][-1]
|
|
self.assertEqual((obj['source_slot'],obj['native_storage_index'],obj['presentation_index']),(1,5,2))
|
|
for hold in ('source_quest_phase_condition_not_evaluated','source_spawn_pool_not_resolved',
|
|
'source_spawn_event_not_resolved','source_alternate_spawn_template_not_resolved',
|
|
'source_loot_condition_not_evaluated','source_visibility_modifier_not_evaluated',
|
|
'phase_and_native_uimap_assignment_not_resolved'):
|
|
self.assertIn(hold,obj['holds'])
|
|
self.assertEqual(b.census(data)['candidate_objectives_by_kind'],{'creature_or_gameobject':129,'item':129})
|
|
point=obj['clusters'][0]['points'][0]
|
|
b.compact(data);cluster=obj['clusters'][0]
|
|
self.assertNotIn('points',cluster)
|
|
self.assertIn([point['guid'],point['possible_creature_entries']],cluster['point_refs'])
|
|
self.assertIn('hash-pinned source snapshot',data['point_reference_semantics'])
|
|
def test_global_bounds_are_fail_closed(self):
|
|
with self.assertRaises(ValueError):q.build(snapshot(),'hash',max_rows=1000001)
|
|
with self.assertRaises(ValueError):q.build(snapshot(),'hash',max_quests=10001)
|
|
with self.assertRaises(ValueError):q.build(snapshot(),'hash',max_rows=1)
|
|
if __name__=='__main__':unittest.main()
|