def __str__(self): s = f"{self.units} {self.name if self.units != 1 else self.name.rstrip('s')} (" s = color(s, "white", attrs=["bold"]) r = [] if self.ok > 0: r.append(color_result("OK", f"{self.ok} ok")) if self.fail > 0: r.append(color_result("Fail", f"{self.fail} failed")) if self.skip > 0: r.append(color_result("Skip", f"{self.skip} skipped")) if self.error > 0: r.append(color_result("Error", f"{self.error} errored")) if self.null > 0: r.append(color_result("Null", f"{self.null} null")) if self.xok > 0: r.append(color_result("XOK", f"{self.xok} xok")) if self.xfail > 0: r.append(color_result("XFail", f"{self.xfail} xfail")) if self.xerror > 0: r.append(color_result("XError", f"{self.xerror} xerror")) if self.xnull > 0: r.append(color_result("XNull", f"{self.xnull} xnull")) s += color(", ", "white", attrs=["bold"]).join(r) s += color(")\n", "white", attrs=["bold"]) return s
def format_argument(msg, no_colors=False): out = [] _indent = indent if not last_message[0] or (last_message[0] and last_message[0]["test_name"] != msg["test_name"]): out.append(format_test(msg, keyword="", no_colors=no_colors)) if not last_message[0] or ( last_message[0] and not last_message[0]["message_keyword"] == Message.ARGUMENT.name or last_message[0]["test_name"] != msg["test_name"]): out.append( f"{_indent}{' ' * 0}{color_secondary_keyword('Arguments', no_colors=no_colors)}" ) out.append( color(f"{_indent}{' ' * 2}{msg['argument_name']}", "white", attrs=["dim"], no_colors=no_colors)) out.append( color(textwrap.indent(f"{msg['argument_value']}", prefix=f"{_indent}{' ' * 4}"), "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def format_specification(msg, no_colors=False): out = [] _indent = indent if not last_message[0] or (last_message[0] and last_message[0]["test_name"] != msg["test_name"]): out.append(format_test(msg, keyword="", no_colors=no_colors)) if not last_message[0] or ( last_message[0] and not last_message[0]["message_keyword"] == Message.SPECIFICATION.name or last_message[0]["test_name"] != msg["test_name"]): out.append( f"{_indent}{' ' * 0}{color_secondary_keyword('Specifications', no_colors=no_colors)}" ) out.append( color(f"{_indent}{' ' * 2}{msg['specification_name']}", "white", attrs=["dim"], no_colors=no_colors)) if msg["specification_version"]: out.append( color(f"{_indent}{' ' * 4}version {msg['specification_version']}", "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def format_attribute(msg, no_colors=False): out = [] _indent = indent if not last_message[0] or (last_message[0] and last_message[0]["test_name"] != msg["test_name"]): out.append(format_test(msg, keyword="", no_colors=no_colors)) if not last_message[0] or ( last_message[0] and not last_message[0]["message_keyword"] == Message.ATTRIBUTE.name or last_message[0]["test_name"] != msg["test_name"]): out.append( f"{_indent}{' ' * 0}{color_secondary_keyword('Attributes', no_colors=no_colors)}" ) out.append( color(f"{_indent}{' ' * 2}{msg['attribute_name']}", "white", attrs=["dim"], no_colors=no_colors)) out.append( color( f"{textwrap.indent(str(msg['attribute_value']), prefix=(_indent + ' ' * 6))}", "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def format_requirement(msg, no_colors=False): out = [] _indent = indent if not last_message[0] or (last_message[0] and last_message[0]["test_name"] != msg["test_name"]): out.append(format_test(msg, keyword="", no_colors=no_colors)) if not last_message[0] or ( last_message[0] and not last_message[0]["message_keyword"] == Message.REQUIREMENT.name or last_message[0]["test_name"] != msg["test_name"]): out.append( f"{_indent}{' ' * 0}{color_secondary_keyword('Requirements', no_colors=no_colors)}" ) out.append( color(f"{_indent}{' ' * 2}{msg['requirement_name']}", "white", attrs=["dim"], no_colors=no_colors)) out.append( color(f"{_indent}{' ' * 4}version {msg['requirement_version']}", "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def format_example(msg, no_colors=False): out = [] _indent = "" row_format = msg["example_row_format"] or ExamplesTable.default_row_format( msg["example_columns"], msg["example_values"]) if last_message[0] and not last_message[0][ "message_keyword"] == Message.EXAMPLE.name: out = [ f"{_indent}{color_secondary_keyword('Examples', no_colors=no_colors)}" ] out.append( color(textwrap.indent( f"{ExamplesTable.__str_header__(tuple(msg['example_columns']),row_format)}", prefix=f"{_indent}{' ' * 2}"), "white", attrs=["dim"], no_colors=no_colors)) out.append( color(textwrap.indent( f"{ExamplesTable.__str_row__(tuple(msg['example_values']),row_format)}", prefix=f"{_indent}{' ' * 2}"), "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def color_result(prefix, result): if result.startswith("X"): return color(prefix + result, "blue", attrs=["bold"]) elif result.endswith("OK"): return color(prefix + result, "green", attrs=["bold"]) elif result.endswith("Skip"): return color(prefix + result, "cyan", attrs=["bold"]) # Error, Fail, Null return color(prefix + result, "red", attrs=["bold"])
def color_result(result): if result.startswith("X"): return color(result, "blue", attrs=["bold"]) elif result == "OK": return color(result, "green", attrs=["bold"]) elif result == "Skip": return color(result, "cyan", attrs=["bold"]) # Error, Fail, Null return color(result, "red", attrs=["bold"])
def format_prompt(msg, last_test_id, keyword): lines = (msg["message"] or "").splitlines() icon = "\u270d " if msg["message"].startswith("Paused"): icon = "\u270b " out = color(icon + lines[0], "yellow", attrs=["bold"]) if len(lines) > 1: out += "\n" + color("\n".join(lines[1:]), "white", attrs=["dim"]) return out
def format_requirements(msg, indent): out = [f"{indent}{' ' * 2}{color_secondary_keyword('Requirements')}"] for req in msg.requirements: out.append( color(f"{indent}{' ' * 4}{req.name}", "white", attrs=["dim"])) out.append( color(f"{indent}{' ' * 6}version {req.version}", "white", attrs=["dim"])) return "\n".join(out) + "\n"
def format_prompt(msg, keyword, no_colors=False): lines = (msg["message"] or "").splitlines() icon = "\u270d " if msg["message"].startswith("Paused"): icon = "\u270b " out = color(icon + lines[0], "white", attrs=["dim"], no_colors=no_colors) if len(lines) > 1: out += "\n" + color( "\n".join(lines[1:]), "white", attrs=["dim"], no_colors=no_colors) return out
def generate(self, output, headings, tested, only): counts = Counts("requirements", *([0] * 4)) for heading in headings: counts.units += 1 indent = " " * (heading.level - 1) if isinstance(heading, Requirement): if tested.get(heading.name) is None: counts.untested += 1 if "untested" in only: output.write( color(f"{indent}\u270E ", "grey", attrs=["bold"]) + color_primary()(f"{heading.num} {heading.name}\n")) output.write( color(f"{indent} no tests\n", "white", attrs=["dim"])) else: _tests = [] _color = None _priority = 0 for test, result in tested.get(heading.name): _tests.append( f"{indent} [ {color_result(result.name)(result.name)} ] " f"{color_secondary()(strftimedelta(result.p_time))} " f"{color_secondary()(test.name)}\n") if result_priority(result.name) > _priority: _color = color_result(result.name) _priority = result_priority(result.name) icon = "\u2714" _include = True if _priority > 2: icon = "\u2718" counts.nok += 1 if "unsatisfied" not in only: _include = False else: if "satisfied" not in only: _include = False counts.ok += 1 if _include: output.write( _color(f"{indent}{icon} ") + color_primary() (f"{heading.num} {heading.name}\n") + "".join(_tests)) else: output.write( color(f"{indent}\u27e5 {heading.num} {heading.name}\n", "white", attrs=["dim"])) # print summary output.write(f"\n{counts}\n")
def format_prompt(msg): global count lines = (msg["message"] or "").splitlines() icon = "\u270d " if msg["message"].startswith("Paused"): icon = "\u270b " out = "" if count > 0: out += "\n" out += color(icon + lines[0], "yellow", attrs=["bold"]) if len(lines) > 1: out += "\n" + color("\n".join(lines[1:]), "white", attrs=["dim"]) count = 0 return out
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
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
def format_requirement(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" if last_message[0] and not last_message[0][ "message_keyword"] == Message.REQUIREMENT.name: out = [f"{_indent}{' ' * 2}{color_secondary_keyword('Requirements')}"] out.append( color(f"{_indent}{' ' * 4}{msg['requirement_name']}", "white", attrs=["dim"])) out.append( color(f"{_indent}{' ' * 6}version {msg['requirement_version']}", "white", attrs=["dim"])) return "\n".join(out) + "\n"
def format_attribute(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" if last_message[0] and not last_message[0][ "message_keyword"] == Message.ATTRIBUTE.name: out = [f"{_indent}{' ' * 2}{color_secondary_keyword('Attributes')}"] out.append( color(f"{_indent}{' ' * 4}{msg['attribute_name']}", "white", attrs=["dim"])) out.append( color( f"{textwrap.indent(str(msg['attribute_value']), prefix=(_indent + ' ' * 6))}", "white", attrs=["dim"])) return "\n".join(out) + "\n"
def format_argument(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" if last_message[0] and not last_message[0][ "message_keyword"] == Message.ARGUMENT.name: out = [f"{_indent}{' ' * 2}{color_secondary_keyword('Arguments')}"] out.append( color(f"{_indent}{' ' * 4}{msg['argument_name']}", "white", attrs=["dim"])) out.append( color(textwrap.indent(f"{msg['argument_value']}", prefix=f"{_indent}{' ' * 6}"), "white", attrs=["dim"])) return "\n".join(out) + "\n"
def format_specification(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" if last_message[0] and not last_message[0][ "message_keyword"] == Message.SPECIFICATION.name: out = [ f"{_indent}{' ' * 2}{color_secondary_keyword('Specifications')}" ] out.append( color(f"{_indent}{' ' * 4}{msg['specification_name']}", "white", attrs=["dim"])) if msg["specification_version"]: out.append( color(f"{_indent}{' ' * 6}version {msg['specification_version']}", "white", attrs=["dim"])) return "\n".join(out) + "\n"
def format_tag(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" if last_message[ 0] and not last_message[0]["message_keyword"] == Message.TAG.name: out = [f"{_indent}{' ' * 2}{color_secondary_keyword('Tags')}"] out.append( color(f"{_indent}{' ' * 4}{msg['tag_value']}", "white", attrs=["dim"])) return "\n".join(out) + "\n"
def __str__(self): s = f"{self.units} {self.name if self.units != 1 else self.name.rstrip('s')} (" s = color(s, "white", attrs=["bold"]) r = [] if self.ok > 0: r.append( color_counts("Satisfied") (f"{self.ok} satisfied {(self.ok / self.units) * 100:.1f}%")) if self.nok > 0: r.append( color_counts("Unsatisfied") (f"{self.nok} unsatisfied {(self.nok / self.units) * 100:.1f}%" )) if self.untested > 0: r.append( color_counts("Untested") (f"{self.untested} untested {(self.untested / self.units) * 100:.1f}%" )) s += color(", ", "white", attrs=["bold"]).join(r) s += color(")\n", "white", attrs=["bold"]) return s
def format_requirement(msg, no_colors=False): out = [] _indent = indent * (msg["test_id"].count('/') - 1) if last_message[0] and not last_message[0][ "message_keyword"] == Message.REQUIREMENT.name: out = [ f"{_indent}{' ' * 2}{color_secondary_keyword('Requirements', no_colors=no_colors)}" ] out.append( color(f"{_indent}{' ' * 4}{msg['requirement_name']}", "white", attrs=["dim"], no_colors=no_colors)) out.append( color(f"{_indent}{' ' * 6}version {msg['requirement_version']}", "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def format_ticket(msg, keyword, no_colors=False): _indent = "" out = [ color_other(f"{keyword}", no_colors=no_colors) + color("Ticket", "white", attrs=["dim", "bold"], no_colors=no_colors) + color_other(f" {msg['ticket_name']}", no_colors=no_colors) ] out.append( color_other(format_multiline(f"{msg['ticket_link']}", _indent + " " * 2), no_colors=no_colors)) return "\n".join(out) + "\n"
def format_metric(msg, keyword, no_colors=False): _indent = "" out = [ color_other(f"{keyword}", no_colors=no_colors) + color("Metric", "white", attrs=["dim", "bold"], no_colors=no_colors) + color_other(f" {msg['metric_name']}", no_colors=no_colors) ] out.append( color_other(format_multiline( f"{msg['metric_value']} {msg['metric_units']}", _indent + " " * 2), no_colors=no_colors)) return "\n".join(out) + "\n"
def format_ticket(msg, keyword): prefix = f"{strftimedelta(msg['message_rtime']):>20}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" _indent = (len(prefix) + 3) * " " out = [ color_other(f"{prefix}{keyword}") + color("Ticket", "white", attrs=["dim", "bold"]) + color_other(f" {msg['ticket_name']}") ] out.append( color_other( format_multiline(f"{msg['ticket_link']}", _indent + " " * 2))) return "\n".join(out) + "\n"
def color_result(result): def result_icon(result): r = result.lstrip("X") if r == "OK": return "\u2714" elif r == "Skip": return "\u2704" elif r == "Error": return "\u2718" elif r == "Fail": return "\u2718" else: return "\u2718" icon = result_icon(result) if result.startswith("X"): return color(icon, "blue", attrs=["bold"]) elif result == "OK": return color(icon, "green", attrs=["bold"]) elif result == "Skip": return color(icon, "white", attrs=["dim"]) elif result == "Error": return color(icon, "yellow", attrs=["bold"]) elif result == "Fail": return color(icon, "red", attrs=["bold"]) # Null return color(icon, "cyan", attrs=["bold"])
def generate(coverages, divider): """Generate report. """ report = "" total_counts = Counts("requirements", units=0, ok=0, nok=0, untested=0) if coverages: report += color(f"{divider}Coverage\n", "white", attrs=["bold"]) for coverage in coverages: report += f"\n{coverage.calculate()}" total_counts.units += coverage.counts.units total_counts.ok += coverage.counts.ok total_counts.nok += coverage.counts.nok total_counts.untested += coverage.counts.untested if len(coverages) > 1: s = color("Total", "white", attrs=["bold", "dim"]) s += f"\n {total_counts}" report += f"\n{s}" return report
def format_attribute(msg, no_colors=False): out = [] _indent = "" if last_message[0] and not last_message[0][ "message_keyword"] == Message.ATTRIBUTE.name: out = [ f"{_indent}{color_secondary_keyword('Attributes', no_colors=no_colors)}" ] out.append( color(f"{_indent}{' ' * 2}{msg['attribute_name']}", "white", attrs=["dim"], no_colors=no_colors)) out.append( color( f"{textwrap.indent(str(msg['attribute_value']), prefix=(' ' * 4))}", "white", attrs=["dim"], no_colors=no_colors)) return "\n".join(out) + "\n"
def generate(results, divider, only_new=False): """Generate report""" if not results: return xfails = "" fails = "" if not only_new: for entry in results: msg, result = results[entry] _color = color_result(result) if not result.startswith("X"): continue xfails += _color( '\u2718') + f" [ { _color(result) } ] {msg['result_test']}" if msg["result_reason"]: xfails += color(f" \u1405 {msg['result_reason']}", "white", attrs=["dim"]) xfails += "\n" if xfails: xfails = color("\nKnown\n\n", "white", attrs=["bold"]) + xfails for entry in results: msg, result = results[entry] _color = color_result(result) if result.startswith("X"): continue fails += _color( "\u2718") + f" [ {_color(result)} ] {msg['result_test']}\n" if fails: fails = color(f"{divider}Failing\n\n", "white", attrs=["bold"]) + fails report = f"{xfails}{fails}" return report or None
def format_example(msg): out = [] _indent = f"{' ':>23}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" row_format = msg["example_row_format"] or ExamplesTable.default_row_format( msg["example_columns"], msg["example_values"]) if last_message[0] and not last_message[0][ "message_keyword"] == Message.EXAMPLE.name: out = [f"{_indent}{' ' * 2}{color_secondary_keyword('Examples')}"] out.append( color(textwrap.indent( f"{ExamplesTable.__str_header__(tuple(msg['example_columns']), row_format)}", prefix=f"{_indent}{' ' * 4}"), "white", attrs=["dim"])) out.append( color(textwrap.indent( f"{ExamplesTable.__str_row__(tuple(msg['example_values']),row_format)}", prefix=f"{_indent}{' ' * 4}"), "white", attrs=["dim"])) return "\n".join(out) + "\n"