def test_connect(self):
        """
        Verify sample data passed through the got data method produces the correct data particles
        """

        """
        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)
        """
        driver = InstrumentDriver(self._got_data_event_callback)
        
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        """
        Now configure the driver with the mock_port_agent, verifying
        that the driver transitions to the DISCONNECTED state
        """
        config = {'mock_port_agent' : mock_port_agent}
        driver.configure(config = config)
        #self.assert_initialize_driver(driver)

        current_state = driver.get_resource_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 UNKNOWN.
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)
    def test_connect(self):
        """
        Verify sample data passed through the got data method produces the correct data particles
        """
        """
        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)
        """
        driver = InstrumentDriver(self._got_data_event_callback)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)
        """
        Now configure the driver with the mock_port_agent, verifying
        that the driver transitions to the DISCONNECTED state
        """
        config = {'mock_port_agent': mock_port_agent}
        driver.configure(config=config)
        #self.assert_initialize_driver(driver)

        current_state = driver.get_resource_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 UNKNOWN.
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)
    def test_heat_on_response_with_data(self):
        """
        """
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)
        driver.set_test_mode(True)

        current_state = driver.get_resource_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}
        driver.configure(config=config)

        current_state = driver.get_resource_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).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)
        ts = ntplib.system_to_ntp_time(time.time())

        log.debug("HEAT ON command response: %s", VALID_SAMPLE_01)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(VALID_SAMPLE_01)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)

        log.debug("HEAT ON command response: %s", HEAT_ON_COMMAND_RESPONSE)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(HEAT_ON_COMMAND_RESPONSE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        self.assertTrue(
            driver._protocol._get_response(
                expected_prompt=TEST_HEAT_ON_DURATION_2))
    def test_heat_on_response_with_data(self):
        """
        """
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)
        driver.set_test_mode(True)

        current_state = driver.get_resource_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}
        driver.configure(config = config)

        current_state = driver.get_resource_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).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)
        ts = ntplib.system_to_ntp_time(time.time())

        log.debug("HEAT ON command response: %s", VALID_SAMPLE_01)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(VALID_SAMPLE_01)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)

        log.debug("HEAT ON command response: %s", HEAT_ON_COMMAND_RESPONSE)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(HEAT_ON_COMMAND_RESPONSE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        self.assertTrue(driver._protocol._get_response(expected_prompt = 
                                                       TEST_HEAT_ON_DURATION_2))
    def test_heat_off(self):
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)

        def my_send(data):
            log.debug("my_send: %s", data)
            driver._protocol._promptbuf += HEAT_OFF_COMMAND_RESPONSE
            return 5

        mock_port_agent.send.side_effect = my_send

        #self.assert_initialize_driver(driver)

        # Put the driver into test mode
        driver.set_test_mode(True)

        current_state = driver.get_resource_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}
        driver.configure(config=config)

        current_state = driver.get_resource_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).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)

        result = driver._protocol._handler_command_heat_off()
        ts = ntplib.system_to_ntp_time(time.time())
        result = driver._protocol._got_chunk(HEAT_OFF_COMMAND_RESPONSE, ts)
    def test_heat_off(self):
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)

        def my_send(data):
            log.debug("my_send: %s", data)
            driver._protocol._promptbuf += HEAT_OFF_COMMAND_RESPONSE
            return 5
        mock_port_agent.send.side_effect = my_send
        
        #self.assert_initialize_driver(driver)

        # Put the driver into test mode
        driver.set_test_mode(True)

        current_state = driver.get_resource_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}
        driver.configure(config = config)

        current_state = driver.get_resource_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).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)

        result = driver._protocol._handler_command_heat_off()
        ts = ntplib.system_to_ntp_time(time.time())
        result = driver._protocol._got_chunk(HEAT_OFF_COMMAND_RESPONSE, ts)