def compare_diff(self, pre_snap_file, post_snap_file, check_from_sqlite): """ This function is called when --diff is used """ if check_from_sqlite: lines_a = pre_snap_file.splitlines(True) lines_b = post_snap_file.splitlines(True) headers = ("Snap_1", "Snap_2") options = get_options()[0] cd = ConsoleDiff(cols=int(options.cols), show_all_spaces=options.show_all_spaces, highlight=options.highlight, no_bold=options.no_bold, line_numbers=options.line_numbers, tabsize=int(options.tabsize)) for line in cd.make_table(lines_a, lines_b, headers[0], headers[1], context=(not options.whole_file), numlines=int(options.unified)): codec_print(line, options) sys.stdout.flush() else: if os.path.isfile(pre_snap_file) and os.path.isfile( post_snap_file): diff(pre_snap_file, post_snap_file) else: self.logger_check.info( colorama.Fore.RED + "ERROR!!! Files are not present in given path", extra=self.log_detail)
def pytest_assertrepr_compare(config: Config, op: str, left, right): # Local import to avoid preclusion of pytest's assertion rewriting from dendrol import PatternTree # Resets the red color from the "E" at the start of each pytest # exception/assertion traceback line -- markup() appends a reset # character after its output, so we give it an empty string, # because we only care about that reset. terminal_writer = config.get_terminal_writer() reset_colors = lambda s: terminal_writer.markup('', white=True) + s if op == '==' and isinstance(left, PatternTree) and isinstance(right, PatternTree): left_desc = 'PatternTree(<left>)' right_desc = 'PatternTree(<right>)' rewritten_assert = f'{left_desc} {op} {right_desc}' summary = 'The pattern trees are not equivalent. Full diff:' left_repr = left.serialize() right_repr = right.serialize() differ = ConsoleDiff(tabsize=4, cols=120) diff = differ.make_table( fromdesc=left_desc, fromlines=left_repr.splitlines(), todesc=right_desc, tolines=right_repr.splitlines(), ) lines = [ rewritten_assert, '', summary, '', ] lines.extend( reset_colors(diff_line) for diff_line in diff ) return lines