Ejemplo n.º 1
0
 def testGraduallyIncreasingLines(self, indentation_level):
   console_size = self.SetConsoleSize(5 + 2 * indentation_level)
   indentation = ' ' * 2 * indentation_level
   stream = io.StringIO()
   scm = multiline.SuffixConsoleMessage('The',
                                        stream,
                                        indentation_level=indentation_level)
   scm.Print()
   scm._UpdateSuffix(' quick')
   scm.Print()
   scm._UpdateSuffix(' quick brown')
   scm.Print()
   scm._UpdateSuffix(' quick brown fox')
   scm.Print()
   self.assertEqual(
       # Print 1
       '\r' + ' ' * console_size + '\r' +
       indentation + 'The' +
       '\r' + ' ' * console_size + '\r' +
       indentation + 'The q\n' +
       indentation + 'uick' +
       '\r' + ' ' * console_size + '\r' +
       indentation + 'uick \n' +
       indentation + 'brown' +
       '\r' + ' ' * console_size + '\r' +
       indentation + 'brown\n' +
       indentation + ' fox',
       stream.getvalue())
Ejemplo n.º 2
0
 def testNoMessageUpdateNoMessage(self):
   stream = io.StringIO()
   scm = multiline.SuffixConsoleMessage('', stream)
   scm.Print()
   scm._UpdateSuffix('')
   scm.Print()
   self.assertEqual('', stream.getvalue())
Ejemplo n.º 3
0
 def testsingleLinePrefixWithDiffMultilineSuffix(self, indentation_level):
   console_size = self.SetConsoleSize(5 + 2 * indentation_level)
   indentation = ' ' * 2 * indentation_level
   stream = io.StringIO()
   scm = multiline.SuffixConsoleMessage('a' * 5,
                                        stream,
                                        suffix='b' * 10,
                                        indentation_level=indentation_level)
   scm.Print()
   # In this case the multiline print can't do better and is forced to reprint
   # everything.
   scm._UpdateSuffix('c' * 10)
   scm.Print()
   self.assertEqual(
       # Print 1
       '\r' + ' ' * console_size + '\r' +
       indentation + 'aaaaa\n' +
       indentation + 'bbbbb\n' +
       indentation + 'bbbbb' +
       # Print 2
       '\n' +
       indentation + 'aaaaa\n' +
       indentation + 'ccccc\n' +
       indentation + 'ccccc',
       stream.getvalue())
Ejemplo n.º 4
0
 def testTwoDiffMultiThenSingle(self, indentation_level):
   """Tests transition from multiline to different multiline to single line."""
   console_size = self.SetConsoleSize(5 + 2 * indentation_level)
   indentation = ' ' * 2 * indentation_level
   stream = io.StringIO()
   scm = multiline.SuffixConsoleMessage('a' * 5,
                                        stream,
                                        suffix='b' * 10,
                                        indentation_level=indentation_level)
   scm.Print()
   scm._UpdateSuffix('c' * 15)
   scm.Print()
   scm._UpdateSuffix('')
   scm.Print()
   self.assertEqual(
       # Print 1
       '\r' + ' ' * console_size + '\r' +
       indentation + 'aaaaa\n' +
       indentation + 'bbbbb\n' +
       indentation + 'bbbbb' +
       # Print 2
       '\n' +
       indentation + 'aaaaa\n' +
       indentation + 'ccccc\n' +
       indentation + 'ccccc\n' +
       indentation + 'ccccc' +
       '\n' +
       indentation + 'aaaaa',
       stream.getvalue())
Ejemplo n.º 5
0
 def testUpdateWithInvalidMessage(self, new_suffix):
     stream = io.StringIO()
     scm = multiline.SuffixConsoleMessage('', stream)
     with self.assertRaisesRegex(
             TypeError,
             'expected a string or other character buffer object'):
         scm._UpdateSuffix(new_suffix)
Ejemplo n.º 6
0
 def testSinglineBecomesMultilineViaCallback(self, indentation_level):
   console_size = self.SetConsoleSize(15 + 2 * indentation_level)
   indentation = ' ' * 2 * indentation_level
   stream = io.StringIO()
   msg = None
   scm = multiline.SuffixConsoleMessage(
       'a' * 13,
       stream,
       detail_message_callback=lambda: msg,
       indentation_level=indentation_level)
   scm.Print()
   msg = 'b' * 5
   scm.Print()
   scm.Print()
   self.assertEqual(
       # Print 1
       '\r' + ' ' * console_size + '\r' +
       indentation + 'a' * 13 +
       # Print 2
       '\r' + ' ' * console_size + '\r' +
       indentation + 'a' * 13 + 'b' * 2 + '\n' +
       indentation + 'bbb' +
       # Print 3
       '\r' + ' ' * console_size + '\r' +
       indentation + 'bbb',
       stream.getvalue())
Ejemplo n.º 7
0
 def testConsoleTooSmall(self, console_width, indentation):
   self.SetConsoleSize(console_width)
   stream = io.StringIO()
   scm = multiline.SuffixConsoleMessage(
       'a', stream, indentation_level=indentation)
   scm.Print()
   scm.Print()
   self.assertEqual('', stream.getvalue())
Ejemplo n.º 8
0
 def testUpdateMessageInvalidMessage(self):
   stream = io.StringIO()
   ssco = multiline.SimpleSuffixConsoleOutput(stream)
   stray_message = multiline.SuffixConsoleMessage('asdf', stream)
   with self.assertRaisesRegex(
       ValueError,
       'The given message does not belong to this output object.'):
     ssco.UpdateMessage(stray_message, 'fdsa')
Ejemplo n.º 9
0
 def testSingleLinePrintExactConsoleWidth(self, indentation_level):
     console_size = self.SetConsoleSize(15 + 2 * indentation_level)
     indentation = ' ' * 2 * indentation_level
     stream = io.StringIO()
     scm = multiline.SuffixConsoleMessage(
         'a' * 15, stream, indentation_level=indentation_level)
     scm.Print()
     scm.Print()
     self.assertEqual(
         # Print 1
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 15 +
         # Print 2
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 15,
         stream.getvalue())
Ejemplo n.º 10
0
 def testPrintAll(self, indentation_level):
     console_size = self.SetConsoleSize(15 + 2 * indentation_level)
     indentation = ' ' * 2 * indentation_level
     stream = io.StringIO()
     scm = multiline.SuffixConsoleMessage(
         'a' * 20, stream, indentation_level=indentation_level)
     scm.Print()
     scm.Print()
     scm.Print(print_all=True)
     self.assertEqual(
         # Print 1
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 15 + '\n' +
         indentation + 'a' * 5 +
         # Print 2
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 5 +
         # Print 3 with print_all set to True
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 15 + '\n' +
         indentation + 'a' * 5,
         stream.getvalue())
Ejemplo n.º 11
0
 def testSingleLineBecomesMultiline(self, indentation_level):
     console_size = self.SetConsoleSize(15 + 2 * indentation_level)
     indentation = ' ' * 2 * indentation_level
     stream = io.StringIO()
     scm = multiline.SuffixConsoleMessage(
         'a' * 13, stream, indentation_level=indentation_level)
     scm.Print()
     scm._UpdateSuffix('b' * 5)
     scm.Print()
     scm.Print()
     self.assertEqual(
         # Print 1
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 13 +
         # Print 2
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 13 +
         'b' * 2 + '\n' + indentation + 'bbb' +
         # Print 3
         '\r' + ' ' * console_size + '\r' + indentation + 'bbb',
         stream.getvalue())
Ejemplo n.º 12
0
 def testMultilineBecomesSingleline(self, indentation_level):
     console_size = self.SetConsoleSize(15 + 2 * indentation_level)
     indentation = ' ' * 2 * indentation_level
     stream = io.StringIO()
     scm = multiline.SuffixConsoleMessage(
         'a' * 5,
         stream,
         suffix='b' * 15,
         indentation_level=indentation_level)
     scm.Print()
     # This makes the output single line.
     scm._UpdateSuffix('b' * 5)
     scm.Print()
     self.assertEqual(
         # Print 1
         '\r' + ' ' * console_size + '\r' + indentation + 'a' * 5 +
         'b' * 10 + '\n' + indentation + 'bbbbb' +
         # Print 2
         '\n' + indentation + 'a' * 5 + 'b' * 5,
         stream.getvalue())