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 test_clear(self): uut = StringPrinter() self.assertEqual(uut.string, "") uut.clear() self.assertEqual(uut.string, "") uut.print("1") self.assertEqual(uut.string, "1\n") uut.clear() self.assertEqual(uut.string, "") uut.print(1000 * "#") self.assertEqual(uut.string, 1000 * "#" + "\n") uut.clear() self.assertEqual(uut.string, "")
def test_printing(self): uut = StringPrinter() self.assertEqual(uut.string, "") uut.print("ABC") self.assertEqual(uut.string, "ABC\n") uut.print("XYZ") self.assertEqual(uut.string, "ABC\nXYZ\n") uut.print("\nHello World.") self.assertEqual(uut.string, "ABC\nXYZ\n\nHello World.\n")
def hijack_print(text, *args, **kwargs): if "•" in text: raise UnicodeEncodeError("test-codec", "", 0, 1, "") else: return StringPrinter.print(printer, text, *args, **kwargs)