コード例 #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")])

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

        passthrough = PassthroughService(master_communicator, passthrough_mock)
        passthrough.start()

        time.sleep(1)

        self.assertEquals(33, master_communicator.get_bytes_read())
        self.assertEquals(21, master_communicator.get_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_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")
        ])

        master_communicator = MasterCommunicator(master_mock,
                                                 init_master=False)
        master_communicator.start()

        passthrough = PassthroughService(master_communicator, passthrough_mock)
        passthrough.start()

        time.sleep(1)

        self.assertEquals(33, master_communicator.get_bytes_read())
        self.assertEquals(21, master_communicator.get_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()
コード例 #3
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))])

        comm = MasterCommunicator(serial_mock, 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_bytes_written())
        self.assertEquals(5 + 18, comm.get_bytes_read())
コード例 #4
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))
        ])

        comm = MasterCommunicator(serial_mock, init_master=False)
        comm.start()

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

        self.assertEquals(21, comm.get_bytes_written())
        self.assertEquals(5 + 18, comm.get_bytes_read())
コード例 #5
0
ファイル: passthrough_tests.py プロジェクト: rubengr/gateway
    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_bytes_read())
        self.assertEquals(21, master_communicator.get_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()