Esempio n. 1
0
    def test_000_data_framer_construct_destruct(self):
        """Test constructing and destructing of DataFramer classes."""
        uut2 = data_framer.InterwovenLogFramer("")
        del uut2

        uut3 = data_framer.NewlineFramer()
        del uut3
Esempio n. 2
0
    def test_034_log_framer_yields_response_line_only(self):
        """Test LogFramer class yields non-matching response line as is."""
        log_line_pattern = r"(my custom log line\n)"
        uut = data_framer.InterwovenLogFramer(log_line_pattern)

        response_line = "some non-matching response line\n"
        lines = uut.get_lines(response_line)
        line = next(lines)
        self.assertEqual(
            response_line, line,
            "Expected line {!r} found {!r}".format(response_line, line))
        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 3
0
    def test_032_log_framer_yields_one_line_on_full_match(self):
        """Test LogFramer class yields one line for full matching log line."""
        log_line = "my custom log line\n"
        log_line_pattern = "({})".format(log_line)
        uut = data_framer.InterwovenLogFramer(log_line_pattern)

        lines = uut.get_lines(log_line)
        line = next(lines)
        self.assertEqual(
            log_line, line,
            "Expected line {!r} found {!r}".format(log_line, line))
        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 4
0
    def test_030_log_framer_yields_partial_line(self):
        """Test LogFramer class yields partial line without newline."""
        log_line = "my custom log line"
        log_line_pattern = "({}\n)".format(log_line)
        uut = data_framer.InterwovenLogFramer(log_line_pattern)

        lines = uut.get_lines(log_line)
        line = next(lines)
        self.assertEqual(
            log_line, line,
            "Expected line {!r} found {!r}".format(log_line, line))
        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 5
0
    def test_031_log_framer_yields_two_lines_on_split_match(self):
        """Test LogFramer yields two lines when log line splits response line."""
        response_line = "response start"
        log_line = "my custom log line\n"
        log_line_pattern = "({})".format(log_line)
        uut = data_framer.InterwovenLogFramer(log_line_pattern)

        raw_data = "{}{}".format(response_line, log_line)
        lines = uut.get_lines(raw_data)
        line1 = next(lines)
        line2 = next(lines)
        self.assertEqual(
            log_line, line1,
            "Expected line {!r} found {!r}".format(log_line, line1))
        self.assertEqual(
            response_line, line2,
            "Expected line {!r} found {!r}".format(response_line, line2))
        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 6
0
    def test_233_transport_read_reorders_log_interrupted_partial_lines(self):
        """Test transport read can order partial and full lines correctly.

    See NEP-3223 which is a bug in the interaction of TransportProcess and
    LogFramer.
    """
        transport = fake_transport.FakeTransport()
        response_start = u"response start"
        response_end = u" end"
        response_full = response_start + response_end
        log_line = u"my custom log line\n"
        log_regex = "({})".format(log_line)
        framer = data_framer.InterwovenLogFramer(log_regex)
        uut = transport_process.TransportProcess(
            "fake_transport",
            self.exception_queue,
            self.command_queue,
            self.log_queue,
            transport,
            call_result_queue=self.call_result_queue,
            framer=framer)

        device_data1 = response_start + log_line + response_end
        transport.reads.put(device_data1)
        wait_for_queue_writes(transport.reads)
        uut._pre_run_hook()
        uut._do_work()
        line1 = self.log_queue.get()
        self.assertIn(
            log_line, line1,
            "Expected {!r} in line but found {!r}".format(log_line, line1))
        self.assertTrue(self.log_queue.empty(),
                        "Expected log queue to be empty")
        time.sleep(_LOG_MESSAGE_TIMEOUT)
        uut._do_work()
        line2 = self.log_queue.get()
        self.assertIn(
            response_full, line2,
            "Expected {!r} in line but found {!r}".format(
                response_full, line2))
        self.assertTrue(self.log_queue.empty(),
                        "Expected log queue to be empty")
        uut._post_run_hook()
Esempio n. 7
0
    def test_033_log_framer_yields_recombined_lines(self):
        """Test LogFramer class yields recombined line with newline added."""
        response_start = "response start"
        response_end = " end\n"
        response_line = "{}{}".format(response_start, response_end)
        log_line = "my custom log line"
        log_line_pattern = "({})".format(log_line)
        uut = data_framer.InterwovenLogFramer(log_line_pattern,
                                              add_newline=True)

        raw_data = "{}{}{}".format(response_start, log_line, response_end)
        lines = uut.get_lines(raw_data)
        line1 = next(lines)
        line2 = next(lines)
        self.assertEqual(
            log_line + "\n", line1,
            "Expected line {!r} found {!r}".format(log_line, line1))
        self.assertEqual(
            response_line, line2,
            "Expected line {!r} found {!r}".format(response_line, line2))
        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 8
0
    def test_234_transport_read_orders_lines_correctly(self):
        """Test transport read can order partial and full lines correctly.

    See NEP-3223 which is a bug in the interaction of TransportProcess and
    LogFramer.
    """
        response_start = u"response start"
        response_end = u" end\n"
        response_full = response_start + response_end
        log_line = u"my custom log line\n"
        log_regex = "({})".format(log_line)
        device_data1 = response_start + log_line + response_end
        transport = mock.MagicMock(fake_transport.FakeTransport)
        transport.read.return_value = device_data1.encode("utf-8", "replace")
        framer = data_framer.InterwovenLogFramer(log_regex)
        self.uut = transport_process.TransportProcess(
            "fake_transport",
            self.exception_queue,
            self.command_queue,
            self.log_queue,
            transport,
            call_result_queue=self.call_result_queue,
            framer=framer)

        self.uut._pre_run_hook()
        self.uut._do_work()
        line1 = self.log_queue.get()
        self.assertIn(
            log_line, line1,
            "Expected {!r} in line but found {!r}".format(log_line, line1))
        line2 = self.log_queue.get()
        self.assertIn(
            response_full, line2,
            "Expected {!r} in line but found {!r}".format(
                response_full, line2))
        self.assertTrue(self.log_queue.empty(),
                        "Expected log queue to be empty")
        self.uut._post_run_hook()