class HardwareLayer(object): """main hardware layer class""" def __init__(self, package_manager=None, hardware_poll_frequency=3): self._package_manager = package_manager self._driver_manager = DriverManager(hardware_poll_frequency) def setup(self): pass def teardown(self): pass @defer.inlineCallbacks def add_driver(self, driver_type=None, driver_params=None): if driver_type is None: raise UnknownDriver() plugins = (yield self._package_manager.get_plugins(ipollapli.IDriver)) driver = None for driver_class in plugins: if driver_type == driver_class.__name__.lower(): driver = self._driver_manager.add_driver(driver_class, **driver_params) break if not driver: raise UnknownDriver() @defer.inlineCallbacks def get_driver_types(self): driver_types_tmp = yield PackageManager.get_plugins(ipollapli.IDriver) driver_types = [driver_type_inst() for driver_type_inst in driver_types_tmp] defer.returnValue(driver_types)
def setUp(self): self._driverManager = DriverManager()
class TestDriverManager(unittest.TestCase): def setUp(self): self._driverManager = DriverManager() def tearDown(self): pass def test_add_driver(self): driver_class = MockDriver exp_driver = MockDriver() obs_driver = self._driverManager.add_driver(driver_class) self.assertEquals(obs_driver, exp_driver) def test_get_driver(self): driver_class = MockDriver exp_driver = self._driverManager.add_driver(driver_class) obs_driver = self._driverManager.get_driver(driver_id=exp_driver.cid) self.assertEquals(obs_driver, exp_driver) @defer.inlineCallbacks def test_get_drivers(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) l_exp_drivers = sorted([exp_driver1, exp_driver2]) l_obs_drivers = sorted((yield self._driverManager.get_drivers())) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_get_drivers_filtered(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) l_exp_drivers = sorted([exp_driver1, exp_driver2]) l_obs_drivers = sorted((yield self._driverManager.get_drivers( {"cid": [exp_driver1.cid, exp_driver2.cid]}))) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_delete_driver(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) yield self._driverManager.delete_driver(exp_driver2.cid) l_exp_drivers = sorted([exp_driver1]) l_obs_drivers = sorted((yield self._driverManager.get_drivers())) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_clear_drivers(self): driver_class = MockDriver self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) yield self._driverManager.clear_drivers() l_exp_drivers = [] l_obs_drivers = yield self._driverManager.get_drivers() self.assertEquals(l_exp_drivers, l_obs_drivers) # @defer.inlineCallbacks # def test_get_unbound_ports(self): # driver_class = MockDriver # driver = self._driverManager.add_driver(driver_class) # MockHardwareInterface.available_ports = ["port1"] # yield self._driverManager.update_device_list() # obs_ubound_ports = self._driverManager.get_unbound_ports(driver.hardware_interface_class) # exp_ubound_ports = ["port1"] # self.assertEquals(obs_ubound_ports, exp_ubound_ports) # def test_connect_driver(self): # driver_class = MockDriver # MockHardwareInterface.available_ports = ["port1"] # driver = self._driverManager.add_driver(driver_class) # self._driverManager.connect_to_hardware(driver_id = driver.cid, connection_mode=1) def test_disconnect_driver(self): pass def test_upload_firmware(self): pass
def setUp(self): # self.observer = log.PythonLoggingObserver() # self.observer.start() self._driverManager = DriverManager()
class TestDriverManagerExampleArduinoDriver(unittest.TestCase): def setUp(self): # self.observer = log.PythonLoggingObserver() # self.observer.start() self._driverManager = DriverManager() def tearDown(self): self._driverManager.teardown() # self.observer.stop() @defer.inlineCallbacks def test_binding(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver( driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", connection_timeout=3) yield self._driverManager.update_device_list() self.assertTrue(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_no_id_doauth(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, connection_timeout=2) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_id_noauth(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver( driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", do_authentification=False, connection_timeout=2) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_id_doauth_timeout(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver( driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", connection_timeout=0.1) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_connect_hardware_forced_noport(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, connection_timeout=2) yield self._driverManager.update_device_list() deferred = self._driverManager.connect_to_hardware(driver.cid, port=None, connection_mode=2) self.assertFailure(deferred, Exception)
def __init__(self, package_manager=None, hardware_poll_frequency=3): self._package_manager = package_manager self._driver_manager = DriverManager(hardware_poll_frequency)
class TestDriverManagerExampleArduinoDriver(unittest.TestCase): def setUp(self): # self.observer = log.PythonLoggingObserver() # self.observer.start() self._driverManager = DriverManager() def tearDown(self): self._driverManager.teardown() # self.observer.stop() @defer.inlineCallbacks def test_binding(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", connection_timeout=3) yield self._driverManager.update_device_list() self.assertTrue(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_no_id_doauth(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, connection_timeout=2) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_id_noauth(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", do_authentification=False, connection_timeout=2) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_binding_failure_id_doauth_timeout(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, hardware_id="72442ba3-058c-4cee-a060-5d7c644f1dbe", connection_timeout=0.1) yield self._driverManager.update_device_list() self.assertFalse(driver.is_bound) @defer.inlineCallbacks def test_connect_hardware_forced_noport(self): driver_class = ExampleArduinoDriver driver = self._driverManager.add_driver(driver_class, connection_timeout=2) yield self._driverManager.update_device_list() deferred = self._driverManager.connect_to_hardware(driver.cid, port=None, connection_mode=2) self.assertFailure(deferred,Exception)
class TestDriverManager(unittest.TestCase): def setUp(self): self._driverManager = DriverManager() def tearDown(self): pass def test_add_driver(self): driver_class = MockDriver exp_driver = MockDriver() obs_driver = self._driverManager.add_driver(driver_class) self.assertEquals(obs_driver, exp_driver) def test_get_driver(self): driver_class = MockDriver exp_driver = self._driverManager.add_driver(driver_class) obs_driver = self._driverManager.get_driver(driver_id=exp_driver.cid) self.assertEquals(obs_driver, exp_driver) @defer.inlineCallbacks def test_get_drivers(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) l_exp_drivers = sorted([exp_driver1, exp_driver2]) l_obs_drivers = sorted((yield self._driverManager.get_drivers())) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_get_drivers_filtered(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) l_exp_drivers = sorted([exp_driver1, exp_driver2]) l_obs_drivers = sorted((yield self._driverManager.get_drivers({"cid": [exp_driver1.cid, exp_driver2.cid]}))) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_delete_driver(self): driver_class = MockDriver exp_driver1 = self._driverManager.add_driver(driver_class) exp_driver2 = self._driverManager.add_driver(driver_class) yield self._driverManager.delete_driver(exp_driver2.cid) l_exp_drivers = sorted([exp_driver1]) l_obs_drivers = sorted((yield self._driverManager.get_drivers())) self.assertEquals(l_exp_drivers, l_obs_drivers) @defer.inlineCallbacks def test_clear_drivers(self): driver_class = MockDriver self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) self._driverManager.add_driver(driver_class) yield self._driverManager.clear_drivers() l_exp_drivers = [] l_obs_drivers = yield self._driverManager.get_drivers() self.assertEquals(l_exp_drivers, l_obs_drivers) # @defer.inlineCallbacks # def test_get_unbound_ports(self): # driver_class = MockDriver # driver = self._driverManager.add_driver(driver_class) # MockHardwareInterface.available_ports = ["port1"] # yield self._driverManager.update_device_list() # obs_ubound_ports = self._driverManager.get_unbound_ports(driver.hardware_interface_class) # exp_ubound_ports = ["port1"] # self.assertEquals(obs_ubound_ports, exp_ubound_ports) # def test_connect_driver(self): # driver_class = MockDriver # MockHardwareInterface.available_ports = ["port1"] # driver = self._driverManager.add_driver(driver_class) # self._driverManager.connect_to_hardware(driver_id = driver.cid, connection_mode=1) def test_disconnect_driver(self): pass def test_upload_firmware(self): pass