Ejemplo n.º 1
0
 def test_add_remove_composite_item_from_Container(self):
     parent = Container(self.game, "parent")
     child = Thing(self.game, "child")
     sub = Thing(self.game, "sub")
     child.addComposite(sub)
     self.start_room.addThing(parent)
     self._assert_can_add_remove(parent, child)
Ejemplo n.º 2
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.",
        )
Ejemplo n.º 3
0
    def test_drop_all(self):
        item1 = Thing(self.game, "miracle")
        item2 = Thing(self.game, "wonder")
        item1.invItem = True
        item2.invItem = True
        item1.makeKnown(self.me)
        item2.makeKnown(self.me)
        self.me.addThing(item1)
        self.me.addThing(item2)

        self.assertIs(
            self.me.location,
            self.start_room,
            "This test needs the Player to be in the start room",
        )

        self.game.turnMain("drop all")
        dropall_msg = self.app.print_stack.pop()

        self.assertEqual(
            len(self.me.contains),
            0,
            f"Expected empty inv, but found {self.me.contains}",
        )

        self.assertIn(item1.ix, self.start_room.contains)
        self.assertIn(item1, self.start_room.contains[item1.ix])
        self.assertIn(item2.ix, self.start_room.contains)
        self.assertIn(item2, self.start_room.contains[item2.ix])
        self.game.turnMain("drop all")
        dropall_msg = self.app.print_stack.pop()
        self.assertEqual(dropall_msg, "Your inventory is empty. ")
Ejemplo n.º 4
0
 def test_verbose_name_is_full_name_if_overridden(self):
     subject = Thing(self.game, "flower")
     ADJECTIVES = ["grandma's", "big", "bright", "yellow"]
     subject.setAdjectives(ADJECTIVES)
     NAME = "sasquatch"
     subject.full_name = NAME
     self.assertEqual(NAME, subject.verbose_name)
Ejemplo n.º 5
0
 def test_legacy_underscore_verbose_name_attr_alias(self):
     subject = Thing(self.game, "flower")
     self.assertFalse(subject.full_name)
     FULL_NAME = "daisy flower"
     subject._verbose_name = FULL_NAME
     self.assertEqual(subject._verbose_name, FULL_NAME)
     self.assertEqual(subject.full_name, FULL_NAME)
Ejemplo n.º 6
0
    def setUp(self):
        super().setUp()
        FILENAME = f"_ifp_tests_saveload__{uuid.uuid4()}.sav"

        path = os.path.dirname(os.path.realpath(__file__))
        self.path = os.path.join(path, FILENAME)

        self.item1 = Surface(self.game, "table")
        self.item2 = Container(self.game, "box")
        self.item3 = Container(self.game, "cup")
        self.item4 = Thing(self.game, "bean")
        self.item5 = Thing(self.game, "spider")

        self.start_room.addThing(self.item1)
        self.item1.addThing(self.item2)
        self.item2.addThing(self.item3)
        self.item3.addThing(self.item4)
        self.item2.addThing(self.item5)

        SaveGame(self.game, self.path)
        self.start_room.removeThing(self.item1)
        self.item1.removeThing(self.item2)
        self.item2.removeThing(self.item3)
        self.item3.removeThing(self.item4)
        self.item2.removeThing(self.item5)
Ejemplo n.º 7
0
    def test_look_in_non_container(self):
        parent = Thing(self.game, "cube")
        parent.moveTo(self.start_room)

        self.game.turnMain("look in cube")

        self.assertIn("cannot look inside", self.app.print_stack.pop())
Ejemplo n.º 8
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",
        )
Ejemplo n.º 9
0
 def setUp(self):
     super().setUp()
     self.sale_item = Thing(self.game, "widget")
     self.actor = Thing(self.game, "statue")
     self.currency = Thing(self.game, "penny")
     self.me.addThing(self.currency)
     self.start_room.addThing(self.actor)
     self.sale_item.makeKnown(self.me)
Ejemplo n.º 10
0
    def test_adds_to_new_location_if_no_previous_location(self):
        child = Thing(self.game, "child")

        new = Container(self.game, "new")
        child.moveTo(new)

        self.assertItemIn(child, new.contains, "Item not added to new location")
        self.assertIs(child.location, new, "Item not added to new location")
Ejemplo n.º 11
0
 def test_add_remove_composite_item_from_UnderSpace(self):
     parent = UnderSpace(self.game, "parent")
     parent.revealed = True
     child = Thing(self.game, "child")
     sub = Thing(self.game, "sub")
     child.addComposite(sub)
     self.start_room.addThing(parent)
     self._assert_can_add_remove(parent, child)
Ejemplo n.º 12
0
    def test_look_under_non_underspace_inv_item(self):
        child = Thing(self.game, "penny")
        child.moveTo(self.start_room)

        self.game.turnMain("look under penny")

        self.assertIn("You take the penny. ", self.app.print_stack)
        self.assertIn("You find nothing underneath. ", self.app.print_stack)
Ejemplo n.º 13
0
    def test_drop_item_not_in_inv(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.start_room.addThing(item)
        self.assertNotIn(item.ix, self.me.contains)

        success = DropVerb()._runVerbFuncAndEvents(self.game, item)
        self.assertFalse(success)
Ejemplo n.º 14
0
    def test_get_underspace_reveals_single_contained_item(self):
        parent = UnderSpace(self.game, "rug")
        child = Thing(self.game, "penny")
        parent.moveTo(self.start_room)
        child.moveTo(parent)

        self.game.turnMain("take rug")
        self.assertIn("A penny is revealed. ", self.app.print_stack)
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def test_look_under_non_underspace_non_inv_item(self):
        child = Thing(self.game, "mountain")
        child.invItem = False
        child.moveTo(self.start_room)

        self.game.turnMain("look under mountain")

        self.assertIn("There's no reason to look under the mountain. ",
                      self.app.print_stack)
Ejemplo n.º 17
0
    def test_get_item_when_pc_sitting(self):
        item = Thing(self.game, "bob")
        item.moveTo(self.start_room)
        self.game.me.position = "sitting"

        self.game.turnMain("take bob")

        self.assertIn("You stand up. ", self.app.print_stack)
        self.assertEqual(self.game.me.position, "standing")
Ejemplo n.º 18
0
    def test_print_replace_with_integer(self):
        thing = Thing(self.game, self._get_unique_noun())
        thing.x_description = "I will <<test_parser.TestReplacement.INTEGER>> this."
        thing.moveTo(self.start_room)

        self.game.turnMain(f"x {thing.name}")

        msg = self.app.print_stack.pop()
        self.assertIn(str(self.INTEGER), msg)
Ejemplo n.º 19
0
 def test_room_desc_contains_description_of_described_item_in_room(self):
     subject = Thing(self.game, self._get_unique_noun())
     subject.description = (
         f"A very large, very strange {subject.verbose_name} lurks in the corner."
     )
     self.start_room.addThing(subject)
     self.game.turnMain(f"l")
     msg = self.app.print_stack.pop()
     self.assertIn(subject.description, msg)
Ejemplo n.º 20
0
    def test_attempting_to_replace_with_function_call_raises(self):
        thing = Thing(self.game, self._get_unique_noun())
        thing.x_description = (
            "I will <<test_parser.TestReplacement.class_method_with_one_arg(7)>> this."
        )
        thing.moveTo(self.start_room)

        with self.assertRaises(NotImplementedError):
            self.game.turnMain(f"x {thing.name}")
Ejemplo n.º 21
0
class TestSellDoesNotWant(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.me.addThing(self.sale_item)

        self.start_room.addThing(self.actor)

        self.BASE_DOES_NOT_WANT_MSG = "doesn't want to buy"

    def test_sell(self):
        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "This test needs a widget in the inventory. ",
        )

        SellVerb()._runVerbFuncAndEvents(self.game, self.sale_item)

        msg = self.app.print_stack.pop()
        self.assertIn(
            self.BASE_DOES_NOT_WANT_MSG,
            msg,
            "Unexpected msg after attempting to sell item",
        )

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to sell item actor does not want. Should still have exactly 1.",
        )

    def test_sell_to(self):
        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "This test needs a widget in the inventory. ",
        )

        SellToVerb()._runVerbFuncAndEvents(self.game, self.sale_item,
                                           self.actor)

        msg = self.app.print_stack.pop()
        self.assertIn(
            self.BASE_DOES_NOT_WANT_MSG,
            msg,
            "Unexpected msg after attempting to sell item",
        )

        self.assertItemExactlyOnceIn(
            self.sale_item,
            self.me.contains,
            "Attempted to sell item actor does not want. Should still have exactly 1.",
        )
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
    def test_get_composite_underspace_reveals_contained_item(self):
        item = Container(self.game, "box")
        parent = UnderSpace(self.game, "space")
        child = Thing(self.game, "penny")
        item.addComposite(parent)
        item.moveTo(self.start_room)
        child.moveTo(parent)

        self.game.turnMain("take box")
        self.assertIn("A penny is revealed. ", self.app.print_stack)
Ejemplo n.º 24
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"
Ejemplo n.º 25
0
 def test_contains_list_does_not_contain_composite_child_items(self):
     subject = Container(self.game, self._get_unique_noun())
     content = Thing(self.game, self._get_unique_noun())
     child = Thing(self.game, "child")
     content.addComposite(child)
     subject.addThing(content)
     self.start_room.addThing(subject)
     self.game.turnMain(f"x {subject.verbose_name}")
     msg = self.app.print_stack.pop()
     self.assertNotIn(child.verbose_name, msg)
Ejemplo n.º 26
0
    def test_get_all_drop(self):
        item1 = Thing(self.game, "miracle")
        item2 = Thing(self.game, "wonder")
        item1.invItem = True
        item2.invItem = True
        item3 = item2.copyThing()
        item1.makeKnown(self.me)
        item3.makeKnown(self.me)
        self.start_room.addThing(item1)
        self.start_room.addThing(item3)
        self.me.addThing(item2)

        self.assertNotIn(item1.ix, self.me.contains)
        self.assertIn(item2.ix, self.me.contains)
        self.assertNotIn(item3, self.me.contains[item2.ix])

        self.game.turnMain("take all")
        getall_msg = self.app.print_stack.pop()

        self.assertIn(
            item1.ix,
            self.me.contains,
            f"Item not added to inv with get all. Msg: '{getall_msg}'",
        )
        self.assertIn(item1, self.me.contains[item1.ix])
        self.assertIn(
            item2.ix,
            self.me.contains,
            f"Item not added to inv with get all. Msg: '{getall_msg}'",
        )
        self.assertIn(item2, self.me.contains[item2.ix])

        self.game.turnMain("take all")
        getall_msg = self.app.print_stack.pop()
        self.assertEqual(getall_msg, "There are no obvious items here to take. ")
Ejemplo n.º 27
0
    def test_verb_func_adds_invitem_to_inv(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.start_room.addThing(item)

        success = GetVerb()._runVerbFuncAndEvents(self.game, item)
        self.assertTrue(success)

        self.assertIn(item.ix, self.me.contains)
        self.assertEqual(len(self.me.contains[item.ix]), 1)
        self.assertIn(item, self.me.contains[item.ix])
Ejemplo n.º 28
0
    def test_get_item_when_pc_is_in_thing_with_no_corresponding_exit_verb(
            self):
        loc = Thing(self.game, "brick")
        loc.moveTo(self.start_room)
        loc.can_contain_standing_player = True
        self.game.me.moveTo(loc)

        self.game.turnMain("take brick")

        self.assertIn("Could not move player out of brick",
                      self.app.print_stack)
Ejemplo n.º 29
0
    def test_verb_func_does_not_add_to_inv_where_invitem_false(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = False
        self.start_room.addThing(item)

        self.assertFalse(item.ix in self.me.contains)

        success = GetVerb()._runVerbFuncAndEvents(self.game, item)
        self.assertFalse(success)

        self.assertNotIn(item.ix, self.me.contains)
Ejemplo n.º 30
0
    def test_undescribed_underspace_not_included_in_composite_desc(self):
        subject = Thing(self.game, self._get_unique_noun())
        child = UnderSpace(self.game, "child")
        subject.addComposite(child)
        self.start_room.addThing(subject)

        self.assertNotIn(child.verbose_name, subject.composite_desc)

        self.game.turnMain(f"l {subject.verbose_name}")
        msg = self.app.print_stack.pop()
        self.assertNotIn(child.verbose_name, msg)