コード例 #1
0
        def _extract_html(result, test_name, test_class='', duration=0,
                          debug=None, output=''):
            additional_html = []
            debug = debug or {}
            links_html = []

            result_map = {
                'KNOWN-FAIL': 'expected failure',
                'PASS': '******',
                'UNEXPECTED-FAIL': 'failure',
                'UNEXPECTED-PASS': '******'}

            if result.upper() in ['SKIPPED', 'UNEXPECTED-FAIL', 'KNOWN-FAIL', 'ERROR']:
                if debug.get('screenshot'):
                    screenshot = 'data:image/png;base64,{}'.format(debug['screenshot'])
                    additional_html.append(html.div(
                        html.a(html.img(src=screenshot), href="#"),
                        class_='screenshot'))
                for name, content in debug.items():
                    try:
                        if 'screenshot' in name:
                            href = '#'
                        else:
                            # use base64 to avoid that some browser (such as Firefox, Opera)
                            # treats '#' as the start of another link if the data URL contains.
                            # use 'charset=utf-8' to show special characters like Chinese.
                            href = 'data:text/plain;charset=utf-8;base64,{}'.format(
                                base64.b64encode(content))
                        links_html.append(html.a(
                            name.title(),
                            class_=name,
                            href=href,
                            target='_blank'))
                        links_html.append(' ')
                    except:
                        pass

                log = html.div(class_='log')
                for line in output.splitlines():
                    separator = line.startswith(' ' * 10)
                    if separator:
                        log.append(line[:80])
                    else:
                        if line.lower().find("error") != -1 or line.lower().find("exception") != -1:
                            log.append(html.span(raw(cgi.escape(line)), class_='error'))
                        else:
                            log.append(raw(cgi.escape(line)))
                    log.append(html.br())
                additional_html.append(log)

            test_logs.append(html.tr([
                html.td(result_map.get(result, result).title(), class_='col-result'),
                html.td(test_class, class_='col-class'),
                html.td(test_name, class_='col-name'),
                html.td(str(duration), class_='col-duration'),
                html.td(links_html, class_='col-links'),
                html.td(additional_html, class_='debug')],
                class_=result_map.get(result, result).lower() + ' results-table-row'))
コード例 #2
0
ファイル: reporting.py プロジェクト: Antonius32/Pale-Moon
        def _extract_html(result, test_name, test_class="", duration=0, debug=None, output=""):
            additional_html = []
            debug = debug or {}
            links_html = []

            result_map = {
                "KNOWN-FAIL": "expected failure",
                "PASS": "******",
                "UNEXPECTED-FAIL": "failure",
                "UNEXPECTED-PASS": "******",
            }

            if result.upper() in ["SKIPPED", "UNEXPECTED-FAIL", "KNOWN-FAIL", "ERROR"]:
                if debug.get("screenshot"):
                    screenshot = "data:image/png;base64,%s" % debug["screenshot"]
                    additional_html.append(html.div(html.a(html.img(src=screenshot), href="#"), class_="screenshot"))
                for name, content in debug.items():
                    try:
                        if "screenshot" in name:
                            href = "#"
                        else:
                            # use base64 to avoid that some browser (such as Firefox, Opera)
                            # treats '#' as the start of another link if the data URL contains.
                            # use 'charset=utf-8' to show special characters like Chinese.
                            href = "data:text/plain;charset=utf-8;base64,%s" % base64.b64encode(content)
                        links_html.append(html.a(name.title(), class_=name, href=href, target="_blank"))
                        links_html.append(" ")
                    except:
                        pass

                log = html.div(class_="log")
                for line in output.splitlines():
                    separator = line.startswith(" " * 10)
                    if separator:
                        log.append(line[:80])
                    else:
                        if line.lower().find("error") != -1 or line.lower().find("exception") != -1:
                            log.append(html.span(raw(cgi.escape(line)), class_="error"))
                        else:
                            log.append(raw(cgi.escape(line)))
                    log.append(html.br())
                additional_html.append(log)

            test_logs.append(
                html.tr(
                    [
                        html.td(result_map.get(result, result).title(), class_="col-result"),
                        html.td(test_class, class_="col-class"),
                        html.td(test_name, class_="col-name"),
                        html.td(str(duration), class_="col-duration"),
                        html.td(links_html, class_="col-links"),
                        html.td(additional_html, class_="debug"),
                    ],
                    class_=result_map.get(result, result).lower() + " results-table-row",
                )
            )