Пример #1
0
    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.")
Пример #2
0
    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)),
            4,
            "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)),
                                     4,
                                     "red")
        self.assertEqual(printer.string, ".he>llo..world.")
Пример #3
0
    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, "")
Пример #4
0
    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, "")