def testUpdateMessageInvalidMessage(self): stream = io.StringIO() mco = multiline.MultilineConsoleOutput(stream) stray_message = multiline.MultilineConsoleMessage('asdf', stream) with self.assertRaisesRegex( ValueError, 'The given message does not belong to this output object.'): mco.UpdateMessage(stray_message, 'fdsa')
def testPrintAddsNewlineToLastLine(self, indentation_level): console_size = self.SetConsoleSize(15 + 2 * indentation_level) indentation = ' ' * 2 * indentation_level stream = io.StringIO() scm = multiline.MultilineConsoleMessage( 'My message', stream, indentation_level=indentation_level) scm.Print() scm.Print() self.assertEqual( # Print 1 '\r' + ' ' * console_size + '\r' + indentation + 'My message\n' + # Print 2 '\r' + ' ' * console_size + '\r' + indentation + 'My message\n', stream.getvalue())
def testHasUpdate(self, indentation_level): console_size = self.SetConsoleSize(15 + 2 * indentation_level) indentation = ' ' * 2 * indentation_level stream = io.StringIO() scm = multiline.MultilineConsoleMessage( 'My message', stream, indentation_level=indentation_level) self.assertTrue(scm.has_update) scm.Print() self.assertFalse(scm.has_update) scm._UpdateMessage('egassem yM') self.assertTrue(scm.has_update) scm.Print() self.assertFalse(scm.has_update) self.assertEqual( # Print 1 '\r' + ' ' * console_size + '\r' + indentation + 'My message\n' + # Print 2 '\r' + ' ' * console_size + '\r' + indentation + 'egassem yM\n', stream.getvalue())