Beispiel #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)
Beispiel #2
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)
    def test_get_explicitly_invitem_component_of_composite_object(self):
        parent = Thing(self.game, "cube")
        child = Thing(self.game, "knob")
        parent.addComposite(child)
        parent.moveTo(self.start_room)
        child.invItem = True

        self.game.turnMain("take knob")
        self.assertIn("The knob is attached to the cube. ",
                      self.app.print_stack)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
0
 def test_add_remove_composite_item_from_Room(self):
     parent = Room(self.game, "parent", "This is a room. ")
     child = Thing(self.game, "child")
     sub = Thing(self.game, "sub")
     child.addComposite(sub)
     self._assert_can_add_remove(parent, child)
Beispiel #7
0
class TestFullInventory(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.parent = Thing(self.game, "cube")
        self.child = Container(self.game, "slot")
        self.parent.addComposite(self.child)
        self.stacked1 = Thing(self.game, "tile")
        self.stacked2 = self.stacked1.copyThing()
        self.clothing = Clothing(self.game, "scarf")
        self.clothing1 = Clothing(self.game, "mitten")
        self.clothing2 = self.clothing1.copyThing()

        self.me.addThing(self.parent)
        self.me.addThing(self.child)
        self.me.addThing(self.stacked1)
        self.me.addThing(self.stacked2)
        self.me.addThing(self.clothing)
        self.me.addThing(self.clothing1)
        self.me.addThing(self.clothing2)

        WearVerb()._runVerbFuncAndEvents(self.game, self.clothing)
        WearVerb()._runVerbFuncAndEvents(self.game, self.clothing1)
        WearVerb()._runVerbFuncAndEvents(self.game, self.clothing2)

    def strip_desc(self, desc):
        desc = desc.replace(". ", "").replace(",", "").replace("and", "")
        return " ".join(desc.split())

    def test_inventory_items_desc(self):
        BASE_MSG = "You have"

        InvVerb()._runVerbFuncAndEvents(self.game)
        self.app.print_stack.pop()
        inv_desc = self.app.print_stack.pop()

        parent_desc = self.parent.lowNameArticle()
        stacked_desc = (f"{len(self.me.contains[self.stacked1.ix])} "
                        f"{self.stacked1.plural}")

        self.assertIn(parent_desc, inv_desc,
                      "Composite item description should be in inv desc")
        inv_desc = inv_desc.replace(parent_desc, "")

        self.assertIn(stacked_desc, inv_desc,
                      "Stacked item description should be in inv desc")
        inv_desc = inv_desc.replace(stacked_desc, "")

        inv_desc = self.strip_desc(inv_desc)
        self.assertEqual(inv_desc, BASE_MSG,
                         "Remaining inv desc should match base message")

    def test_inventory_wearing_desc(self):
        BASE_MSG = "You are wearing"

        InvVerb()._runVerbFuncAndEvents(self.game)
        wearing_desc = self.app.print_stack.pop()

        clothing_desc = self.clothing.lowNameArticle()
        stacked_clothing_desc = (f"{len(self.me.wearing[self.clothing1.ix])} "
                                 f"{self.clothing1.plural}")

        self.assertIn(
            clothing_desc,
            wearing_desc,
            "Clothing item description should be in inv desc",
        )
        wearing_desc = wearing_desc.replace(clothing_desc, "")

        self.assertIn(
            stacked_clothing_desc,
            wearing_desc,
            "Stacked clothing item description should be in inv desc",
        )
        wearing_desc = wearing_desc.replace(stacked_clothing_desc, "")

        wearing_desc = self.strip_desc(wearing_desc)
        self.assertEqual(wearing_desc, BASE_MSG,
                         "Remaining wearing desc should match base message")