Best Python code snippet using lemoncheesecake
console.py
Source:console.py  
...36    return _serialize_metadata(37        obj.tags, obj.properties, obj.links,38        disabled=not hide_disabled and getattr(obj, "disabled", False)39    )40def serialize_hierarchy_metadata(obj, hide_disabled=False):41    return _serialize_metadata(42        obj.hierarchy_tags, obj.hierarchy_properties, obj.hierarchy_links,43        disabled=not hide_disabled and (hasattr(obj, "is_disabled") and obj.is_disabled())44    )45class Renderer(object):46    def __init__(self, max_width, explicit=False, highlight=None, show_debug_logs=False):47        self.max_width = max_width48        self.explicit = explicit49        self.highlight = highlight50        self.show_debug_logs = show_debug_logs51        # "20" is an approximation of the maximal overhead of table border, padding, and table first cell52        self._table_overhead = 2053    def wrap_description_col(self, description):54        return wrap_text(description, int((self.max_width - self._table_overhead) * 0.75))55    def wrap_details_col(self, details):56        return wrap_text(details, int((self.max_width - self._table_overhead) * 0.25))57    def render_check_outcome(self, is_successful):58        if self.explicit:59            check_label = "CHECK %s" % ("OK" if is_successful else "KO")60        else:61            check_label = "CHECK"62        return colored(check_label, color=outcome_to_color(is_successful), attrs=["bold"])63    def render_highlighted(self, content):64        if not self.highlight or not content:65            return content66        return self.highlight.sub(67            lambda m: colored(m.group(0), color="yellow", attrs=["bold", "underline"]), content68        )69    def render_step_log(self, log):70        if isinstance(log, Log):71            if log.level == "debug" and not self.show_debug_logs:72                return None73            else:74                return [75                    colored(log.level.upper(), color=log_level_to_color(log.level), attrs=["bold"]),76                    self.render_highlighted(self.wrap_description_col(log.message))77                ]78        if isinstance(log, Check):79            return [80                self.render_check_outcome(log.is_successful),81                self.render_highlighted(self.wrap_description_col(log.description)),82                self.render_highlighted(self.wrap_details_col(log.details))83            ]84        if isinstance(log, Url):85            if log.description == log.url:86                description = log.url87            else:88                description = "%s (%s)" % (log.url, log.description)89            return [90                colored("URL", color="cyan", attrs=["bold"]),91                self.render_highlighted(self.wrap_description_col(description))92            ]93        if isinstance(log, Attachment):94            return [95                colored("ATTACH", color="cyan", attrs=["bold"]),96                self.render_highlighted(self.wrap_description_col(log.description)),97                self.render_highlighted(log.filename)98            ]99        raise ValueError("Unknown step log class '%s'" % log.__class__.__name__)100    def render_steps(self, steps):101        rows = []102        for step in steps:103            step_log_rows = list(filter(bool, map(self.render_step_log, step.get_logs())))104            if step_log_rows:105                rows.append([106                    "",107                    colored(108                        self.render_highlighted(self.wrap_description_col(step.description)),109                        color=outcome_to_color(step.is_successful()),110                        attrs=["bold"]111                    ),112                    colored(humanize_duration(step.duration, show_milliseconds=True), attrs=["bold"])113                        if step.duration is not None else "-"114                ])115                rows.extend(step_log_rows)116        if not rows:117            return None118        table = AsciiTable(rows)119        table.inner_heading_row_border = False120        table.justify_columns[0] = "center"121        table.inner_row_border = True122        return table.table123    def render_chunk(self, description, short_description, status, steps):124        if status is None:125            status = "in_progress"126        if steps:127            details = self.render_steps(steps) or "n/a"128        else:129            details = "n/a"130        parts = [131            colored(132                "%s: %s" % (status.upper(), description) if self.explicit else description,133                color=test_status_to_color(status),134                attrs=["bold"]135            )136        ]137        if short_description:138            parts.append(colored("(%s)" % short_description, attrs=["bold"]))139        parts.append(details)140        return "\n".join(parts)141    def render_test(self, test):142        test_metadata = serialize_hierarchy_metadata(test, hide_disabled=True)143        if test_metadata:144            short_description = "%s - %s" % (test.path, test_metadata)145        else:146            short_description = test.path147        return self.render_chunk(test.description, short_description, test.status, test.get_steps())148    def render_result(self, result):149        if result.type == "suite_setup":150            description = "- SUITE SETUP - %s" % result.parent_suite.description151            short_description = result.parent_suite.path152        elif result.type == "suite_teardown":153            description = "- SUITE TEARDOWN - %s" % result.parent_suite.description154            short_description = result.parent_suite.path155        elif result.type == "test_session_setup":156            description = "- TEST SESSION SETUP -"...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
