def test_valid_complete_sample(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config = config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state = DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) """ - Reset test verification variables. - Construct a complete sample - Pass to got_data() - Verify that raw and parsed streams have been received """ self.reset_test_vars() packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(FULL_SAMPLE) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received)
def test_valid_complete_sample(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config=config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state=DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) """ - Reset test verification variables. - Construct a complete sample - Pass to got_data() - Verify that raw and parsed streams have been received """ self.reset_test_vars() packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(FULL_SAMPLE) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received)
def test_concatenated_fragmented_sample(self): """ Simulate a complete sample that arrives in with a fragment concatenated. The concatenated fragment should have have a terminator. A separate invocations of got_data() will have the remainder; result should be a complete sample published """ """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config = config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state = DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) """ - Reset test verification variables. - Construct a sample stream with a concatenated fragment - Pass to got_data() - Verify that raw and parsed streams have been received - Later, when the final fragment has been send, verify that raw and parsed streams have been received. """ self.reset_test_vars() """ - Add the beginning of another sample stream - Pass to got_data() """ packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(FULL_SAMPLE+SAMPLE_FRAGMENT_1) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received) """ - Reset test verification variables - Construct the final fragment of a sample stream - Pass to got_data() - Verify that raw and parsed streams have been received """ self.reset_test_vars() packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(SAMPLE_FRAGMENT_2) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received)
def test_get_current_capabilities(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config = config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) result = test_driver._protocol.get_resource_capabilities() self.assertEqual(result[0], []) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state = DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) result = test_driver._protocol.get_resource_capabilities() self.assertEqual(result[0], [Capability.STOP_AUTOSAMPLE]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) test_driver.test_force_state(state = DriverProtocolState.COMMAND) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.COMMAND) result = test_driver._protocol.get_resource_capabilities() self.assert_(Capability.START_AUTOSAMPLE in result[0]) self.assert_(Capability.GET in result[0]) self.assert_(Capability.SET in result[0]) self.assert_(Capability.START_DIRECT in result[0]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) test_driver.test_force_state(state = DriverProtocolState.DIRECT_ACCESS) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.DIRECT_ACCESS) result = test_driver._protocol.get_resource_capabilities() self.assert_(Capability.STOP_DIRECT in result[0]) self.assert_(Capability.EXECUTE_DIRECT in result[0]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME])
def test_concatenated_fragmented_sample(self): """ Simulate a complete sample that arrives in with a fragment concatenated. The concatenated fragment should have have a terminator. A separate invocations of got_data() will have the remainder; result should be a complete sample published """ """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config=config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state=DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) """ - Reset test verification variables. - Construct a sample stream with a concatenated fragment - Pass to got_data() - Verify that raw and parsed streams have been received - Later, when the final fragment has been send, verify that raw and parsed streams have been received. """ self.reset_test_vars() """ - Add the beginning of another sample stream - Pass to got_data() """ packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(FULL_SAMPLE + SAMPLE_FRAGMENT_1) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received) """ - Reset test verification variables - Construct the final fragment of a sample stream - Pass to got_data() - Verify that raw and parsed streams have been received """ self.reset_test_vars() packet = PortAgentPacket() header = "\xa3\x9d\x7a\x02\x00\x1c\x0b\x2e\x00\x00\x00\x01\x80\x00\x00\x00" packet.unpack_header(header) packet.attach_data(SAMPLE_FRAGMENT_2) test_driver._protocol.got_data(packet) self.assertTrue(self.raw_stream_received) self.assertTrue(self.parsed_stream_received)
def test_get_current_capabilities(self): """ Create a mock port agent """ mock_port_agent = Mock(spec=LoggerClient) """ Instantiate the driver class directly (no driver client, no driver client, no zmq driver process, no driver process; just own the driver) """ test_driver = ooicoreInstrumentDriver(self.my_event_callback) current_state = test_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} test_driver.configure(config=config) current_state = test_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). """ test_driver.connect() current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.UNKNOWN) result = test_driver._protocol.get_resource_capabilities() self.assertEqual(result[0], []) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) """ Force the driver into AUTOSAMPLE state so that it will parse and publish samples """ test_driver.set_test_mode(True) test_driver.test_force_state(state=DriverProtocolState.AUTOSAMPLE) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE) result = test_driver._protocol.get_resource_capabilities() self.assertEqual(result[0], [Capability.STOP_AUTOSAMPLE]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) test_driver.test_force_state(state=DriverProtocolState.COMMAND) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.COMMAND) result = test_driver._protocol.get_resource_capabilities() self.assert_(Capability.START_AUTOSAMPLE in result[0]) self.assert_(Capability.GET in result[0]) self.assert_(Capability.SET in result[0]) self.assert_(Capability.START_DIRECT in result[0]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME]) test_driver.test_force_state(state=DriverProtocolState.DIRECT_ACCESS) current_state = test_driver.get_resource_state() self.assertEqual(current_state, DriverProtocolState.DIRECT_ACCESS) result = test_driver._protocol.get_resource_capabilities() self.assert_(Capability.STOP_DIRECT in result[0]) self.assert_(Capability.EXECUTE_DIRECT in result[0]) self.assertEqual(result[1], [Parameter.ALL, Parameter.CYCLE_TIME])