Skip to content

Commit

Permalink
Merge pull request #244 from DMSC-Instrument-Data/241_fix_switch_setup
Browse files Browse the repository at this point in the history
Fix switch_setup bug
  • Loading branch information
MikeHart85 authored Jun 2, 2017
2 parents 543685c + d0b4eb7 commit 7aaf69f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lewis/core/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def device_lock(self):
"""
return self._lock

def set_device(self, new_device):
"""Bind the new device to all interfaces managed by the adapters in the collection."""
for adapter in self._adapters.values():
adapter.interface.device = new_device

def add_adapter(self, adapter):
"""
Adds the supplied adapter to the container but raises a ``RuntimeError`` if there's
Expand Down
2 changes: 1 addition & 1 deletion lewis/core/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def switch_setup(self, new_setup):
"""
try:
self._device = self._device_builder.create_device(new_setup)
self._adapters.device = self._device
self._adapters.set_device(self._device)
self.log.info('Switched setup to \'%s\'', new_setup)
except Exception as e:
self.log.error(
Expand Down
9 changes: 9 additions & 0 deletions test/test_core_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ def test_configuration(self):
{
'protocol_b': {'bar': True, 'foo': False},
})

def test_set_device(self):
adapter = DummyAdapter(protocol='foo')
adapter.interface = MagicMock()

collection = AdapterCollection(adapter)
collection.set_device('test')

self.assertEqual(adapter.interface.device, 'test')

0 comments on commit 7aaf69f

Please sign in to comment.