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")])
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)
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?")
def test_npc_line_knows_its_owner(self) -> None: assert NpcLine("I'm Npc!").belongs_to_npc()
def test_line_string_representation(self) -> None: self.assertEqual(repr(NpcLine("I'm Npc!")), 'NpcLine(text="I\'m Npc!")')
def test_line_different_if_text_equal_but_types_differ(self) -> None: self.assertNotEqual(NpcLine('text'), PlayerLine('text'))
def test_line_equal_if_text_and_type_equal(self) -> None: self.assertEqual(NpcLine('text'), NpcLine('text'))