示例#1
0
    def get_detail(self, source, depth, row_idx):
        """
        Render the message if there is any, then render XMLTagComparison items.
        """
        msg = []

        msg.append('xpath: {}'.format(escape(source['xpath'])))

        if source['namespaces']:
            msg.append(
                'Namespaces: {}'.format(
                    escape(
                        str(
                            source['namespaces']
                        )
                    )
                )
            )

        if source['message']:
            msg.append(
                _format_text(
                    colour='black' if source['passed'] else 'red',
                    text=escape(source['message']),
                    bold = not source['passed']
                )
            )

        if source['data']:
            msg.append('Tags:')

        msg_style = RowStyle(
            left_padding=const.INDENT * (depth + 1),
            bottom_padding=0,
            span=tuple()
        )
        msg_para = Paragraph(
            text='<br />\n'.join(msg),
            style=const.PARAGRAPH_STYLE
        )
        msg_row = RowData(
            content=[msg_para, '', '', ''],
            style=msg_style,
            start=row_idx
        )

        tags = []
        for data in source['data']:
            tag_comp = assertions.XMLTagComparison(
                tag=data[0],
                diff=data[1],
                error=data[2],
                extra=data[3]
            )
            template = '{actual} {operator} {expected}'
            common = dict(
                actual=tag_comp.tag,
                expected=tag_comp.comparison_value
            )

            if tag_comp.passed:
                tags.append(
                    escape(
                        template.format(
                            operator='==', **common
                        )
                    )
                )
            else:
                tags.append(
                    _format_text(
                        text=escape(
                            template.format(
                                operator='!=', **common
                            )
                        ),
                        colour='red',
                        bold=True
                    )
                )

        if tags:
            tags_style = RowStyle(
                left_padding=const.INDENT * (depth + 2),
                span=tuple()
            )
            tags_para = Paragraph(
                text='<br />\n'.join(tags),
                style=const.PARAGRAPH_STYLE
            )
            tags_row = RowData(
                content=[tags_para, '', '', ''],
                style=tags_style,
                start=msg_row.end
            )

            return msg_row + tags_row
        else:
            return msg_row
示例#2
0
    def get_detail(self, source, depth, row_idx):
        """
        Render the message if there is any, then render XMLTagComparison items.
        """
        msg = []

        msg.append("xpath: {}".format(html_escape(source["xpath"])))

        if source["namespaces"]:
            msg.append("Namespaces: {}".format(
                html_escape(str(source["namespaces"]))))

        if source["message"]:
            msg.append(
                _format_text(
                    colour="black" if source["passed"] else "red",
                    text=html_escape(source["message"]),
                    bold=not source["passed"],
                ))

        if source["data"]:
            msg.append("Tags:")

        msg_style = RowStyle(
            left_padding=const.INDENT * (depth + 1),
            bottom_padding=0,
            span=tuple(),
        )
        msg_para = Paragraph(text="<br />\n".join(msg),
                             style=const.PARAGRAPH_STYLE)
        msg_row = RowData(content=[msg_para, "", "", ""],
                          style=msg_style,
                          start=row_idx)

        tags = []
        for data in source["data"]:
            tag_comp = assertions.XMLTagComparison(tag=data[0],
                                                   diff=data[1],
                                                   error=data[2],
                                                   extra=data[3])
            template = "{actual} {operator} {expected}"
            common = dict(actual=tag_comp.tag,
                          expected=tag_comp.comparison_value)

            if tag_comp.passed:
                tags.append(
                    html_escape(template.format(operator="==", **common)))
            else:
                tags.append(
                    _format_text(
                        text=html_escape(
                            template.format(operator="!=", **common)),
                        colour="red",
                        bold=True,
                    ))

        if tags:
            tags_style = RowStyle(left_padding=const.INDENT * (depth + 2),
                                  span=tuple())
            tags_para = Paragraph(text="<br />\n".join(tags),
                                  style=const.PARAGRAPH_STYLE)
            tags_row = RowData(
                content=[tags_para, "", "", ""],
                style=tags_style,
                start=msg_row.end,
            )

            return msg_row + tags_row
        else:
            return msg_row