def test_parse_ds(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=PortAgentClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = InstrumentDriver(self.my_event_callback) current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED) """ Now configure the driver with the mock_port_agent, verifying that the driver transitions to that state """ config = {'mock_port_agent' : mock_port_agent} # commented below out; trying real port agent test_driver.configure(config = config) """ DHE: trying this; want to invoke the driver methods themselves, but with the driver talking to the port_agent (through the client). Will it work? Answer: It does, but I can't step through it. Let me try just running this. """ #test_driver.configure(config = self.port_agent_comm_config()) current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverConnectionState.DISCONNECTED) """ Invoke the connect method of the driver: should connect to mock port agent. Verify that the connection FSM transitions to CONNECTED, (which means that the FSM should now be reporting the ProtocolState). """ """ TODO: DHE: Shouldn't have to put a sleep here; it's like the port_agent isn't up yet; I get a connection refused without this. """ gevent.sleep(2) test_driver.connect() current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverProtocolState.UNKNOWN) self.reset_test_vars() test_ds_response = "output salinity = yes, output sound velocity = no\r\n" test_driver._protocol._parse_dsdc_response(test_ds_response, '<Executed/>') """
def test_sample(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=PortAgentClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = InstrumentDriver(self.my_event_callback) current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED) """ Now configure the driver with the mock_port_agent, verifying that the driver transitions to that state """ config = {'mock_port_agent' : mock_port_agent} # commented below out; trying real port agent test_driver.configure(config = config) """ DHE: trying this; want to invoke the driver methods themselves, but with the driver talking to the port_agent (through the client). Will it work? Answer: It does, but I can't step through it. Let me try just running this. """ #test_driver.configure(config = self.port_agent_comm_config()) current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverConnectionState.DISCONNECTED) """ Invoke the connect method of the driver: should connect to mock port agent. Verify that the connection FSM transitions to CONNECTED, (which means that the FSM should now be reporting the ProtocolState). """ """ TODO: DHE: Shouldn't have to put a sleep here; it's like the port_agent isn't up yet; I get a connection refused without this. """ gevent.sleep(2) test_driver.connect() current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverProtocolState.UNKNOWN) """ Invoke the discover_state method of the driver """ # commenting out because it will try wakeup #test_driver.discover_state() #current_state = test_driver.get_resource_state() #print "DHE: DriverConnectionState: " + str(current_state) """ Force state to command state. """ """ This won't work right now because the SBE16 does an _update_params upon entry to the command_handler; since this is a unit test there is nothing to respond to the ds and dc commands. Setting up mock to do it would be really handy. """ test_driver.execute_force_state(state = DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() print "DHE: DriverConnectionState: " + str(current_state) self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) self.reset_test_vars() test_sample = "# 24.0088, 0.00001, -0.000, 0.0117, 03 Oct 2012 20:59:04\r\n" """ use for test particle test_sample = "# 24.0088, 0.00001, -0.000, 0.0117, 03 Oct 2012 20:59:04\r\n" test_sample = "# 24. 24.0088, 0.00001, 0.000, 0.0117, 03 Oct 2012 20:58:54\r\n" """ paPacket = PortAgentPacket() paHeader = "\xa3\x9d\x7a\x02\x00\x50\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" paPacket.unpack_header(paHeader) paPacket.attach_data(test_sample) test_driver._protocol.got_data(paPacket) """