def test_write_output(self): player = Player("julie", "f") player.prompt_toolkit_enabled = False with WrappedConsoleIO(None) as io: pc = PlayerConnection(player, io) player.tell("hello 1", end=True) player.tell("hello 2", end=True) pc.write_output() self.assertEqual(" hello 2", pc.last_output_line) self.assertEqual(" hello 1\n hello 2\n", sys.stdout.getvalue())
def test_peek_output(self): player = Player("fritz", "m") pc = PlayerConnection(player, ConsoleIo(None)) player.prompt_toolkit_enabled = False player.set_screen_sizes(0, 100) player.tell("line1") player.tell("line2") self.assertEqual(["line1\nline2\n"], player.test_peek_output_paragraphs()) self.assertEqual("line1 line2\n", pc.get_output()) self.assertEqual([], player.test_peek_output_paragraphs())
def test_input(self): player = Player("julie", "f") player.prompt_toolkit_enabled = False with WrappedConsoleIO(None) as io: pc = PlayerConnection(player, io) player.tell("first this text") player.store_input_line(" input text \n") x = pc.input_direct("inputprompt") self.assertEqual("input text", x) self.assertEqual(" first this text\ninputprompt ", sys.stdout.getvalue() ) # should have outputted the buffered text