示例#1
0
 def test_dialogs_are_added_to_previously_defined_stage(self) -> None:
     dialog = Dialog()
     dialog.add_player_line("I'm the player.")
     dialog.set_next_stage(fired_by=Event('Rat killed'))
     dialog.add_npc_line("I'm Npc. You have killed a rat")
     dialog.add_player_line("Yes I did!")
     dialog.set_next_stage(fired_by=Event('Huge Rat killed'))
     dialog.add_npc_line("Wow you have killed a Huuuge rat")
     self.assertEqual(dialog.lines_for_stage(0),
                      [PlayerLine("I'm the player.")])
     self.assertEqual(dialog.lines_for_stage(1), [
         NpcLine("I'm Npc. You have killed a rat"),
         PlayerLine("Yes I did!"),
     ])
     self.assertEqual(dialog.lines_for_stage(2),
                      [NpcLine("Wow you have killed a Huuuge rat")])
示例#2
0
 def test_presents_line_for_next_stage_if_specific_event_happened(
         self) -> None:
     dialog = Dialog()
     dialog.add_player_line("I'm the player.")
     dialog.set_next_stage(fired_by=Event('Rat killed'))
     dialog.add_npc_line("I'm Npc. You have killed a rat")
     dialog.add_player_line("Yes I did!")
     dialog.handle(event=Event('Rat killed'))
     lines = dialog.lines()
     self.assertEqual(next(lines),
                      NpcLine("I'm Npc. You have killed a rat"))
     self.assertEqual(next(lines), PlayerLine("Yes I did!"))
     with self.assertRaises(StopIteration):
         next(lines)
示例#3
0
 def test_dialog_can_have_npc_lines(self) -> None:
     dialog = Dialog()
     dialog.add_npc_line("I'm Npc. What's your name?")
     assert next(dialog.lines()) == NpcLine("I'm Npc. What's your name?")
示例#4
0
 def test_npc_line_knows_its_owner(self) -> None:
     assert NpcLine("I'm Npc!").belongs_to_npc()
示例#5
0
 def test_line_string_representation(self) -> None:
     self.assertEqual(repr(NpcLine("I'm Npc!")),
                      'NpcLine(text="I\'m Npc!")')
示例#6
0
 def test_line_different_if_text_equal_but_types_differ(self) -> None:
     self.assertNotEqual(NpcLine('text'), PlayerLine('text'))
示例#7
0
 def test_line_equal_if_text_and_type_equal(self) -> None:
     self.assertEqual(NpcLine('text'), NpcLine('text'))