コード例 #1
0
    def test_passthrough(self):
        """ Test the passthrough. """
        master_mock = SerialMock([
            sout("data for the passthrough"),
            sin("response"),
            sout("more data"),
            sin("more response")
        ])
        passthrough_mock = SerialMock([
            sin("data for the passthrough"),
            sout("response"),
            sin("more data"),
            sout("more response")
        ])
        SetUpTestInjections(controller_serial=master_mock,
                            passthrough_serial=passthrough_mock)

        master_communicator = MasterCommunicator(init_master=False)
        master_communicator.enable_passthrough()
        master_communicator.start()

        SetUpTestInjections(master_communicator=master_communicator)

        passthrough = PassthroughService()
        passthrough.start()

        time.sleep(1)

        self.assertEquals(
            33,
            master_communicator.get_communication_statistics()['bytes_read'])
        self.assertEquals(
            21,
            master_communicator.get_communication_statistics()
            ['bytes_written'])

        self.assertEquals(33, master_mock.bytes_read)
        self.assertEquals(21, master_mock.bytes_written)

        self.assertEquals(21, passthrough_mock.bytes_read)
        self.assertEquals(33, passthrough_mock.bytes_written)

        passthrough.stop()
コード例 #2
0
    def test_bytes_counter(self):
        """ Test the number of bytes written and read from the serial port. """
        action = master_api.basic_action()
        in_fields = {"action_type": 1, "action_number": 2}
        out_fields = {"resp": "OK"}

        serial_mock = SerialMock([
            sin(action.create_input(1, in_fields)),
            sout("hello"),
            sout(action.create_output(1, out_fields))
        ])
        SetUpTestInjections(controller_serial=serial_mock)

        comm = MasterCommunicator(init_master=False)
        comm.enable_passthrough()
        comm.start()

        self.assertEquals("OK", comm.do_command(action, in_fields)["resp"])
        self.assertEquals("hello", comm.get_passthrough_data())

        self.assertEquals(21,
                          comm.get_communication_statistics()['bytes_written'])
        self.assertEquals(5 + 18,
                          comm.get_communication_statistics()['bytes_read'])