本文整理汇总了Python中tale.player.Player.io方法的典型用法代码示例。如果您正苦于以下问题:Python Player.io方法的具体用法?Python Player.io怎么用?Python Player.io使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tale.player.Player
的用法示例。
在下文中一共展示了Player.io方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wiretap
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_wiretap(self):
attic = Location("Attic", "A dark attic.")
player = Player("fritz", "m")
player.io = ConsoleIo(None)
player.io.supports_smartquotes = False
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.get_output_paragraphs_raw())
with self.assertRaises(SecurityViolation):
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")
output = player.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.get_output_paragraphs_raw())
示例2: test_tell_formatted
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_tell_formatted(self):
player = Player("fritz", "m")
player.io = 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", player.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", player.get_output())
player.tell("word " * 30)
self.assertNotEqual(("word " * 30).strip(), player.get_output())
player.tell("word " * 30, format=False)
self.assertEqual(("word " * 30) + "\n", player.get_output()) # when format=False output should be unformatted
player.tell(" xyz \n 123", format=False)
self.assertEqual(" xyz \n 123\n", player.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.get_output_paragraphs_raw())
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", player.get_output())
示例3: test_peek_output
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_peek_output(self):
player = Player("fritz", "m")
player.io = ConsoleIo(None)
player.set_screen_sizes(0, 100)
player.tell("line1")
player.tell("line2", 42)
self.assertEqual(["line1\nline2\n42\n"], player.peek_output_paragraphs_raw())
self.assertEqual("line1 line2 42\n", player.get_output())
self.assertEqual([], player.peek_output_paragraphs_raw())
示例4: test_write_output
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_write_output(self):
player = Player("julie", "f")
player.io = ConsoleIo(None)
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
player.tell("hello 1", end=True)
player.tell("hello 2", end=True)
player.write_output()
self.assertEqual(" hello 1\n hello 2\n", sys.stdout.getvalue())
finally:
sys.stdout = old_stdout
示例5: test_input
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_input(self):
player = Player("julie", "f")
player.io = ConsoleIo(None)
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
player.tell("first this text")
player.store_input_line("input text\n")
x = player.input("inputprompt")
self.assertEqual("input text", x)
self.assertEqual(" first this text\ninputprompt", sys.stdout.getvalue()) # should have outputted the buffered text
finally:
sys.stdout = old_stdout
示例6: test_tell_formats
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import io [as 别名]
def test_tell_formats(self):
player = Player("fritz", "m")
player.io = 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.get_output_paragraphs_raw())
player.tell("a b c", format=True)
player.tell("d e f", format=True)
self.assertEqual("a b c d e f\n", player.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.get_output_paragraphs_raw())
player.tell("a b c", format=False)
player.tell("d e f", format=False)
self.assertEqual("a b c\nd e f\n", player.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.get_output_paragraphs_raw())
player.tell("a b c", format=True)
player.tell("d e f", format=False)
self.assertEqual("a b c\nd e f\n", player.get_output())