From aedddc35b1fbbea7e7a9c3ea10af64f1cefe4228 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 01:46:06 +0000 Subject: [PATCH] P1 (3/n): three-level multipatch unit tests use the level-list constructor KW (legacy base/fine/child blocks + child_rectangles_in_parent) becomes levels(): refinements=[PARENTS, CHILDREN], level_blocks, level_objects, level_jets. Every negative case is kept and expressed per level (child rectangles, per-level blocks); the L1-body case now expects the level-list rule's message 'only on the finest level' instead of the legacy keyword message 'only on L2' (same constraint). Co-Authored-By: Claude Opus 5.5 --- .../test_refinement_three_level_multipatch.py | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/unit/test_refinement_three_level_multipatch.py b/tests/unit/test_refinement_three_level_multipatch.py index a66f17b..b11df01 100644 --- a/tests/unit/test_refinement_three_level_multipatch.py +++ b/tests/unit/test_refinement_three_level_multipatch.py @@ -173,8 +173,10 @@ def bodies_and_jets(speed=.002): return bodies,jets -KW=dict(base_block=(4,4),fine_block=(4,4),child_block=(4,4), - child_rectangles_in_parent=CHILDREN) +def levels(parents=PARENTS,children=CHILDREN,blocks=((4,4),)*3,objects=((),(),()),jets=((),(),())): + """Level-list constructor keywords for the L0 set, L1 set and L2 set used here.""" + return dict(refinements=[parents,children],level_blocks=list(blocks), + level_objects=list(objects),level_jets=list(jets)) def mock_backend(*, children=CHILDREN, bodies=False, fail_compile=False, fail_upload=False): @@ -201,9 +203,8 @@ def mock_backend(*, children=CHILDREN, bodies=False, fail_compile=False, fail_up module.cuda.memcpy_htod.side_effect=upload objects,jets=bodies_and_jets() if bodies else ((),()) try: - run=module.FixedPatchStepper(CFG,PARENTS,context=context, - child_objects=objects,child_jets=jets, - **dict(KW,child_rectangles_in_parent=children)) + run=module.FixedPatchStepper(CFG,context=context, + **levels(children=children,objects=((),(),objects),jets=((),(),jets))) except RuntimeError: for allocation in allocations: allocation.free.assert_called_once_with() @@ -214,28 +215,29 @@ def mock_backend(*, children=CHILDREN, bodies=False, fail_compile=False, fail_up class ConstructorAndSchedule(unittest.TestCase): def test_invalid_inputs_fail_before_context_or_allocations(self): context=Mock() - cases=[dict(child=(8,8,16,16)),dict(child_rectangles_in_parent=[]), - dict(child_rectangles_in_parent=[(16,16,32)]), - dict(child_rectangles_in_parent=[(16.5,16,32,40)]), - dict(child_rectangles_in_parent=[(16,16,32,24),(16,27,32,55)]), - dict(child_rectangles_in_parent=[(40,16,48,40)]), - dict(child_rectangles_in_parent=[(8,16,32,40)]), - dict(child_block=None),dict(fine_block=None),dict(base_block=None), - dict(child_block=(5,4)),dict(fine_block=(5,4)), - dict(child_block=(4,)),dict(child_rectangles_in_parent=(16,16,32,40))] + b=(4,4) + cases=[dict(children=(8,8,16,16)),dict(children=[]), + dict(children=[(16,16,32)]), + dict(children=[(16.5,16,32,40)]), + dict(children=[(16,16,32,24),(16,27,32,55)]), + dict(children=[(40,16,48,40)]), + dict(children=[(8,16,32,40)]), + dict(blocks=(b,b,None)),dict(blocks=(b,None,b)),dict(blocks=(None,b,b)), + dict(blocks=(b,b,(5,4))),dict(blocks=(b,(5,4),b)), + dict(blocks=(b,b,(4,))),dict(children=(16,16,32,40))] for changes in cases: with self.subTest(changes=changes),self.assertRaises((ValueError,TypeError)): - host.FixedPatchStepper(CFG,PARENTS,context=context,**dict(KW,**changes)) + host.FixedPatchStepper(CFG,context=context,**levels(**changes)) with self.assertRaisesRegex(ValueError,'margin'): - host.FixedPatchStepper(CFG,[(1,4,20,28),(23,4,44,28)],context=context,**KW) + host.FixedPatchStepper(CFG,context=context,**levels(parents=[(1,4,20,28),(23,4,44,28)])) objects,jets=bodies_and_jets() - with self.assertRaisesRegex(ValueError,'only on L2'): - host.FixedPatchStepper(CFG,PARENTS,context=context,fine_objects=objects,**KW) + with self.assertRaisesRegex(ValueError,'only on the finest level'): + host.FixedPatchStepper(CFG,context=context,**levels(objects=((),objects,()))) from CelerisLab.body.jets import Jet,Tube,Parallel spanning=Jet(Tube((10.5,14.),0.,25.,.3),Parallel(0.),amplitude=0.) with self.assertRaisesRegex(ValueError,'one jet'): - host.FixedPatchStepper(CFG,PARENTS,context=context,child_objects=objects, - child_jets=[spanning],**KW) + host.FixedPatchStepper(CFG,context=context, + **levels(objects=((),(),objects),jets=((),(),[spanning]))) context.activate.assert_not_called() host.cuda.mem_alloc.assert_not_called()