def get_composite_from_store(store: Store) -> Composite: """Make a :term:`Composite` from a :term:`Store`""" return Composite( processes=store.get_processes(), topology=store.get_topology(), steps=store.get_steps(), flow=store.get_flow(), state=store.get_value(), )
def test_disconnected_store_failure() -> None: """Test that inserting a Store into the tree results in an exception""" store = get_toy_store() with pytest.raises(Exception): store['ddd'] = Store({}) store['process1', 'port1'] = store['store_D'] with pytest.raises(Exception): store['process1', 'port1'] = Store({'_value': 'NEW STORE'})
def test_run_inserted_store() -> None: """Make a store using the API, run it as a simulation""" store = Store({}) store["p1"] = ToyProcess({'name': 'p1'}) store["p2"] = ToyProcess({'name': 'p2'}) sim = Engine(store=store) sim.update(1.0)
def test_run_rewired_store() -> None: """Make a store using the API, run it as a simulation""" store = Store({}) store["p1"] = ToyProcess({'name': 'p1'}) store["p2"] = ToyProcess({'name': 'p2'}) store["p1"].connect(('port1', ), store['p2', "port2"]) sim = Engine(store=store) sim.update(1.0)
def test_port_connect() -> None: # create the root store = Store({}) # create a new store at a path store.create(['top', 'store1']) store.create(['top', 'store2']) # create a process at a path store.create(['top', 'process1'], ToyProcess({})) store.create(['top', 'process2'], ToyProcess({})) # connect port using a relative path store['top', 'process1'].connect('port1', 'store1') # connect using store target through a different port store['top', 'process1'].connect('port2', store['top', 'process1', 'port1']) # connect using absolute path store['top', 'process1'].connect('port2', ('top', 'store2'), absolute=True) assert store['top', 'process1'].topology == { 'port1': ('store1', ), 'port2': ('store2', ) }
def test_divide_store() -> None: store = Store({}) store.create(['top', 'process1'], ToyProcess({})) store.create(['top', 'store1', 'X']) store['top', 'process1'].connect('port1', 'store1') # divide store1 into two daughters store['top'].divide({ 'mother': 'store1', 'daughters': [{ 'key': 'store2' }, { 'key': 'store3' }] }) final_state = store.get_value() assert 'store2' in final_state['top'] assert 'store3' in final_state['top'] assert 'store1' not in final_state['top']
def test_update_schema() -> None: store = Store({}) store.create(['top', 'process1'], ToyProcess({})) store.create(['top', 'store1'], _updater='set') assert store['top', 'store1'].updater == 'set', \ 'updater is not set correctly'
def test_recursive_store() -> None: environment_config = { 'environment': { 'temperature': { '_default': 0.0, '_updater': 'accumulate' }, 'fields': { (0, 1): { 'enzymeX': { '_default': 0.0, '_updater': 'set' }, 'enzymeY': { '_default': 0.0, '_updater': 'set' } }, (0, 2): { 'enzymeX': { '_default': 0.0, '_updater': 'set' }, 'enzymeY': { '_default': 0.0, '_updater': 'set' } } }, 'agents': { '1': { 'location': { '_default': (0, 0), '_updater': 'set' }, 'boundary': { 'external': { '_default': 0.0, '_updater': 'set' }, 'internal': { '_default': 0.0, '_updater': 'set' } }, 'transcripts': { 'flhDC': { '_default': 0, '_updater': 'accumulate' }, 'fliA': { '_default': 0, '_updater': 'accumulate' } }, 'proteins': { 'ribosome': { '_default': 0, '_updater': 'set' }, 'flagella': { '_default': 0, '_updater': 'accumulate' } } }, '2': { 'location': { '_default': (0, 0), '_updater': 'set' }, 'boundary': { 'external': { '_default': 0.0, '_updater': 'set' }, 'internal': { '_default': 0.0, '_updater': 'set' } }, 'transcripts': { 'flhDC': { '_default': 0, '_updater': 'accumulate' }, 'fliA': { '_default': 0, '_updater': 'accumulate' } }, 'proteins': { 'ribosome': { '_default': 0, '_updater': 'set' }, 'flagella': { '_default': 0, '_updater': 'accumulate' } } } } } } state = Store(environment_config) state.apply_update({}) state.state_for(['environment'], ['temperature'])