Example #1
0
    def get_detail(self, source, depth, row_idx):
        """
        `RegexMatchLine` returns line indexes
        along with begin/end character indexes per matched line.
        """
        left_padding = const.INDENT * (depth + 1)
        pattern_style = [
            RowStyle(
                font=(const.FONT, const.FONT_SIZE_SMALL),
                left_padding=left_padding,
                text_color=colors.black,
                background=None if source["passed"] else colors.whitesmoke,
                span=tuple(),
            )
        ]

        p = "Pattern: `{}`".format(source["pattern"])
        pattern = RowData(content=[p, "", "", ""],
                          style=pattern_style,
                          start=row_idx)

        if source["match_indexes"]:
            parts = []
            match_map = {
                line_no: (begin, end)
                for line_no, begin, end in source["match_indexes"]
            }

            for idx, line in enumerate(source["string"].splitlines()):
                if idx in match_map:
                    begin, end = match_map[idx]
                    parts.append((line[:begin], "{}"))
                    parts.append((line[begin:end],
                                  "<b><font color=green>{}</font></b>"))
                    parts.append((line[end:], "{}"))
                else:
                    parts.append((line, "{}"))
                parts.append(("\n", "{}"))

        else:
            parts = (source["string"], "{}")

        for para in SlicedParagraph(
                parts=parts,
                width=const.PAGE_WIDTH - left_padding - 6,
        ):
            pattern = pattern + RowData(
                content=[para, "", "", ""],
                style=[
                    RowStyle(
                        left_padding=left_padding,
                        span=tuple(),
                        background=None
                        if source["passed"] else colors.whitesmoke,
                    )
                ],
                start=pattern.end,
            )

        return pattern
def test_sliced_para():

    msg = (
        "This is a super looooooooooong message with indents, extra spaces\n"
        "    and <Test>special</Test> characters,\n"
        "    and    it    will    be    written    as-is    in    pdf.\n"
    )

    para = Paragraph(
        text=escape(msg, quote=False)
        .replace("\n", "<br/>")
        .replace(" ", "&nbsp;"),
        style=constants.PARAGRAPH_STYLE,
    )
    width, height = para.wrap(constants.PAGE_WIDTH, constants.MAX_CELL_HEIGHT)

    assert (
        sum(
            1
            for _ in SlicedParagraph(
                parts=[(msg, "{}")] * 3,
                width=width,
                height=height,
            )
        )
        == 3
    )
Example #3
0
    def get_detail(self, source, depth, row_idx):
        """
        Return highlighted patterns within the string, if there is a match.
        """
        left_padding = const.INDENT * (depth + 1)

        pattern_style = [
            RowStyle(
                font=(const.FONT, const.FONT_SIZE_SMALL),
                left_padding=left_padding,
                text_color=colors.black,
                span=tuple(),
                background=None if source["passed"] else colors.whitesmoke,
            )
        ]

        p = "Pattern: `{}`".format(source["pattern"])
        pattern = RowData(content=[p, "", "", ""],
                          style=pattern_style,
                          start=row_idx)

        parts = []
        string = source["string"]
        if source["match_indexes"]:
            curr_idx = 0

            for begin, end in source["match_indexes"]:
                parts.append((string[curr_idx:begin], "{}"))
                parts.append((
                    string[begin:end],
                    "<b><font color={color}>{{}}</font></b>".format(
                        color=self.highlight_color),
                ))
                curr_idx = end
            if curr_idx < len(string):
                parts.append((string[curr_idx:], "{}"))
        else:
            parts = (string, "{}")

        for para in SlicedParagraph(
                parts=parts,
                width=const.PAGE_WIDTH - left_padding - 6,
        ):
            pattern = pattern + RowData(
                content=[para, "", "", ""],
                style=[
                    RowStyle(
                        left_padding=left_padding,
                        span=tuple(),
                        background=None
                        if source["passed"] else colors.whitesmoke,
                    )
                ],
                start=pattern.end,
            )

        return pattern
Example #4
0
    def get_row_data(self, source, depth, row_idx):
        """
        Create a header and a detailed log message, only create a head if
        should display a string message without the description.
        """
        header = self.get_header(source, depth, row_idx)

        log_msg = (str(source["message"]) if isinstance(
            source["message"], str) else pprint.pformat(source["message"],
                                                        depth=6))
        left_padding = constants.INDENT * (depth + 1)

        for para in SlicedParagraph(
                parts=(log_msg, "{}"),
                width=constants.PAGE_WIDTH - left_padding - 6,
        ):
            header = header + RowData(
                content=[para, "", "", ""],
                style=[RowStyle(left_padding=left_padding, span=tuple())],
                start=header.end,
            )

        return header