Beispiel #1
0
 def test_wiretap(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("fritz", "m")
     io = ConsoleIo(None)
     io.supports_smartquotes = False
     pc = PlayerConnection(player, io)
     player.set_screen_sizes(0, 100)
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"], player.test_get_output_paragraphs())
     with self.assertRaises(ActionRefused):
         player.create_wiretap(julie)
     player.privileges = {"wizard"}
     player.create_wiretap(julie)
     player.create_wiretap(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     pubsub.sync()
     output = pc.get_output()
     self.assertTrue("[wiretapped from 'Attic': message for room]" in output)
     self.assertTrue("[wiretapped from 'julie': message for julie]" in output)
     self.assertTrue("[wiretapped from 'julie': message for room]" in output)
     self.assertTrue("message for room " in output)
     # test removing the wiretaps
     player.clear_wiretaps()
     import gc
     gc.collect()
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"], player.test_get_output_paragraphs())
Beispiel #2
0
 def test_complete_one(self):
     player = Player("fritz", "m")
     driver = TestDriver()
     conn = PlayerConnection(player)
     io = IoAdapterBase(conn)
     conn.io = io
     self.assertEqual(["criticize"], io.tab_complete("critic", driver))
Beispiel #3
0
 def test_tell_formats(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("a b c", format=True)
     player.tell("d e f", format=True)
     self.assertEqual(["a b c\nd e f\n"],
                      player.test_get_output_paragraphs())
     player.tell("a b c", format=True)
     player.tell("d e f", format=True)
     self.assertEqual("a b c d e f\n", pc.get_output())
     player.tell("a b c", format=False)
     player.tell("d e f", format=False)
     self.assertEqual(["a b c\nd e f\n"],
                      player.test_get_output_paragraphs())
     player.tell("a b c", format=False)
     player.tell("d e f", format=False)
     self.assertEqual("a b c\nd e f\n", pc.get_output())
     player.tell("a b c", format=True)
     player.tell("d e f", format=False)
     self.assertEqual(["a b c\n", "d e f\n"],
                      player.test_get_output_paragraphs())
     player.tell("a b c", format=True)
     player.tell("d e f", format=False)
     self.assertEqual("a b c\nd e f\n", pc.get_output())
Beispiel #4
0
 def test_complete_one(self):
     player = Player("fritz", "m")
     driver = TestDriver()
     conn = PlayerConnection(player)
     io = IoAdapterBase(conn)
     conn.io = io
     self.assertEqual(["criticize"], io.tab_complete("critic", driver))
Beispiel #5
0
 def test_build(self):
     conn = PlayerConnection()
     with WrappedConsoleIO(conn) as io:
         conn.io = io
         b = CharacterBuilder(conn, None)
         builder = b.build_async()
         why, what = next(builder)
         self.assertEqual("input", why)
Beispiel #6
0
 def test_build(self):
     conn = PlayerConnection()
     with WrappedConsoleIO(conn) as io:
         conn.io = io
         b = CharacterBuilder(conn, None)
         builder = b.build_async()
         why, what = next(builder)
         self.assertEqual("input", why)
Beispiel #7
0
 def test_input(self):
     player = Player("julie", "f")
     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
Beispiel #8
0
 def test_peek_output(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("line1")
     player.tell("line2", 42)
     self.assertEqual(["line1\nline2 42\n"], player.test_peek_output_paragraphs())
     self.assertEqual("line1 line2 42\n", pc.get_output())
     self.assertEqual([], player.test_peek_output_paragraphs())
Beispiel #9
0
 def test_write_output(self):
     player = Player("julie", "f")
     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())
Beispiel #10
0
 def test_write_output(self):
     player = Player("julie", "f")
     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())
Beispiel #11
0
 def test_tell_sep(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 10)
     player.tell("apple", "bee", "zinc", "rose")
     self.assertEqual(["apple bee zinc rose\n"], player.test_get_output_paragraphs())
     pc.get_output()
     player.tell("apple", "bee", "zinc", "rose", format=False)
     self.assertEqual("apple\nbee\nzinc\nrose\n", pc.get_output())
Beispiel #12
0
 def test_if_build(self):
     conn = PlayerConnection()
     conf = StoryConfig()
     with WrappedConsoleIO(conn) as io:
         conn.io = io
         b = IFCharacterBuilder(conn, conf)
         builder = b.build_character()
         why, what = next(builder)
         self.assertEqual("input", why)
         self.assertEqual("What shall you be known as?", what[0])
Beispiel #13
0
 def test_peek_output(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("line1")
     player.tell("line2", 42)
     self.assertEqual(["line1\nline2 42\n"],
                      player.test_peek_output_paragraphs())
     self.assertEqual("line1 line2 42\n", pc.get_output())
     self.assertEqual([], player.test_peek_output_paragraphs())
Beispiel #14
0
 def test_tell_sep(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 10)
     player.tell("apple", "bee", "zinc", "rose")
     self.assertEqual(["apple bee zinc rose\n"],
                      player.test_get_output_paragraphs())
     pc.get_output()
     player.tell("apple", "bee", "zinc", "rose", format=False)
     self.assertEqual("apple\nbee\nzinc\nrose\n", pc.get_output())
Beispiel #15
0
 def test_input(self):
     player = Player("julie", "f")
     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
Beispiel #16
0
 def test_mud_build(self):
     conn = PlayerConnection()
     conf = StoryConfig()
     with WrappedConsoleIO(conn) as io:
         conn.io = io
         b = MudCharacterBuilder(conn, "PETER", conf)
         self.assertEqual("peter", b.naming.name)
         builder = b.build_character()
         why, what = next(builder)
         self.assertEqual("input-noecho", why)
         self.assertEqual("Please type in the desired password.", what[0])
Beispiel #17
0
 def test_complete_c(self):
     player = Player("fritz", "m")
     driver = TestDriver()
     conn = PlayerConnection(player)
     io = IoAdapterBase(conn)
     conn.io = io
     result = io.tab_complete("c", driver)
     self.assertGreater(len(result), 20)
     self.assertTrue("cackle" in result)
     self.assertTrue("criticize" in result)
     result = io.tab_complete("h", driver)
     self.assertGreater(len(result), 10)
     self.assertTrue("hiss" in result)
Beispiel #18
0
 def test_complete_c(self):
     player = Player("fritz", "m")
     driver = TestDriver()
     conn = PlayerConnection(player)
     io = IoAdapterBase(conn)
     conn.io = io
     result = io.tab_complete("c", driver)
     self.assertGreater(len(result), 20)
     self.assertTrue("cackle" in result)
     self.assertTrue("criticize" in result)
     result = io.tab_complete("h", driver)
     self.assertGreater(len(result), 10)
     self.assertTrue("hiss" in result)
Beispiel #19
0
 def test_tell_formatted(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("line1")
     player.tell("line2", "\n")
     player.tell("hello\nnewline")
     player.tell("\n")  # paragraph separator
     player.tell("ints", 42, 999)
     self.assertEqual("line1 line2 hello newline\nints 42 999\n", pc.get_output())
     player.tell("para1", end=False)
     player.tell("para2", end=True)
     player.tell("para3")
     player.tell("\n")
     player.tell("para4", "\n", "para5")
     self.assertEqual("para1 para2\npara3\npara4   para5\n", pc.get_output())
     player.tell("word " * 30)
     self.assertNotEqual(("word " * 30).strip(), pc.get_output())
     player.tell("word " * 30, format=False)
     self.assertEqual(("word " * 30) + "\n", pc.get_output())  # when format=False output should be unformatted
     player.tell("   xyz   \n  123", format=False)
     self.assertEqual("   xyz   \n  123\n", pc.get_output())
     player.tell("line1", end=True)
     player.tell("\n")
     player.tell("line2", end=True)
     player.tell("\n")
     player.tell("\n")
     self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"], player.test_get_output_paragraphs())
     player.tell("line1", end=True)
     player.tell("\n")
     player.tell("line2", end=True)
     player.tell("\n")
     player.tell("\n")
     self.assertEqual("line1\n\nline2\n\n\n", pc.get_output())
Beispiel #20
0
 def test_idle(self):
     p = Player("dummy", "f")
     c = PlayerConnection(p, WrappedConsoleIO(None))
     self.assertLess(p.idle_time, 0.1)
     self.assertLess(c.idle_time, 0.1)
     time.sleep(0.2)
     self.assertGreater(p.idle_time, 0.1)
     self.assertGreater(c.idle_time, 0.1)
     p.store_input_line("input")
     self.assertLess(p.idle_time, 0.1)
     self.assertLess(c.idle_time, 0.1)
Beispiel #21
0
 def test_tell_formats(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("a b c", format=True)
     player.tell("d e f", format=True)
     self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs())
     player.tell("a b c", format=True)
     player.tell("d e f", format=True)
     self.assertEqual("a b c d e f\n", pc.get_output())
     player.tell("a b c", format=False)
     player.tell("d e f", format=False)
     self.assertEqual(["a b c\nd e f\n"], player.test_get_output_paragraphs())
     player.tell("a b c", format=False)
     player.tell("d e f", format=False)
     self.assertEqual("a b c\nd e f\n", pc.get_output())
     player.tell("a b c", format=True)
     player.tell("d e f", format=False)
     self.assertEqual(["a b c\n", "d e f\n"], player.test_get_output_paragraphs())
     player.tell("a b c", format=True)
     player.tell("d e f", format=False)
     self.assertEqual("a b c\nd e f\n", pc.get_output())
Beispiel #22
0
 def test_wiretap(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("fritz", "m")
     io = ConsoleIo(None)
     io.supports_smartquotes = False
     pc = PlayerConnection(player, io)
     player.set_screen_sizes(0, 100)
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())
     with self.assertRaises(ActionRefused):
         player.create_wiretap(julie)
     player.privileges = {"wizard"}
     player.create_wiretap(julie)
     player.create_wiretap(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     pubsub.sync()
     output = pc.get_output()
     self.assertTrue(
         "[wiretapped from 'Attic': message for room]" in output)
     self.assertTrue(
         "[wiretapped from 'julie': message for julie]" in output)
     self.assertTrue(
         "[wiretapped from 'julie': message for room]" in output)
     self.assertTrue("message for room " in output)
     # test removing the wiretaps
     player.clear_wiretaps()
     import gc
     gc.collect()
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())
Beispiel #23
0
 def test_tell_formatted(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("line1")
     player.tell("line2")
     player.tell("\n")
     player.tell("hello\nnewline")
     player.tell("\n")  # paragraph separator
     player.tell("ints")
     player.tell(42)
     player.tell(999)
     self.assertEqual("line1 line2\nhello newline\nints 42 999\n",
                      pc.get_output())
     player.tell("para1", end=False)
     player.tell("para2", end=True)
     player.tell("para3")
     player.tell("\n")
     player.tell("para4")
     player.tell("\n")
     player.tell("para5")
     self.assertEqual("para1 para2\npara3\npara4\npara5\n", pc.get_output())
     player.tell("word " * 30)
     self.assertNotEqual(("word " * 30).strip(), pc.get_output())
     player.tell("word " * 30, format=False)
     self.assertEqual(
         ("word " * 30) + "\n",
         pc.get_output())  # when format=False output should be unformatted
     player.tell("   xyz   \n  123", format=False)
     self.assertEqual("   xyz   \n  123\n", pc.get_output())
     player.tell("line1", end=True)
     player.tell("\n")
     player.tell("line2", end=True)
     player.tell("\n")
     player.tell("\n")
     self.assertEqual(["line1\n", "\n", "line2\n", "\n", "\n"],
                      player.test_get_output_paragraphs())
     player.tell("line1", end=True)
     player.tell("\n")
     player.tell("line2", end=True)
     player.tell("\n")
     player.tell("\n")
     self.assertEqual("line1\n\nline2\n\n\n", pc.get_output())
Beispiel #24
0
 def test_destroy(self):
     pc = PlayerConnection(None, ConsoleIo(None))
     pc.destroy()
     self.assertIsNone(pc.player)
     self.assertIsNone(pc.io)
Beispiel #25
0
 def test_destroy(self):
     pc = PlayerConnection(None, ConsoleIo(None))
     pc.destroy()
     self.assertIsNone(pc.player)
     self.assertIsNone(pc.io)