コード例 #1
0
class TestBuyInfiniteStock(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.actor = Actor(self.game, "Dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor.addSelling(self.sale_item, self.currency, 1, True)
        self.start_room.addThing(self.actor)
        self.sale_item.makeKnown(self.me)

    def test_buy(self):
        stock_before = self.actor.for_sale[self.sale_item.ix].number

        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = f"(Received: {self.sale_item.verbose_name}) "
        self.assertEqual(msg, expected,
                         "Unexpected msg after attempting to buy item")

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. ",
        )

        stock_after = self.actor.for_sale[self.sale_item.ix].number

        self.assertIs(
            stock_before,
            stock_after,
            "Stock of infinite item should not have changed after buying",
        )
コード例 #2
0
class TestSpecialTopic(IFPTestCase):
    def setUp(self):
        super().setUp()

        self.actor = Actor(self.game, "shepherd")
        self.actor.moveTo(self.start_room)

        self.verb_keyword = "ask"
        self.subject_phrase = "how come"
        suggestion = " ".join([self.verb_keyword, self.subject_phrase])

        self.text = "He shakes his head sadly."

        topic = SpecialTopic(self.game, suggestion, self.text)
        self.actor.addSpecialTopic(topic)

        self.game.turnMain("hi")

    def test_take_conversation_suggestion_with_verb_keyword(self):
        self.game.turnMain(self.verb_keyword)
        self.assertIn(self.text, self.app.print_stack)

    def test_take_conversation_suggestion_without_verb_keyword(self):
        self.game.turnMain(self.subject_phrase)
        self.assertIn(self.text, self.app.print_stack)
コード例 #3
0
ファイル: test_conversation.py プロジェクト: JSMaika/intficpy
class TestTalkTo(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.actor = Actor(self.game, "girl")
        self.actor.moveTo(self.start_room)

    def test_talk_to_non_actor_thing(self):
        item = Thing(self.game, "bit")
        item.moveTo(self.start_room)
        self.game.turnMain("talk to bit")
        self.assertIn("cannot talk to", self.app.print_stack.pop())

    def test_talk_to_actor_with_sticky_topic(self):
        self.actor.sticky_topic = Topic(
            self.game, "Weren't you that guy from yesterday?")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.sticky_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_hermit_topic(self):
        self.actor.hermit_topic = Topic(self.game, "Go away.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.hermit_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_hi_topic(self):
        self.actor.hi_topic = Topic(self.game, "Oh. Hi.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.hi_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_returning_hi_topic(self):
        self.actor.return_hi_topic = Topic(self.game, "You're back. Great.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.return_hi_topic.text, self.app.print_stack)
コード例 #4
0
class TestBuyNotEnoughMoney(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.actor = Actor(self.game, "Dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor.addSelling(self.sale_item, self.currency, 2, 1)
        self.start_room.addThing(self.actor)
        self.sale_item.makeKnown(self.me)

    def test_buy(self):
        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        BASE_FAILURE_MSG = "You don't have enough"
        self.assertIn(
            BASE_FAILURE_MSG,
            msg,
            "Unexpected message after attempting to buy item with insufficient funds",
        )

        self.assertItemNotIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item with insufficient money.",
        )
コード例 #5
0
 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. ')
コード例 #6
0
 def setUp(self):
     super().setUp()
     self.sale_item = Thing(self.game, "widget")
     self.actor = Actor(self.game, "Dmitri")
     self.currency = Thing(self.game, "penny")
     self.me.addThing(self.currency)
     self.actor.addSelling(self.sale_item, self.currency, 1, True)
     self.start_room.addThing(self.actor)
     self.sale_item.makeKnown(self.me)
コード例 #7
0
 def setUp(self):
     super().setUp()
     self.sale_item = Actor(self.game, "kate")
     self.actor = Actor(self.game, "dmitri")
     self.currency = Thing(self.game, "penny")
     self.me.addThing(self.currency)
     self.actor.addSelling(self.sale_item, self.currency, 2, 1)
     self.start_room.addThing(self.actor)
     self.sale_item.makeKnown(self.me)
コード例 #8
0
 def setUp(self):
     super().setUp()
     self.sale_item = Thing(self.game, "bulb")
     self.actor1 = Actor(self.game, "dmitri")
     self.actor2 = Actor(self.game, "kate")
     self.currency = Thing(self.game, "penny")
     self.me.addThing(self.sale_item)
     self.actor1.addWillBuy(self.sale_item, self.currency, 1, 1)
     self.start_room.addThing(self.actor1)
     self.start_room.addThing(self.actor2)
コード例 #9
0
 def setUp(self):
     super().setUp()
     self.sale_item = Thing(self.game, "bulb")
     self.actor1 = Actor(self.game, "Dmitri")
     self.actor2 = Actor(self.game, "Kate")
     self.currency = Thing(self.game, "penny")
     self.me.addThing(self.currency)
     self.actor1.addSelling(self.sale_item, self.currency, 1, 1)
     self.start_room.addThing(self.actor1)
     self.start_room.addThing(self.actor2)
     self.sale_item.makeKnown(self.me)
コード例 #10
0
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.actor = Actor(self.game, "Dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor.addSelling(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor)
        self.sale_item.makeKnown(self.me)

        self.OUT_STOCK_MSG = "That item is out of stock. "
コード例 #11
0
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.sale_item.makeKnown(self.me)
        self.actor = Actor(self.game, "dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.sale_item)
        self.me.addThing(self.sale_item.copyThing())
        self.actor.addWillBuy(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor)

        self.BASE_DOES_NOT_WANT_MORE_MSG = "will not buy any more"
コード例 #12
0
ファイル: test_conversation.py プロジェクト: JSMaika/intficpy
 def setUp(self):
     super().setUp()
     self.actor = Actor(self.game, "girl")
     self.actor.moveTo(self.start_room)
     self.item = Thing(self.game, "mess")
     self.item.moveTo(self.start_room)
     self.CANNOT_TALK_MSG = "You cannot talk to that. "
     self.topic = Topic(self.game,
                        '"Ah, yes," says the girl mysteriously. ')
     self.sticky_topic = Topic(
         self.game, '"But remember about the thing!" insists the girl. ')
     self.game.turnMain("l")
コード例 #13
0
ファイル: test_conversation.py プロジェクト: JSMaika/intficpy
 def setUp(self):
     super().setUp()
     self.actor1 = Actor(self.game, "grocer")
     self.actor1.can_be_led = True
     self.start_room.addThing(self.actor1)
     self.room2 = Room(self.game, "Place", "Words")
     self.start_room.north = self.room2
コード例 #14
0
    def setUp(self):
        super().setUp()

        self.actor = Actor(self.game, "shepherd")
        self.actor.moveTo(self.start_room)

        self.verb_keyword = "ask"
        self.subject_phrase = "how come"
        suggestion = " ".join([self.verb_keyword, self.subject_phrase])

        self.text = "He shakes his head sadly."

        topic = SpecialTopic(self.game, suggestion, self.text)
        self.actor.addSpecialTopic(topic)

        self.game.turnMain("hi")
コード例 #15
0
    def test_accept_suggestion(self):
        girl = Actor(self.game, "girl")
        TOPIC_SUGGESTION = "ask what her name is"
        TOPIC_TEXT = '"It\'s Karen," says the girl.'
        topic = SpecialTopic(self.game, TOPIC_SUGGESTION, TOPIC_TEXT)
        girl.addSpecialTopic(topic)
        self.start_room.addThing(girl)

        self.game.turnMain("talk to girl")
        self.assertTrue(self.game.parser.command.specialTopics)

        self.game.turnMain(TOPIC_SUGGESTION)

        msg = self.app.print_stack.pop(-2)

        self.assertEqual(
            msg, TOPIC_TEXT, "Expected topic text to print after accepting suggestion"
        )
コード例 #16
0
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.sale_item.makeKnown(self.me)
        self.actor = Actor(self.game, "Dmitri")
        self.me.addThing(self.sale_item)

        self.start_room.addThing(self.actor)

        self.BASE_DOES_NOT_WANT_MSG = "doesn't want to buy"
コード例 #17
0
    def test_gets_correct_objects_with_adjacent_dobj_iobj(self):
        dobj_item = Actor(self.game, self._get_unique_noun())
        self.start_room.addThing(dobj_item)
        iobj_item = Thing(self.game, self._get_unique_noun())
        self.start_room.addThing(iobj_item)

        self.game.turnMain(f"give {dobj_item.name} {iobj_item.name}")

        self.assertEqual(self.game.parser.command.dobj.target, dobj_item)
        self.assertEqual(self.game.parser.command.iobj.target, iobj_item)
コード例 #18
0
    def test_gets_correct_verb_with_dobj_and_direction_iobj(self):
        dobj = Actor(self.game, self._get_unique_noun())
        self.start_room.addThing(dobj)
        iobj = "east"
        self.start_room.east = self.start_room

        self.game.turnMain(f"lead {dobj.name} {iobj}")

        self.assertIs(self.game.parser.command.verb, LeadDirVerb)
        self.assertIs(self.game.parser.command.dobj.target, dobj)
        self.assertEqual(self.game.parser.command.iobj.target, iobj)
コード例 #19
0
class TestBuyPerson(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Actor(self.game, "kate")
        self.actor = Actor(self.game, "dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor.addSelling(self.sale_item, self.currency, 2, 1)
        self.start_room.addThing(self.actor)
        self.sale_item.makeKnown(self.me)

    def test_buy(self):
        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        FAILURE_MSG = "You cannot buy or sell a person. "
        self.assertEqual(
            FAILURE_MSG, msg,
            "Unexpected message after attempting to buy an Actor")

        self.assertItemNotIn(self.sale_item, self.me.contains,
                             "Attempted to buy an Actor.")
コード例 #20
0
 def test_create_Actor(self):
     item = Actor(self.game, Actor.__name__)
     self.assertTrue(item.ix)
     self.assertIn(
         item.ix,
         self.game.ifp_objects,
         f"Tried to create a {Actor.__name__}, but index not in things obj_map",
     )
     self.assertIs(
         self.game.ifp_objects[item.ix],
         item,
         f"New {Actor.__name__} index successfully added to "
         f"object_map, but {self.game.ifp_objects[item.ix]} found under key instead of "
         f"the new instance {item}",
     )
コード例 #21
0
    def test_verb_by_objects_no_near_matches_unrecognized_noun(self):
        sarah1 = Actor(self.game, "teacher")
        sarah1.setAdjectives(["good"])
        self.start_room.addThing(sarah1)

        sarah2 = Actor(self.game, "teacher")
        sarah2.setAdjectives(["bad"])
        self.start_room.addThing(sarah2)

        self.game.turnMain("hi teacher")
        self.assertTrue(self.game.parser.command.ambiguous)

        self.game.turnMain("set green sarah")

        msg = self.app.print_stack.pop()
        expected = "I understood as far as"

        self.assertIn(
            expected,
            msg,
            "Unexpected response attempting to disambiguate verb with unrecognized "
            "noun.",
        )
コード例 #22
0
ファイル: test_look.py プロジェクト: JSMaika/intficpy
 def test_look_through_person(self):
     item = Actor(self.game, "dude")
     item.moveTo(self.start_room)
     self.game.turnMain("look through dude")
     self.assertIn("cannot look through the dude", self.app.print_stack.pop())
コード例 #23
0
ファイル: testgame.py プロジェクト: JSMaika/intficpy
startroom.exit = shackdoor
beach.entrance = shackdoor

# Attic

attic = Room(game, "Shack, attic", "You are in a dim, cramped attic. ")
shackladder = LadderConnector(game, startroom, attic)
shackladder.entrance_a.description = (
    "Against the north wall is a ladder leading up to the attic. ")
startroom.north = shackladder
silverkey.moveTo(attic)

# CHARACTERS
# Sarah
sarah = Actor(game, "Sarah")
sarah.makeProper("Sarah")
sarah.moveTo(startroom)


def sarahOpalFunc(game, dobj):
    """
    IntFicPy verbs can be overridden or customized for specific items.
    To do this, find the verb you want to customize in the intficpy.verb module.
    Note
        1) the class name of the verb
        2) whether its verbFunc method takes just a "dobj" (direct object) parameter,
           or an "iobj" (indirect object) as well
           For instance, GetVerb (as in, "get opal") takes only a direct object (here, "opal"),
           while GiveVerb (as in, "give opal to Sarah") takes an indirect object as well
           (here, "Sarah")
コード例 #24
0
 def setUp(self):
     super().setUp()
     self.actor1 = Actor(self.game, "grocer")
     self.start_room.addThing(self.actor1)
コード例 #25
0
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}",
        )
コード例 #26
0
    def setUp(self):
        super().setUp()

        self.actor = Actor(self.game, "girl")
        self.item = Thing(self.game, "item")
        self.item.moveTo(self.actor)
コード例 #27
0
class TestBuyInRoomWithMultipleActors(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "bulb")
        self.actor1 = Actor(self.game, "Dmitri")
        self.actor2 = Actor(self.game, "Kate")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor1.addSelling(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor1)
        self.start_room.addThing(self.actor2)
        self.sale_item.makeKnown(self.me)

    def test_buy(self):
        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        BASE_DISAMBIG_MSG = "Would you like to buy from"
        self.assertIn(
            BASE_DISAMBIG_MSG,
            msg,
            "Unexpected message after attempting to buy from ambiguous Actor",
        )

        self.assertItemNotIn(self.sale_item, self.me.contains,
                             "Attempted to buy from ambiguous Actor.")

    def test_buy_with_lastTurn_dobj_actor(self):
        self.game.parser.command.dobj = GrammarObject(target=self.actor1)

        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = f"(Received: {self.sale_item.verbose_name}) "
        self.assertEqual(
            msg,
            expected,
            "Unexpected msg after attempting to buy from ambigous Actor",
        )

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. ",
        )

    def test_buy_with_lastTurn_iobj_actor(self):
        self.game.parser.command.iobj = GrammarObject(target=self.actor1)

        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = f"(Received: {self.sale_item.verbose_name}) "
        self.assertEqual(
            msg, expected,
            "Unexpected msg after attempting to buy from ambigous Actor")

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. ",
        )
コード例 #28
0
class TestSell(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.sale_item.makeKnown(self.me)
        self.actor = Actor(self.game, "dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.sale_item)
        self.me.addThing(self.sale_item.copyThing())
        self.actor.addWillBuy(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor)

        self.BASE_DOES_NOT_WANT_MORE_MSG = "will not buy any more"

    def test_sell(self):
        self.assertItemIn(
            self.sale_item,
            self.me.contains,
            "This test needs widgets in the inventory. ",
        )
        self.assertEqual(len(self.me.contains[self.sale_item.ix]), 2)

        self.game.turnMain(f"sell {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = (
            f"(Received: {self.actor.will_buy[self.sale_item.ix].price} "
            f"{self.currency.verbose_name}) ")
        self.assertEqual(msg, expected,
                         "Unexpected msg after attempting to sell item")

        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to sell item. Received success message. ",
        )

        SellVerb()._runVerbFuncAndEvents(self.game, self.sale_item)
        msg = self.app.print_stack.pop()

        self.assertIn(
            self.BASE_DOES_NOT_WANT_MORE_MSG,
            msg,
            "Tried to sell item to actor who should not want any more. Received "
            "unexpected msg",
        )
        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to buy out of stock item. Number in inventory should not have "
            "changed. ",
        )

    def test_sell_to(self):
        self.assertItemIn(
            self.sale_item,
            self.me.contains,
            "This test needs widgets in the inventory. ",
        )
        self.assertEqual(len(self.me.contains[self.sale_item.ix]), 2)

        self.game.turnMain(
            f"sell {self.sale_item.verbose_name} to {self.actor.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = (
            f"(Received: {self.actor.will_buy[self.sale_item.ix].price} "
            f"{self.currency.verbose_name}) ")
        self.assertEqual(msg, expected,
                         "Unexpected msg after attempting to sell item")

        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to sell item. Received success message. ",
        )

        SellToVerb()._runVerbFuncAndEvents(self.game, self.sale_item,
                                           self.actor)
        msg = self.app.print_stack.pop()

        self.assertIn(
            self.BASE_DOES_NOT_WANT_MORE_MSG,
            msg,
            "Tried to sell item to actor who should not want any more. Received "
            "unexpected msg",
        )
        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to buy out of stock item. Number in inventory should not have "
            "changed. ",
        )
コード例 #29
0
class TestSellInRoomWithMultipleActors(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "bulb")
        self.actor1 = Actor(self.game, "dmitri")
        self.actor2 = Actor(self.game, "kate")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.sale_item)
        self.actor1.addWillBuy(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor1)
        self.start_room.addThing(self.actor2)

    def test_sell(self):
        self.game.turnMain(f"sell {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        BASE_DISAMBIG_MSG = "Would you like to sell it to"
        self.assertIn(
            BASE_DISAMBIG_MSG,
            msg,
            "Unexpected message after attempting to sell to ambiguous Actor",
        )

        self.assertItemIn(self.sale_item, self.me.contains,
                          "Attempted to sell to ambiguous Actor.")

    def test_sell_with_lastTurn_dobj_actor(self):
        self.game.parser.command.dobj = GrammarObject(target=self.actor1)

        self.game.turnMain(f"sell {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = (
            f"(Received: {self.actor1.will_buy[self.sale_item.ix].price} "
            f"{self.currency.verbose_name}) ")
        self.assertEqual(
            msg, expected,
            "Unexpected msg after attempting to sell from ambigous Actor")

        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to sell item. Recieved success message. Expected 1 currency. ",
        )
        self.assertItemNotIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. Expected no sale_item "
            "in inv.",
        )

    def test_sell_with_lastTurn_iobj_actor(self):
        self.game.parser.command.iobj = GrammarObject(target=self.actor1)
        self.assertTrue(self.game.parser.command.iobj.target)

        self.game.turnMain(f"sell {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = (
            f"(Received: {self.actor1.will_buy[self.sale_item.ix].price} "
            f"{self.currency.verbose_name}) ")
        self.assertEqual(
            msg, expected,
            "Unexpected msg after attempting to sell from ambigous Actor")

        self.assertItemExactlyOnceIn(
            self.currency,
            self.me.contains,
            "Attempted to sell item. Recieved success message. Expected 1 currency. ",
        )
        self.assertItemNotIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. Expected no sale_item "
            "in inv.",
        )
コード例 #30
0
class TestBuyFiniteStock(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.sale_item = Thing(self.game, "widget")
        self.actor = Actor(self.game, "Dmitri")
        self.currency = Thing(self.game, "penny")
        self.me.addThing(self.currency)
        self.actor.addSelling(self.sale_item, self.currency, 1, 1)
        self.start_room.addThing(self.actor)
        self.sale_item.makeKnown(self.me)

        self.OUT_STOCK_MSG = "That item is out of stock. "

    def test_buy(self):
        self.game.turnMain(f"buy {self.sale_item.verbose_name}")

        msg = self.app.print_stack.pop()
        expected = f"(Received: {self.sale_item.verbose_name}) "
        self.assertEqual(msg, expected,
                         "Unexpected msg after attempting to buy item")

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. ",
        )

        self.game.turnMain(f"buy {self.sale_item.verbose_name}")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.OUT_STOCK_MSG,
            "Tried to buy item which should be out of stock. Received unexpected msg",
        )
        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy out of stock item. Number in inventory should not have "
            "changed. ",
        )

    def test_buy_from(self):
        BuyFromVerb()._runVerbFuncAndEvents(self.game, self.sale_item,
                                            self.actor)

        msg = self.app.print_stack.pop()
        expected = f"(Received: {self.sale_item.verbose_name}) "
        self.assertEqual(msg, expected,
                         "Unexpected msg after attempting to buy item")

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy item. Received success message. ",
        )

        BuyFromVerb()._runVerbFuncAndEvents(self.game, self.sale_item,
                                            self.actor)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.OUT_STOCK_MSG,
            "Tried to buy item which should be out of stock. Received unexpected msg",
        )
        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to buy out of stock item. Number in inventory should not have "
            "changed. ",
        )