Exemple #1
0
    def testPrintPacked(self):
        matches = ['foo', 'bar', 'spam', 'eggs', 'python', 'perl']
        longest_match_len = max(len(m) for m in matches)
        max_lines = 10

        for width in (1, 10, 20, 30, 40, 50):
            f = cStringIO.StringIO()
            n = comp_ui._PrintPacked(matches, longest_match_len, width,
                                     max_lines, f)

            out = f.getvalue()
            lines = out.splitlines()
            max_len = max(len(line) for line in lines)

            print('WIDTH = %d' % width)
            print('reported lines = %d' % n)
            print('measured lines = %d' % len(lines))
            print('max_len = %d' % max_len)

            # Make sure it fits in the width!

            # NOTE: This is too conservative because of non-printable characters
            # like \n and ANSI escapes
            if width != 1:
                self.assertLess(max_len, width)

            print('')
Exemple #2
0
    def testLongStringAndSkinnyTerminal(self):
        matches = ['foo' * 10, 'bar' * 10, 'spams' * 10, 'zzz']
        longest_match_len = max(len(m) for m in matches)

        for width in (1, 10, 20, 30, 40, 50):
            f = cStringIO.StringIO()
            n = comp_ui._PrintPacked(matches, longest_match_len, width, 10, f)

            out = f.getvalue()
            lines = out.splitlines()
            max_len = max(len(line) for line in lines)

            print('WIDTH = %d' % width)
            print('reported lines = %d' % n)
            print('measured lines = %d' % len(lines))
            print('max_len = %d' % max_len)
            print('')
Exemple #3
0
    def testTooMany(self):
        matches = ['--flag%d' % i for i in xrange(100)]
        longest_match_len = max(len(m) for m in matches)

        for width in (1, 10, 20, 30, 40, 50, 60):
            f = cStringIO.StringIO()
            n = comp_ui._PrintPacked(matches, longest_match_len, width, 10, f)

            out = f.getvalue()
            lines = out.splitlines()
            max_len = max(len(line) for line in lines)

            print('WIDTH = %d' % width)
            print('reported lines = %d' % n)
            # Count newlines since last one doesn't have a newline
            print('measured lines = %d' % out.count('\n'))
            print('max_len = %d' % max_len)
            print('')