def empty_collection(self, item_cls, attached, attach_items): list_ = SyncedList(validation=_PartialIsInstance(item_cls), attach_members=attach_items) if attached: self._synced_list = [] list_._sync(DummySimulation(), self._synced_list) return list_
def test_value_add_and_attach(slist): op = DummyOperation() assert not slist._value_add_and_attach(op)._attached assert op._added slist._synced_list = [] slist._simulation = DummySimulation() op = DummyOperation() assert slist._value_add_and_attach(op)._attached assert op._added
def test_attaching(typedict_singleton_keys): sim = DummySimulation() cpp_obj = DummyCppObj() typedict_singleton_keys['A'] = dict(bar='first') typedict_singleton_keys['B'] = dict(bar='second') return AttachedTypeParameterDict(cpp_obj, param_name='type_param', type_kind='particle_types', type_param_dict=typedict_singleton_keys, sim=sim)
def test_apply_typeparam_dict(full_op): '''Tests _apply_typeparam_dict and by necessity getattr.''' full_op.type_param['A'] = dict(bar='world') full_op.type_param['B'] = dict(bar='hello') cpp_obj = DummyCppObj() full_op._cpp_obj = cpp_obj full_op._apply_typeparam_dict(cpp_obj, DummySimulation()) assert cpp_obj.getTypeParam('A') == dict(foo=1, bar='world') assert cpp_obj.getTypeParam('B') == dict(foo=1, bar='hello') return full_op
def test_attach(): triggered_op = DummyTriggeredOp(trigger=1) sim = DummySimulation() slist = SyncedList(lambda x: isinstance(x, DummyTriggeredOp), lambda x: (x._cpp_obj, x.trigger)) slist.append(triggered_op) triggered_op._cpp_obj = DummyCppObj() slist._sync(sim, sim._cpp_sys.dummy_list) assert len(sim._cpp_sys.dummy_list) == 1 assert len(sim._cpp_sys.dummy_list[0]) == 2 assert triggered_op._cpp_obj == sim._cpp_sys.dummy_list[0][0] assert triggered_op.trigger == sim._cpp_sys.dummy_list[0][1]
def test_attach(typeparam): return typeparam._attach(DummyCppObj(), DummySimulation().state)