From 632972ce3861ec11d17067ff0b414a65729438e7 Mon Sep 17 00:00:00 2001 From: Michael Wedel Date: Fri, 2 Jun 2017 15:13:16 +0200 Subject: [PATCH 1/3] Fix switch_setup bug --- lewis/core/adapters.py | 6 ++++++ lewis/core/simulation.py | 2 +- test/test_core_adapters.py | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lewis/core/adapters.py b/lewis/core/adapters.py index e73b3cac..4ab988e6 100644 --- a/lewis/core/adapters.py +++ b/lewis/core/adapters.py @@ -236,6 +236,12 @@ 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(): + print(adapter.protocol, adapter.interface) + adapter.interface.device = new_device + def add_adapter(self, adapter): """ Adds the supplied adapter to the container but raises a ``RuntimeError`` if there's diff --git a/lewis/core/simulation.py b/lewis/core/simulation.py index 4cf4e7d2..18648c49 100644 --- a/lewis/core/simulation.py +++ b/lewis/core/simulation.py @@ -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( diff --git a/test/test_core_adapters.py b/test/test_core_adapters.py index 77e93b9e..84b357a2 100644 --- a/test/test_core_adapters.py +++ b/test/test_core_adapters.py @@ -1,7 +1,7 @@ import inspect import unittest -from mock import Mock, MagicMock +from mock import Mock, MagicMock, PropertyMock, call, patch from lewis.core.adapters import Adapter, AdapterCollection, NoLock from lewis.core.exceptions import LewisException @@ -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') From 9b237e366d0f36815f1d78bcccc96a13f38810a2 Mon Sep 17 00:00:00 2001 From: Michael Wedel Date: Fri, 2 Jun 2017 15:30:39 +0200 Subject: [PATCH 2/3] Remove unused imports from test --- test/test_core_adapters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_core_adapters.py b/test/test_core_adapters.py index 84b357a2..b6526a41 100644 --- a/test/test_core_adapters.py +++ b/test/test_core_adapters.py @@ -1,7 +1,7 @@ import inspect import unittest -from mock import Mock, MagicMock, PropertyMock, call, patch +from mock import Mock, MagicMock from lewis.core.adapters import Adapter, AdapterCollection, NoLock from lewis.core.exceptions import LewisException From d0b4eb7678740ce6270efeae996cc48d8bcc50a9 Mon Sep 17 00:00:00 2001 From: Michael Wedel Date: Fri, 2 Jun 2017 16:17:06 +0200 Subject: [PATCH 3/3] Remove superfluous print statement --- lewis/core/adapters.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lewis/core/adapters.py b/lewis/core/adapters.py index 4ab988e6..31cb63aa 100644 --- a/lewis/core/adapters.py +++ b/lewis/core/adapters.py @@ -239,7 +239,6 @@ def device_lock(self): 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(): - print(adapter.protocol, adapter.interface) adapter.interface.device = new_device def add_adapter(self, adapter):