#!/usr/bin/env python # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import base64 import json import os from collections import defaultdict from datetime import datetime
import six
from .. import base
html = None
raw = None
if six.PY2: from cgi import escape else: from html import escape
base_path = os.path.split(__file__)[0]
def do_defered_imports(): global html global raw
from .xmlgen import html, raw
class HTMLFormatter(base.BaseFormatter): """Formatter that produces a simple HTML-formatted report."""
if status != expected and status notin known_intermittent:
status_name = "UNEXPECTED_" + status elif status in known_intermittent:
status_name = "KNOWN_INTERMITTENT" elif status notin ("PASS", "SKIP"):
status_name = "EXPECTED_" + status
self.test_count[status_name] += 1
if status in ["SKIP", "FAIL", "PRECONDITION_FAILED", "ERROR"]: if debug.get("differences"):
images = [
("image1", "Image 1 (test)"),
("image2", "Image 2 (reference)"),
] for title, description in images:
screenshot = "%s" % debug[title]
additional_html.append(
html.div(
html.a(html.img(src=screenshot), href="#"),
html.br(),
html.a(description),
class_="screenshot",
)
)
for name, content in debug.items(): if name in ["screenshot", "image1", "image2"]: ifnot content.startswith("data:image/png;base64,"):
href = "data:image/png;base64,%s" % content else:
href = content else: ifnot isinstance(content, (six.text_type, six.binary_type)): # All types must be json serializable
content = json.dumps(content) # Decode to text type if JSON output is byte string ifnot isinstance(content, six.text_type):
content = content.decode("utf-8") # Encode base64 to avoid that some browsers (such as Firefox, Opera) # treats '#' as the start of another link if it is contained in the data URL. if isinstance(content, six.text_type):
is_known_utf8 = True
content_bytes = six.text_type(content).encode( "utf-8", "xmlcharrefreplace"
) else:
is_known_utf8 = False
content_bytes = content
meta = ["text/html"] if is_known_utf8:
meta.append("charset=utf-8")
# base64 is ascii only, which means we don't have to care about encoding # in the case where we don't know the encoding of the input
b64_bytes = base64.b64encode(content_bytes)
b64_text = b64_bytes.decode()
href = "data:%s;base64,%s" % (";".join(meta), b64_text)
links_html.append(
html.a(name.title(), class_=name, href=href, target="_blank")
)
links_html.append(" ")
log = html.div(class_="log")
output = data.get("stack", "").splitlines()
output.extend(data.get("message", "").splitlines()) for line in output:
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(escape(line)), class_="error")) else:
log.append(raw(escape(line)))
log.append(html.br())
additional_html.append(log)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.