Example #1
0
    def add_test_messages(self, test, idx, tests, tests_by_parent,
                          tests_by_id):
        started = test["test"]["message_time"]
        ended = test["result"]["message_time"]

        messages = [
            format_test(test["test"],
                        "",
                        tests_by_parent,
                        tests_by_id,
                        no_colors=True)
        ]

        if getattr(TestType, test["test"]["test_type"]) > TestType.Test:
            for t in tests[idx + 1:]:
                flags = Flags(t["test"]["test_flags"])
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"]["message_time"] > ended:
                    break
                if getattr(TestType, t["test"]["test_type"]) >= TestType.Test \
                        and t["test"]["test_id"].startswith(test["test"]["test_id"]):
                    messages.append(
                        format_test(t["test"],
                                    "",
                                    tests_by_parent,
                                    tests_by_id,
                                    no_colors=True))
                    messages.append(format_result(t["result"], no_colors=True))
        else:
            for t in tests[idx + 1:]:
                flags = Flags(t["test"]["test_flags"])
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"]["message_time"] > ended:
                    break
                if t["test"]["test_id"].startswith(test["test"]["test_id"]):
                    messages.append(
                        format_test(t["test"],
                                    "",
                                    tests_by_parent,
                                    tests_by_id,
                                    no_colors=True))
                    messages.append(format_result(t["result"], no_colors=True))

        messages.append(format_result(test["result"], no_colors=True))

        test["messages"] = "".join(messages)
        return test
Example #2
0
def format_input(msg, keyword):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return
    out = f"{indent * (msg.p_id.count('/'))}"
    out += color("\u270b " + msg.message, "yellow", attrs=["bold"]) + cursor_up() + "\n"
    return out
Example #3
0
def format_result(msg, last_test_id, result):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return

    if msg.p_type < TestType.Test:
        return

    _result = color_result(result)
    _test = color_keyword(
        format_type(msg)) + color_test_name(f" {basename(msg.test)}")

    _indent = indent * (msg.p_id.count('/') - 1)
    out = f"{_indent}{_result}"

    if last_test_id[-1] == msg.p_id:
        out = cursor_up() + "\r" + out

    if msg.name in ("Fail", "Error", "Null"):
        out += f" {_test}"
        if msg.message:
            out += color_test_name(",")
            out += f" {color(format_multiline(msg.message, _indent).lstrip(), 'yellow', attrs=['bold'])}"
    elif msg.name.startswith("X"):
        out += f" {_test}"
        if msg.reason:
            out += color_test_name(",")
            out += f" {color(msg.reason, 'blue', attrs=['bold'])}"
    else:
        out += f" {_test}"
    return out + "\n"
Example #4
0
def format_result(msg):
    result = msg["result_type"]

    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return

    if getattr(TestType, msg["test_type"]) < TestType.Iteration:
        return

    _icon = color_result(result)
    _result = color_result(result, result)
    _test = color_test_name(f"{msg['result_test']}")

    out = f"{_icon} " + color_other(
        f"{strftimedelta(msg['message_rtime']):<10}"
    ) + f"[ {result.center(6, ' ')} ]".ljust(10, ' ').replace(result, _result)

    if result in ("Fail", "Error", "Null"):
        out += f" {_test}"
        if msg["result_message"]:
            out += f"\n{indent}  {color(format_multiline(msg['result_message'], indent).lstrip(), 'yellow', attrs=['bold'])}"
    elif result.startswith("X"):
        out += f" {_test}"
        if msg['result_reason']:
            out += f"\n{indent}  {color(msg['result_reason'], 'blue', attrs=['bold'])}"
    else:
        out += f" {_test}"
    return out + "\n"
Example #5
0
def format_input(msg, keyword):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return
    out = color_other(f"{strftimedelta(msg.p_time):>20}{'':3}{indent * (msg.p_id.count('/') - 1)}{keyword}")
    out += color("\u270b " + msg.message, "yellow", attrs=["bold"]) + cursor_up() + "\n"
    return out
Example #6
0
def format_result(msg, last_test_id):
    result = msg["result_type"]

    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return

    if getattr(TestType, msg["test_type"]) < TestType.Iteration:
        return

    _result = color_result(result)
    _test = color_keyword(
        format_type(msg)) + color_test_name(f" {basename(msg['result_test'])}")

    _indent = indent * (msg["test_id"].count('/') - 1)
    out = f"{_indent}{_result}"

    if last_test_id and last_test_id[-1] == msg["test_id"]:
        out = cursor_up() + "\r" + out
    last_test_id = []

    if result in ("Fail", "Error", "Null"):
        out += f" {_test}"
        if msg["result_message"]:
            out += color_test_name(",")
            out += f" {color(format_multiline(msg['result_message'], _indent).lstrip(), 'yellow', attrs=['bold'])}"
    elif result.startswith("X"):
        out += f" {_test}"
        if msg['result_reason']:
            out += color_test_name(",")
            out += f" {color(msg['result_reason'], 'blue', attrs=['bold'])}"
    else:
        out += f" {_test}"
    return out + "\n"
Example #7
0
    def paths(self, results):
        d = {}
        tests = list(results["tests"].values())

        def get_path(test, idx):
            started = test["test"].started
            ended = started + test["result"].p_time
            path = []

            for t in tests[idx:]:
                flags = Flags(t["test"].p_flags)
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"].started > ended:
                    break
                if t["test"].p_id.startswith(test["test"].p_id):
                    if t["test"].node:
                        path.append(t["test"].node)

            return path

        for idx, name in enumerate(results["tests"]):
            test = results["tests"][name]
            flags = Flags(test["test"].p_flags)
            if flags & SKIP and settings.show_skipped is False:
                continue
            if test["test"].p_type < TestType.Test:
                continue
            d[name] = get_path(test, idx)

        return d
Example #8
0
 def xfails_section(self, results):
     s = "\n\n## Known Fails\n"
     s += '<table class="stripped primary">\n'
     s += '<thead><tr><th><span style="display: block; min-width: 20vw;">Test Name</span></th><th><span style="display: block; min-width: 90px;">Result</span></th><th>Message</th></tr></thead>\n'
     s += "<tbody>\n"
     has_xfails = False
     for test in results["tests"].values():
         result = test["result"]
         if result.p_type < TestType.Test:
             continue
         flags = Flags(result.p_flags)
         if flags & SKIP and settings.show_skipped is False:
             continue
         if type(result) in XoutResults:
             cls = result.name.lower()
             s += (
                 "<tr>" + f'<td>{result.test}</td>' +
                 f'<td><span class="result result-{cls}">{result.name}</span> '
                 + strftimedelta(result.p_time) + '<br>' +
                 str(result.reason).replace("|", "\|") + '</td>' +
                 '<td><div style="max-width: 30vw; overflow-x: auto;"><pre>'
                 + str(result.message).replace("|", "\|") +
                 '</pre></div></td>') + "</tr>\n"
             has_xfails = True
     s += '<tbody>\n'
     s += '</table>\n'
     if not has_xfails:
         return ""
     return s
Example #9
0
def add_result(msg, results, result):
    if msg.p_type < TestType.Test:
        return
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return
    if result in ("OK", "Skip"):
        results[msg.p_id] = (msg, result)
Example #10
0
def add_result(msg, results):
    result = msg["result_type"]
    if getattr(TestType, msg["test_type"]) < TestType.Iteration:
        return
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return
    if result in ("OK", "Skip"):
        results[msg["test_id"]] = (msg, result)
Example #11
0
    def add_test_messages(self, test, idx, tests, tests_by_parent,
                          tests_by_id):
        started = test["test"].started
        ended = started + test["result"].p_time

        messages = [
            format_test(test["test"], "", tests_by_parent, tests_by_id)
        ]

        if test["test"].p_type > TestType.Test:
            for t in tests[idx + 1:]:
                flags = Flags(t["test"].p_flags)
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"].started > ended:
                    break
                if t["test"].p_type >= TestType.Test \
                        and t["test"].p_id.startswith(test["test"].p_id):
                    messages.append(
                        format_test(t["test"], "", tests_by_parent,
                                    tests_by_id))
                    messages.append(
                        format_result(t["result"], t["result"].name))
        else:
            for t in tests[idx + 1:]:
                flags = Flags(t["test"].p_flags)
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"].started > ended:
                    break
                if t["test"].p_id.startswith(test["test"].p_id):
                    messages.append(
                        format_test(t["test"], "", tests_by_parent,
                                    tests_by_id))
                    messages.append(
                        format_result(t["result"], t["result"].name))

        messages.append(format_result(test["result"], test["result"].name))

        test["messages"] = "".join(messages)
        return test
Example #12
0
def format_result(msg, prefix, result):
    if Flags(msg.p_flags) & SKIP and settings.show_skipped is False:
        return
    _result = color_result(prefix, result)
    _test = color_other(basename(msg.test))
    _indent = indent * (msg.p_id.count('/') - 1)

    return (color_other(f"{strftimedelta(msg.p_time):>20}") +
        f"{'':3}{_indent}{_result} "
        f"{_test}{color_other(', ' + msg.test)}"
        f"{(color_other(', ') + color(format_multiline(msg.message, _indent + ' ' * 26).lstrip(), 'yellow', attrs=['bold'])) if msg.message else ''}"
        f"{(color_other(', ') + color(msg.reason, 'blue', attrs=['bold'])) if msg.reason else ''}\n")
Example #13
0
def format_other(msg, keyword):
    if Flags(msg.p_flags) & SKIP and settings.show_skipped is False:
        return
    fields = ' '.join([str(f) for f in msg[message.Prefix.time + 1:]])
    if msg.p_stream:
        fields = f"[{msg.p_stream}] {fields}"
    fields = strip_nones.sub("", fields)

    fields = textwrap.indent(fields, prefix=(indent * (msg.p_id.count('/') - 1) + " " * 30))
    fields = fields.lstrip(" ")

    return color_other(f"{strftimedelta(msg.p_time):>20}{'':3}{indent * (msg.p_id.count('/') - 1)}{keyword} {fields}\n")
Example #14
0
def format_result(msg, coverages, results):
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return
    test_id = msg["test_id"]

    if results.get(test_id) is None:
        return

    if not results[test_id]["requirements"]:
        del results[test_id]
    else:
        results[test_id]["result"] = msg
Example #15
0
 def format_results(self, data):
     s = "\n## Results\n"
     s += (
         'Test Name | Result | <span style="display: block; min-width: 100px;">Duration</span>\n'
         "--- | --- | --- \n"
     )
     for test in data["tests"]:
         result = test["result"]
         flags = Flags(result["test_flags"])
         if flags & SKIP and settings.show_skipped is False:
             continue
         cls = result["result_type"].lower()
         s += " | ".join([result["result_test"], f'<span class="result result-{cls}">{result["result_type"]}</span>', strftimedelta(result["message_rtime"])]) + "\n"
     return s
Example #16
0
def format_result(msg, result):
    global count
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return

    count += 1
    _result = f"{color_result(result)}"
    # wrap if we hit max width
    if count >= width:
        count = 0
        _result += "\n"

    return _result
Example #17
0
def format_result(msg):
    global count
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return

    count += 1
    _result = f"{color_result(msg['result_type'])}"
    # wrap if we hit max width
    if count >= width:
        count = 0
        _result += "\n"

    return _result
Example #18
0
def format_requirement(msg, coverages, results):
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return
    test_id = msg["test_id"]
    requirement_name = msg["requirement_name"]

    if results.get(test_id) is None:
        return

    results[test_id]["requirements"].append(msg)

    for coverage in coverages:
        if requirement_name in coverage.requirements:
            coverage.requirements[requirement_name].append(results[test_id])
Example #19
0
def format_test(msg, keyword):
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return

    if getattr(TestType, msg["test_type"]) < TestType.Iteration:
        return

    icon = '\u27A4'
    time = f"{strftime(localfromtimestamp(msg['message_time'])):>20}"

    _name = color_test_name(msg["test_name"])
    out = f"{icon} {color_other(time)} {_name}\n"

    return out
Example #20
0
        def get_path(test, idx):
            started = test["test"].started
            ended = started + test["result"].p_time
            path = []

            for t in tests[idx:]:
                flags = Flags(t["test"].p_flags)
                if flags & SKIP and settings.show_skipped is False:
                    continue
                if t["test"].started > ended:
                    break
                if t["test"].p_id.startswith(test["test"].p_id):
                    if t["test"].node:
                        path.append(t["test"].node)

            return path
Example #21
0
 def add_tests(self, requirements, results):
     tests = list(results["tests"].values())
     for i, test in enumerate(tests):
         flags = Flags(test["test"].p_flags)
         if flags & SKIP and settings.show_skipped is False:
             continue
         result = test["result"]
         if result.p_type < TestType.Test:
             continue
         for requirement in test["test"].requirements:
             if requirement.name in requirements:
                 requirements[requirement.name]["tests"].append(
                     self.add_test_messages(test, i, tests,
                                            results["tests_by_parent"],
                                            results["tests_by_id"]))
     return requirements
Example #22
0
def transform(metrics):
    """Transform parsed log into metrics.
    """
    line = None
    while True:
        if line is not None:
            msg = line
            formatter = formatters.get(line["message_keyword"], None)
            if formatter:
                flags = Flags(line["test_flags"])
                if flags & SKIP and settings.show_skipped is False:
                    line = None
                else:
                    line = formatter[0](line, *formatter[1:], metrics)
            else:
                line = None
        line = yield line
Example #23
0
def format_test(msg, counts):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return
    if msg.p_type == TestType.Module:
        counts["module"].units += 1
    elif msg.p_type == TestType.Suite:
        counts["suite"].units += 1
    elif msg.p_type == TestType.Iteration:
        counts["iteration"].units += 1
    elif msg.p_type == TestType.Step:
        counts["step"].units += 1
    else:
        if msg.p_subtype == TestSubType.Feature:
            counts["feature"].units += 1
        elif msg.p_subtype == TestSubType.Scenario:
            counts["scenario"].units += 1
        else:
            counts["test"].units += 1
Example #24
0
 def results_section(self, results):
     s = "\n## Results\n"
     s += (
         'Test Name | Result | <span style="display: block; min-width: 100px;">Duration</span>\n'
         "--- | --- | --- \n")
     for test in results["tests"].values():
         result = test["result"]
         if result.p_type < TestType.Test:
             continue
         flags = Flags(result.p_flags)
         if flags & SKIP and settings.show_skipped is False:
             continue
         cls = result.name.lower()
         s += " | ".join([
             result.test,
             f'<span class="result result-{cls}">{result.name}</span>',
             strftimedelta(result.p_time)
         ]) + "\n"
     return s
Example #25
0
def format_test(msg, last_test_id, keyword):
    flags = Flags(msg["test_flags"])
    if flags & SKIP and settings.show_skipped is False:
        return

    if getattr(TestType, msg["test_type"]) < TestType.Iteration:
        return

    icon = '\u27A4 '

    keyword += format_type(msg)

    _keyword = color_keyword(keyword)
    _name = color_test_name(split(msg["test_name"])[-1])
    _indent = indent * (msg["test_id"].count('/') - 1)
    out = f"{_indent}{icon}{_keyword} {_name}\n"

    last_test_id.append(msg["test_id"])

    return out
Example #26
0
def transform():
    """Transform parsed log line into a procedure format.
    """
    line = None
    while True:
        if line is not None:
            msg = line

            formatter = formatters.get(line["message_keyword"], None)

            if formatter:
                flags = Flags(line["test_flags"])
                if flags & SKIP and settings.show_skipped is False:
                    line = None
                else:
                    line = formatter[0](line, *formatter[1:])
                    last_message[0] = msg
            else:
                line = None
        line = yield line
Example #27
0
def format_result(msg, result):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return

    _result = color_result(result)
    _test = color_test_name(basename(msg.test))

    _indent = indent * (msg.p_id.count('/') - 1)
    out = f"{_indent}{_result}"

    if msg.name in ("Fail", "Error", "Null"):
        out += f" {_test}"
        if msg.message:
            out += color_test_name(",")
            out += f" {color(format_multiline(msg.message, _indent).lstrip(), 'yellow', attrs=['bold'])}"
    elif msg.name.startswith("X"):
        out += f" {_test}"
        if msg.reason:
            out += color_test_name(",")
            out += f" {color(msg.reason, 'blue', attrs=['bold'])}"
    return out + "\n"
Example #28
0
def format_test(msg, last_test_id, keyword):
    flags = Flags(msg.p_flags)
    if flags & SKIP and settings.show_skipped is False:
        return

    if msg.p_type < TestType.Test:
        return

    icon = '\u27A4 '

    keyword += format_type(msg)

    _keyword = color_keyword(keyword)
    _name = color_test_name(split(msg.name)[-1])
    _indent = indent * (msg.p_id.count('/') - 1)
    out = f"{_indent}{icon}{_keyword} {_name}\n"

    if last_test_id:
        last_test_id.pop()
    last_test_id.append(msg.p_id)

    return out
Example #29
0
def transform(no_colors=False, show_input=True):
    """Transform parsed log line into 'manual' format.
    """
    line = None
    while True:
        if line is not None:
            msg = line
            formatter = formatters.get(line["message_keyword"], None)
            if formatter:
                if formatter[0] is format_input and show_input is False:
                    line = None
                else:
                    flags = Flags(line["test_flags"])
                    if flags & SKIP and settings.show_skipped is False:
                        line = None
                    else:
                        line = formatter[0](line,
                                            *formatter[1:],
                                            no_colors=no_colors)
                        last_message[0] = msg
            else:
                line = None
        line = yield line
Example #30
0
def format_result(msg, counts):
    if Flags(msg.p_flags) & SKIP and settings.show_skipped is False:
        return

    _result_name_map = {
        message.RawResultOK: "ok",
        message.RawResultFail: "fail",
        message.RawResultNull: "null",
        message.RawResultError: "error",
        message.RawResultXOK: "xok",
        message.RawResultXFail: "xfail",
        message.RawResultXNull: "xnull",
        message.RawResultXError: "xerror",
        message.RawResultSkip: "skip"
    }

    _name = _result_name_map[type(msg)]

    if msg.p_type == TestType.Module:
        setattr(counts["module"], _name, getattr(counts["module"], _name) + 1)
    elif msg.p_type == TestType.Suite:
        setattr(counts["suite"], _name, getattr(counts["suite"], _name) + 1)
    elif msg.p_type == TestType.Iteration:
        setattr(counts["iteration"], _name,
                getattr(counts["iteration"], _name) + 1)
    elif msg.p_type == TestType.Step:
        setattr(counts["step"], _name, getattr(counts["step"], _name) + 1)
    else:
        if msg.p_subtype == TestSubType.Feature:
            setattr(counts["feature"], _name,
                    getattr(counts["feature"], _name) + 1)
        elif msg.p_subtype == TestSubType.Scenario:
            setattr(counts["scenario"], _name,
                    getattr(counts["scenario"], _name) + 1)
        else:
            setattr(counts["test"], _name, getattr(counts["test"], _name) + 1)