opal.showVerbIobj = sarahOpalFunc howgethere = SpecialTopic( game, "ask how you got here", 'You ask Sarah how you got here. She bites her lip. <br> "There was a storm," she says. "Your ship crashed on shore. I brought you inside."', ) def sarahDefault(game): game.addText(sarah.default_topic) storm_concept.makeKnown(me) sarah.addSpecialTopic(howgethere) sarah.defaultTopic = sarahDefault opalTopic = Topic( game, '"I should never it from the cave," says Sarah. "I want nothing to do with it. If you\'re smart, you\'ll leave it where you found it."', ) sarah.addTopic("asktell", opalTopic, opal) shackTopic = Topic( game, '"It\'s not such a bad place, this shack," Sarah says. "It\'s warm. Safe."' ) sarah.addTopic("asktell", shackTopic, shack_concept) key2Topic = Topic( game,
class TestConversationVerbs(IFPTestCase): def setUp(self): super().setUp() self.item = Thing(self.game, "mess") self.actor = Actor(self.game, "Jenny") self.start_room.addThing(self.item) self.start_room.addThing(self.actor) self.CANNOT_TALK_MSG = "You cannot talk to that. " self.topic = Topic(self.game, '"Ah, yes," says Jenny mysteriously. ') def test_ask_inanimate(self): AskVerb()._runVerbFuncAndEvents(self.game, self.item, self.actor) msg = self.app.print_stack.pop() self.assertEqual( msg, self.CANNOT_TALK_MSG, "Tried ask verb with an inanimate dobj. Expected msg " f"{self.CANNOT_TALK_MSG}, received {msg}", ) def test_tell_inanimate(self): TellVerb()._runVerbFuncAndEvents(self.game, self.item, self.actor) msg = self.app.print_stack.pop() self.assertEqual( msg, self.CANNOT_TALK_MSG, "Tried ask verb with an inanimate dobj. Expected msg " f"{self.CANNOT_TALK_MSG}, received {msg}", ) def test_give_inanimate(self): GiveVerb()._runVerbFuncAndEvents(self.game, self.item, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.CANNOT_TALK_MSG, "Tried ask verb with an inanimate dobj. Expected msg " f"{self.CANNOT_TALK_MSG}, received {msg}", ) def test_show_inanimate(self): ShowVerb()._runVerbFuncAndEvents(self.game, self.item, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.CANNOT_TALK_MSG, "Tried ask verb with an inanimate dobj. Expected msg " f"{self.CANNOT_TALK_MSG}, received {msg}", ) def test_ask_no_defined_topic(self): self.actor.defaultTopic(self.game) self.game.runTurnEvents() default = self.app.print_stack.pop() self.assertNotIn( self.item.ix, self.actor.ask_topics, ) AskVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, default, "Tried ask verb for topic not in ask topics. Expected default topic " f"{default}, received {msg}", ) def test_tell_no_defined_topic(self): self.actor.defaultTopic(self.game) self.game.runTurnEvents() default = self.app.print_stack.pop() self.assertNotIn( self.item.ix, self.actor.tell_topics, ) TellVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, default, "Tried tell verb for topic not in tell topics. Expected default topic " f"{default}, received {msg}", ) def test_give_no_defined_topic(self): self.actor.defaultTopic(self.game) self.game.runTurnEvents() default = self.app.print_stack.pop() self.assertNotIn( self.item.ix, self.actor.give_topics, ) GiveVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, default, "Tried give verb for topic not in give topics. Expected default topic " f"{default}, received {msg}", ) def test_show_no_defined_topic(self): self.actor.defaultTopic(self.game) self.game.runTurnEvents() default = self.app.print_stack.pop() self.assertNotIn( self.item.ix, self.actor.show_topics, ) ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, default, "Tried show verb for topic not in show topics. Expected default topic " f"{default}, received {msg}", ) def test_ask_with_topic(self): self.actor.addTopic("ask", self.topic, self.item) AskVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.topic.text, "Tried ask verb for topic in ask topics. Expected topic text " f"{self.topic.text}, received {msg}", ) def test_tell_with_topic(self): self.actor.addTopic("tell", self.topic, self.item) TellVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.topic.text, "Tried tell verb for topic in ask topics. Expected topic text " f"{self.topic.text}, received {msg}", ) def test_give_with_topic(self): self.actor.addTopic("give", self.topic, self.item) GiveVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.topic.text, "Tried give verb for topic in ask topics. Expected topic text " f"{self.topic.text}, received {msg}", ) def test_show_with_topic(self): self.actor.addTopic("show", self.topic, self.item) ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item) msg = self.app.print_stack.pop() self.assertEqual( msg, self.topic.text, "Tried show verb for topic in ask topics. Expected topic text " f"{self.topic.text}, received {msg}", )