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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7821c6ad71
commit
aedddc35b1
1 file changed
+22
-20
@@ -173,8 +173,10 @@ def bodies_and_jets(speed=.002):
|
|||||||
return bodies,jets
|
return bodies,jets
|
||||||
|
|
||||||
|
|
||||||
KW=dict(base_block=(4,4),fine_block=(4,4),child_block=(4,4),
|
def levels(parents=PARENTS,children=CHILDREN,blocks=((4,4),)*3,objects=((),(),()),jets=((),(),())):
|
||||||
child_rectangles_in_parent=CHILDREN)
|
"""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):
|
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
|
module.cuda.memcpy_htod.side_effect=upload
|
||||||
objects,jets=bodies_and_jets() if bodies else ((),())
|
objects,jets=bodies_and_jets() if bodies else ((),())
|
||||||
try:
|
try:
|
||||||
run=module.FixedPatchStepper(CFG,PARENTS,context=context,
|
run=module.FixedPatchStepper(CFG,context=context,
|
||||||
child_objects=objects,child_jets=jets,
|
**levels(children=children,objects=((),(),objects),jets=((),(),jets)))
|
||||||
**dict(KW,child_rectangles_in_parent=children))
|
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
for allocation in allocations:
|
for allocation in allocations:
|
||||||
allocation.free.assert_called_once_with()
|
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):
|
class ConstructorAndSchedule(unittest.TestCase):
|
||||||
def test_invalid_inputs_fail_before_context_or_allocations(self):
|
def test_invalid_inputs_fail_before_context_or_allocations(self):
|
||||||
context=Mock()
|
context=Mock()
|
||||||
cases=[dict(child=(8,8,16,16)),dict(child_rectangles_in_parent=[]),
|
b=(4,4)
|
||||||
dict(child_rectangles_in_parent=[(16,16,32)]),
|
cases=[dict(children=(8,8,16,16)),dict(children=[]),
|
||||||
dict(child_rectangles_in_parent=[(16.5,16,32,40)]),
|
dict(children=[(16,16,32)]),
|
||||||
dict(child_rectangles_in_parent=[(16,16,32,24),(16,27,32,55)]),
|
dict(children=[(16.5,16,32,40)]),
|
||||||
dict(child_rectangles_in_parent=[(40,16,48,40)]),
|
dict(children=[(16,16,32,24),(16,27,32,55)]),
|
||||||
dict(child_rectangles_in_parent=[(8,16,32,40)]),
|
dict(children=[(40,16,48,40)]),
|
||||||
dict(child_block=None),dict(fine_block=None),dict(base_block=None),
|
dict(children=[(8,16,32,40)]),
|
||||||
dict(child_block=(5,4)),dict(fine_block=(5,4)),
|
dict(blocks=(b,b,None)),dict(blocks=(b,None,b)),dict(blocks=(None,b,b)),
|
||||||
dict(child_block=(4,)),dict(child_rectangles_in_parent=(16,16,32,40))]
|
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:
|
for changes in cases:
|
||||||
with self.subTest(changes=changes),self.assertRaises((ValueError,TypeError)):
|
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'):
|
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()
|
objects,jets=bodies_and_jets()
|
||||||
with self.assertRaisesRegex(ValueError,'only on L2'):
|
with self.assertRaisesRegex(ValueError,'only on the finest level'):
|
||||||
host.FixedPatchStepper(CFG,PARENTS,context=context,fine_objects=objects,**KW)
|
host.FixedPatchStepper(CFG,context=context,**levels(objects=((),objects,())))
|
||||||
from CelerisLab.body.jets import Jet,Tube,Parallel
|
from CelerisLab.body.jets import Jet,Tube,Parallel
|
||||||
spanning=Jet(Tube((10.5,14.),0.,25.,.3),Parallel(0.),amplitude=0.)
|
spanning=Jet(Tube((10.5,14.),0.,25.,.3),Parallel(0.),amplitude=0.)
|
||||||
with self.assertRaisesRegex(ValueError,'one jet'):
|
with self.assertRaisesRegex(ValueError,'one jet'):
|
||||||
host.FixedPatchStepper(CFG,PARENTS,context=context,child_objects=objects,
|
host.FixedPatchStepper(CFG,context=context,
|
||||||
child_jets=[spanning],**KW)
|
**levels(objects=((),(),objects),jets=((),(),[spanning])))
|
||||||
context.activate.assert_not_called()
|
context.activate.assert_not_called()
|
||||||
host.cuda.mem_alloc.assert_not_called()
|
host.cuda.mem_alloc.assert_not_called()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user