def process_test(msg, results, names, unique): def add_name(name, names, unique, test_id): _name = name duplicate = 0 if name in unique: duplicate = unique[name] duplicate += 1 _name = f'{name} ~{duplicate}' names[test_id] = _name unique[name] = duplicate return add_name(msg["test_name"], names, unique, msg["test_id"]) test = { "attributes":[], "arguments":[], "tags": [], "specifications": [], "requirements": [], "node": None, "map": [], "examples": [] } test.update(msg) results["tests"][names[msg["test_id"]]] = {"test": test, "result": {"tickets":[], "values":[], "metrics":[]}} process_test_counts(msg, results["counts"]) # add test to the tests map parent = parentname(msg["test_id"]) if results["tests_by_parent"].get(parent) is None: results["tests_by_parent"][parent] = [] results["tests_by_parent"][parent].append(test) results["tests_by_id"][msg["test_id"]] = test
def process_test(msg, results, names, unique): def add_name(name, names, unique, p_id, duplicate=0): _name = name if duplicate: _name = f'{name} ~{duplicate}' if _name in unique: return add_name(name, names, unique, p_id, duplicate + 1) names[p_id] = _name unique.add(_name) return add_name(msg.name, names, unique, msg.p_id) results["tests"][names[msg.p_id]] = {"test": msg} process_test_counts(msg, results["counts"]) # add test to the tests map parent = parentname(msg.p_id) if results["tests_by_parent"].get(parent) is None: results["tests_by_parent"][parent] = [] results["tests_by_parent"][parent].append(msg) results["tests_by_id"][msg.p_id] = msg
def format_test(msg, keyword): flags = Flags(msg.p_flags) if flags & SKIP and settings.show_skipped is False: return # add test to the tests map parent = parentname(msg.p_id) if tests_by_parent.get(parent) is None: tests_by_parent[parent] = [] tests_by_parent[parent].append(msg) tests_by_name[msg.p_id] = msg if msg.p_type == TestType.Module: keyword += "Module" elif msg.p_type == TestType.Suite: if msg.p_subtype == TestSubType.Feature: keyword += "Feature" else: keyword += "Suite" elif msg.p_type == TestType.Iteration: keyword += "Iteration" elif msg.p_type == TestType.Step: if msg.p_subtype == TestSubType.And: keyword += "And" elif msg.p_subtype == TestSubType.Given: keyword += and_keyword(msg, parent, "Given", TestSubType.Given) elif msg.p_subtype == TestSubType.When: keyword += and_keyword(msg, parent, "When", TestSubType.When) elif msg.p_subtype == TestSubType.Then: keyword += and_keyword(msg, parent, "Then", TestSubType.Then) elif msg.p_subtype == TestSubType.By: keyword += and_keyword(msg, parent, "By", TestSubType.By) elif msg.p_subtype == TestSubType.But: keyword += and_keyword(msg, parent, "But", TestSubType.But) elif msg.p_subtype == TestSubType.Finally: keyword += and_keyword(msg, parent, "Finally", TestSubType.Finally) else: keyword += "Step" else: if msg.p_subtype == TestSubType.Scenario: keyword += "Scenario" elif msg.p_subtype == TestSubType.Background: keyword += "Background" else: keyword += "Test" started = strftime(localfromtimestamp(msg.started)) _keyword = color_keyword(keyword) _name = color_other(split(msg.name)[-1]) _indent = f"{started:>20}" + f"{'':3}{indent * (msg.p_id.count('/') - 1)}" out = f"{color_other(_indent)}{_keyword} {_name}{color_other(', flags:' + str(flags) if flags else '')}\n" # convert indent to just spaces _indent = (len(_indent) + 3) * " " if msg.description: out += format_description(msg, _indent) if msg.tags: out += format_tags(msg, _indent) if msg.requirements: out += format_requirements(msg, _indent) if msg.attributes: out += format_attributes(msg, _indent) if msg.users: out += format_users(msg, _indent) if msg.tickets: out += format_tickets(msg, _indent) if msg.args: out += format_arguments(msg, _indent) if msg.examples: out += format_examples(msg, _indent) return out
def format_test(msg, keyword, tests_by_parent, tests_by_id, no_colors=False): # add test to the tests map parent = parentname(msg["test_id"]) if tests_by_parent.get(parent) is None: tests_by_parent[parent] = [] tests_by_parent[parent].append(msg) tests_by_id[msg["test_id"]] = msg test_type = get_type(msg) test_subtype = get_subtype(msg) if test_subtype == TestSubType.Example: keyword += "Example" elif test_type == TestType.Module: keyword += "MODULE" elif test_type == TestType.Suite: if test_subtype == TestSubType.Feature: keyword += "FEATURE" else: keyword += "SUITE" elif test_type == TestType.Iteration: keyword += "Iteration" elif test_type == TestType.Step: if test_subtype == TestSubType.And: keyword += "\u25a1 And" elif test_subtype == TestSubType.Given: keyword += and_keyword(msg, parent, "\u25a1 Given", TestSubType.Given) elif test_subtype == TestSubType.When: keyword += and_keyword(msg, parent, "\u25a1 When", TestSubType.When) elif test_subtype == TestSubType.Then: keyword += and_keyword(msg, parent, "\u25a1 Then", TestSubType.Then) elif test_subtype == TestSubType.By: keyword += and_keyword(msg, parent, "\u25a1 By", TestSubType.By) elif test_subtype == TestSubType.But: keyword += and_keyword(msg, parent, "\u25a1 But", TestSubType.But) elif test_subtype == TestSubType.Finally: keyword += and_keyword(msg, parent, "\u25a1 Finally", TestSubType.Finally) elif test_subtype == TestSubType.Background: keyword += and_keyword(msg, parent, "\u25a1 Background", TestSubType.Background) else: keyword += "\u25a1 Step" elif test_type == TestType.Outline: keyword += "OUTLINE" else: if test_subtype == TestSubType.Scenario: keyword += "SCENARIO" elif test_subtype == TestSubType.Check: keyword += "CHECK" elif test_subtype == TestSubType.Recipe: keyword += "RECIPE" else: keyword += "TEST" _keyword = color_keyword(keyword, no_colors=no_colors) _name = color_test_name(split(msg["test_name"])[-1], no_colors=no_colors) out = "" if test_type > TestType.Step: out += clear_screen() if test_type > TestType.Step: out += f"{separators[test_type]}" out += f"{_keyword} {_name}\n" if msg["test_description"]: out += format_test_description(msg, "", no_colors=no_colors) if test_type > TestType.Step: out += f"{separators[test_type]}" return out
def format_test(msg, keyword): # add test to the tests map parent = parentname(msg["test_id"]) if tests_by_parent.get(parent) is None: tests_by_parent[parent] = [] tests_by_parent[parent].append(msg) tests_by_name[msg["test_id"]] = msg flags = Flags(msg["test_flags"]) test_type = get_type(msg) test_subtype = get_subtype(msg) if test_subtype == TestSubType.Example: keyword += "Example" elif test_type == TestType.Module: keyword += "Module" elif test_type == TestType.Suite: if test_subtype == TestSubType.Feature: keyword += "Feature" else: keyword += "Suite" elif test_type == TestType.Iteration: keyword += "Iteration" elif test_type == TestType.Step: if test_subtype == TestSubType.And: keyword += "And" elif test_subtype == TestSubType.Given: keyword += and_keyword(msg, parent, "Given", TestSubType.Given) elif test_subtype == TestSubType.When: keyword += and_keyword(msg, parent, "When", TestSubType.When) elif test_subtype == TestSubType.Then: keyword += and_keyword(msg, parent, "Then", TestSubType.Then) elif test_subtype == TestSubType.By: keyword += and_keyword(msg, parent, "By", TestSubType.By) elif test_subtype == TestSubType.But: keyword += and_keyword(msg, parent, "But", TestSubType.But) elif test_subtype == TestSubType.Finally: keyword += and_keyword(msg, parent, "Finally", TestSubType.Finally) elif test_subtype == TestSubType.Background: keyword += and_keyword(msg, parent, "Background", TestSubType.Background) else: keyword += "Step" elif test_type == TestType.Outline: keyword += "Outline" else: if test_subtype == TestSubType.Scenario: keyword += "Scenario" elif test_subtype == TestSubType.Check: keyword += "Check" elif test_subtype == TestSubType.Recipe: keyword += "Recipe" else: keyword += "Test" started = strftime(localfromtimestamp(msg["message_time"])) _keyword = color_keyword(keyword) _name = color_other(split(msg["test_name"])[-1]) _indent = f"{started:>20}" + f"{'':3}{indent * (msg['test_id'].count('/') - 1)}" out = f"{color_other(_indent)}{_keyword} {_name}{color_other(', flags:' + str(flags) if flags else '')}\n" # convert indent to just spaces _indent = (len(_indent) + 3) * " " if msg["test_description"]: out += format_test_description(msg, _indent) return out
def format_test(msg, keyword, tests_by_parent, tests_by_id, no_colors=False): # add test to the tests map parent = parentname(msg["test_id"]) if tests_by_parent.get(parent) is None: tests_by_parent[parent] = [] tests_by_parent[parent].append(msg) tests_by_id[msg["test_id"]] = msg test_type = get_type(msg) test_subtype = get_subtype(msg) if test_subtype == TestSubType.Example: keyword += "Example" elif test_type == TestType.Module: keyword += "Module" elif test_type == TestType.Suite: if test_subtype == TestSubType.Feature: keyword += "Feature" else: keyword += "Suite" elif test_type == TestType.Iteration: keyword += "Iteration" elif test_type == TestType.Step: if test_subtype == TestSubType.And: keyword += "And" elif test_subtype == TestSubType.Given: keyword += and_keyword(msg, parent, "Given", TestSubType.Given) elif test_subtype == TestSubType.When: keyword += and_keyword(msg, parent, "When", TestSubType.When) elif test_subtype == TestSubType.Then: keyword += and_keyword(msg, parent, "Then", TestSubType.Then) elif test_subtype == TestSubType.By: keyword += and_keyword(msg, parent, "By", TestSubType.By) elif test_subtype == TestSubType.But: keyword += and_keyword(msg, parent, "But", TestSubType.But) elif test_subtype == TestSubType.Finally: keyword += and_keyword(msg, parent, "Finally", TestSubType.Finally) elif test_subtype == TestSubType.Background: keyword += and_keyword(msg, parent, "Background", TestSubType.Background) else: keyword += "Step" elif test_type == TestType.Outline: keyword += "Outline" else: if test_subtype == TestSubType.Scenario: keyword += "Scenario" elif test_subtype == TestSubType.Check: keyword += "Check" elif test_subtype == TestSubType.Recipe: keyword += "Recipe" else: keyword += "Test" _keyword = color_keyword(keyword, no_colors=no_colors) _name = color_test_name(split(msg["test_name"])[-1], no_colors=no_colors) _indent = indent * (msg["test_id"].count('/') - 1) out = f"{_indent}{_keyword} {_name}\n" if msg["test_description"]: out += format_test_description(msg, _indent, no_colors=no_colors) return out
def format_test(msg, keyword, tests_by_parent, tests_by_id): flags = Flags(msg.p_flags) if flags & SKIP and settings.show_skipped is False: return # add test to the tests map parent = parentname(msg.p_id) if tests_by_parent.get(parent) is None: tests_by_parent[parent] = [] tests_by_parent[parent].append(msg) tests_by_id[msg.p_id] = msg if msg.p_type == TestType.Module: keyword += "Module" elif msg.p_type == TestType.Suite: if msg.p_subtype == TestSubType.Feature: keyword += "Feature" else: keyword += "Suite" elif msg.p_type == TestType.Iteration: keyword += "Iteration" elif msg.p_type == TestType.Step: if msg.p_subtype == TestSubType.And: keyword += "And" elif msg.p_subtype == TestSubType.Given: keyword += and_keyword(msg, parent, "Given", TestSubType.Given) elif msg.p_subtype == TestSubType.When: keyword += and_keyword(msg, parent, "When", TestSubType.When) elif msg.p_subtype == TestSubType.Then: keyword += and_keyword(msg, parent, "Then", TestSubType.Then) elif msg.p_subtype == TestSubType.By: keyword += and_keyword(msg, parent, "By", TestSubType.By) elif msg.p_subtype == TestSubType.But: keyword += and_keyword(msg, parent, "But", TestSubType.But) elif msg.p_subtype == TestSubType.Finally: keyword += and_keyword(msg, parent, "Finally", TestSubType.Finally) else: keyword += "Step" else: if msg.p_subtype == TestSubType.Scenario: keyword += "Scenario" elif msg.p_subtype == TestSubType.Background: keyword += "Background" else: keyword += "Test" _keyword = color_keyword(keyword) _name = color_test_name(split(msg.name)[-1]) _indent = indent * (msg.p_id.count('/') - 1) out = f"{_indent}{_keyword} {_name}\n" if msg.description: out += format_description(msg, _indent) if msg.tags: out += format_tags(msg, _indent) if msg.requirements: out += format_requirements(msg, _indent) if msg.attributes: out += format_attributes(msg, _indent) if msg.users: out += format_users(msg, _indent) if msg.tickets: out += format_tickets(msg, _indent) if msg.args: out += format_arguments(msg, _indent) if msg.examples: out += format_examples(msg, _indent) return out