def test_configure(self): """Driver configuration tests""" channels = Some.VALID_CHANNELS + Some.INVALID_CHANNELS mi_logger.debug("\n configure: %s" % str(channels)) configs = {} for c in channels: configs[c] = { "method": "ethernet", "device_addr": "1.1.1.1", "device_port": 1, "server_addr": "2.2.2.2", "server_port": 2, } result = self.driver.configure(configs) _print_dict("\n configure result", result) for c in channels: self.assertTrue(c in result) for c in Some.INVALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.INVALID_CHANNEL) for c in Some.VALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.OK)
def set(self, params, *args, **kwargs): mi_logger.debug("MyProtocol(%s).set: params=%s" % (self._channel, str(params))) assert isinstance(params, dict) updated_params = 0 result = {} for (param, value) in params.items(): if param in self._values: if isinstance(value, int): self._values[param] = value result[param] = InstErrorCode.OK updated_params += 1 else: result[param] = InstErrorCode.INVALID_PARAM_VALUE else: result[param] = InstErrorCode.INVALID_PARAMETER # self.announce_to_driver(DriverAnnouncement.CONFIG_CHANGE, # msg="%s parameter(s) successfully set." % # updated_params) return result
def test_configure(self): """Driver configuration tests""" channels = Some.VALID_CHANNELS + Some.INVALID_CHANNELS mi_logger.debug("\n configure: %s" % str(channels)) configs = {} for c in channels: configs[c] = { 'method': 'ethernet', 'device_addr': '1.1.1.1', 'device_port': 1, 'server_addr': '2.2.2.2', 'server_port': 2 } result = self.driver.configure(configs) _print_dict("\n configure result", result) for c in channels: self.assertTrue(c in result) for c in Some.INVALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.INVALID_CHANNEL) for c in Some.VALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.OK)
def test_configure(self): """Driver configuration tests""" channels = Some.VALID_CHANNELS + Some.INVALID_CHANNELS mi_logger.debug("\n configure: %s" % str(channels)) configs = {} for c in channels: configs[c] = {'method': 'ethernet', 'device_addr': '1.1.1.1', 'device_port': 1, 'server_addr': '2.2.2.2', 'server_port': 2} result = self.driver.configure(configs) _print_dict("\n configure result", result) for c in channels: self.assertTrue(c in result) for c in Some.INVALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.INVALID_CHANNEL) for c in Some.VALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.OK)
def get(self, params, *args, **kwargs): mi_logger.debug("MyProtocol(%s).get: params=%s" % (self._channel, str(params))) assert isinstance(params, (list, tuple)) result = {} for param in params: if param in self._values: value = self._values[param] else: value = InstErrorCode.INVALID_PARAMETER result[param] = value return result
def test_get_params_channel_all(self): """Driver get all params tests""" params = [(Channel.ALL, Parameter.PARAM1), (Channel.ALL, Parameter.PARAM2)] mi_logger.debug("\nGET: %s" % str(params)) get_result = self.driver.get_resource(params) _print_dict("\nGET get_result", get_result) for c in Channel.list(): if c != Channel.ALL: self.assertTrue((c, Parameter.PARAM1) in get_result) self.assertTrue((c, Parameter.PARAM2) in get_result)
def test_connect_disconnect(self): """Test state change when connecting and disconnecting""" result = self.driver.get_resource_state() mi_logger.debug("Initial state result: %s", result) self.assertEquals(result[Channel.INSTRUMENT], DriverState.UNCONFIGURED) self.driver.chan_map[Channel.INSTRUMENT].connect = Mock(return_value=12) result = self.driver.connect() result = self.driver.get_resource_state() # Verify we hit the protocol since we are "connected" self.assertEquals(result[Channel.INSTRUMENT], DriverState.UNCONFIGURED) result = self.driver.disconnect() result = self.driver.get_resource_state() # driver FSM should intercept self.assertEquals(result[Channel.INSTRUMENT], DriverConnectionState.DISCONNECTED)
def test_get_params(self): """Driver get params tests""" params = Some.VALID_PARAMS + Some.INVALID_PARAMS mi_logger.debug("\nGET: %s" % str(params)) get_result = self.driver.get_resource(params) _print_dict("\nGET get_result", get_result) self.assertEqual(get_result[("invalid_chan", Parameter.PARAM1)], InstErrorCode.INVALID_CHANNEL) self.assertEqual(get_result[(Channel.CHAN1, "invalid_param")], InstErrorCode.INVALID_PARAMETER) for cp in Some.VALID_PARAMS: self.assertTrue(cp in get_result)
def test_connect_disconnect(self): """Test state change when connecting and disconnecting""" result = self.driver.get_resource_state() mi_logger.debug("Initial state result: %s", result) self.assertEquals(result[Channel.INSTRUMENT], DriverState.UNCONFIGURED) self.driver.chan_map[Channel.INSTRUMENT].connect = Mock( return_value=12) result = self.driver.connect() result = self.driver.get_resource_state() # Verify we hit the protocol since we are "connected" self.assertEquals(result[Channel.INSTRUMENT], DriverState.UNCONFIGURED) result = self.driver.disconnect() result = self.driver.get_resource_state() # driver FSM should intercept self.assertEquals(result[Channel.INSTRUMENT], DriverConnectionState.DISCONNECTED)
def test_connect(self): """Driver connection tests""" channels = Some.VALID_CHANNELS + Some.INVALID_CHANNELS mi_logger.debug("\n connect: %s" % str(channels)) result = self.driver.connect(channels) _print_dict("\n connect result", result) for c in channels: self.assertTrue(c in result) for c in Some.INVALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.INVALID_CHANNEL) for c in Some.VALID_CHANNELS: self.assertEqual(result[c], InstErrorCode.OK)
def _print_dict(title, d): mi_logger.debug("%s:" % title) for item in d.items(): mi_logger.debug("\t%s" % str(item))