def test_print_spaces_tabs_in_unicode(self): printer = StringPrinter() sh = SpacingHelper(4) test_string = "\the\tllo world " print_spaces_tabs_in_unicode( printer, test_string, dict(sh.yield_tab_lengths(test_string)), "red") self.assertEqual(printer.string, "--->he->llo•world•••") # Test the case when the bullet can't be printed because of encoding # problems. def hijack_print(text, *args, **kwargs): if "•" in text: raise UnicodeEncodeError("test-codec", "", 0, 1, "") else: return StringPrinter.print(printer, text, *args, **kwargs) printer.print = hijack_print printer.clear() test_string = " he\tllo world " print_spaces_tabs_in_unicode(printer, test_string, dict(sh.yield_tab_lengths(test_string)), "red") self.assertEqual(printer.string, ".he>llo..world.")
def test_print_spaces_tabs_in_unicode(self): printer = StringPrinter() sh = SpacingHelper(4) test_string = "\the\tllo world " print_spaces_tabs_in_unicode(printer, test_string, dict(sh.yield_tab_lengths(test_string)), "red") self.assertEqual(printer.string, "--->he->llo•world•••") # Test the case when the bullet can't be printed because of encoding # problems. def hijack_print(text, *args, **kwargs): if "•" in text: raise UnicodeEncodeError("test-codec", "", 0, 1, "") else: return StringPrinter.print(printer, text, *args, **kwargs) printer.print = hijack_print printer.clear() test_string = " he\tllo world " print_spaces_tabs_in_unicode(printer, test_string, dict(sh.yield_tab_lengths(test_string)), "red") self.assertEqual(printer.string, ".he>llo..world.")
def print_lines(console_printer, file_dict, section, sourcerange): """ Prints the lines between the current and the result line. If needed they will be shortened. :param console_printer: Object to print messages on the console. :param file_dict: A dictionary containing all files as values with filenames as key. :param sourcerange: The SourceRange object referring to the related lines to print. """ for i in range(sourcerange.start.line, sourcerange.end.line + 1): console_printer.print(format_lines(lines='', line_nr=i), color=FILE_LINES_COLOR, end='') line = file_dict[sourcerange.file][i - 1].rstrip("\n") tab_width = int(section.get('tab_width', 4)) s = SpacingHelper(tab_width) tab_dict = dict(s.yield_tab_lengths(line)) printed_chars = 0 if i == sourcerange.start.line and sourcerange.start.column: print_spaces_tabs_in_unicode( console_printer, line[:sourcerange.start.column-1], tab_dict, FILE_LINES_COLOR) printed_chars = sourcerange.start.column-1 if i == sourcerange.end.line and sourcerange.end.column: print_spaces_tabs_in_unicode( console_printer, line[printed_chars:sourcerange.end.column-1], tab_dict, HIGHLIGHTED_CODE_COLOR, printed_chars) print_spaces_tabs_in_unicode( console_printer, line[sourcerange.end.column-1:], tab_dict, FILE_LINES_COLOR, sourcerange.end.column) console_printer.print("") else: print_spaces_tabs_in_unicode( console_printer, line[printed_chars:], tab_dict, HIGHLIGHTED_CODE_COLOR, printed_chars) console_printer.print("")
def print_lines(console_printer, file_dict, section, sourcerange): """ Prints the lines between the current and the result line. If needed they will be shortened. :param console_printer: Object to print messages on the console. :param file_dict: A dictionary containing all files as values with filenames as key. :param sourcerange: The SourceRange object referring to the related lines to print. """ for i in range(sourcerange.start.line, sourcerange.end.line + 1): console_printer.print(format_lines(lines='', line_nr=i), color=FILE_LINES_COLOR, end='') line = file_dict[sourcerange.file][i - 1].rstrip("\n") tab_width = int(section.get('tab_width', 4)) s = SpacingHelper(tab_width) tab_dict = dict(s.yield_tab_lengths(line)) printed_chars = 0 if i == sourcerange.start.line and sourcerange.start.column: print_spaces_tabs_in_unicode( console_printer, line[:sourcerange.start.column-1], tab_dict, FILE_LINES_COLOR) printed_chars = sourcerange.start.column-1 if i == sourcerange.end.line and sourcerange.end.column: print_spaces_tabs_in_unicode( console_printer, line[printed_chars:sourcerange.end.column-1], tab_dict, HIGHLIGHTED_CODE_COLOR, printed_chars) print_spaces_tabs_in_unicode( console_printer, line[sourcerange.end.column-1:], tab_dict, FILE_LINES_COLOR, sourcerange.end.column-1) console_printer.print("") else: print_spaces_tabs_in_unicode( console_printer, line[printed_chars:], tab_dict, HIGHLIGHTED_CODE_COLOR, printed_chars) console_printer.print("")