Ejemplo n.º 1
0
    def test_pour_item_implicitly_into_child_object(self):
        target = Thing(self.game, "thing")
        target.addComposite(self.new_container)
        target.moveTo(self.start_room)

        self.game.turnMain("pour wine in thing")
        self.assertIn("You dump", self.app.print_stack.pop())
        self.assertTrue(self.new_container.containsItem(self.liquid))
Ejemplo n.º 2
0
 def test_drop_composite_child(self):
     machine = Thing(self.game, "machine")
     wheel = Thing(self.game, "wheel")
     machine.addComposite(wheel)
     machine.moveTo(self.me)
     self.game.turnMain("drop wheel")
     self.assertIn("wheel is attached to the machine",
                   self.app.print_stack.pop())
     self.assertTrue(self.me.containsItem(wheel))
Ejemplo n.º 3
0
    def test_set_composite_child_in_gives_attached_message(self):
        parent = Thing(self.game, "thing")
        parent.moveTo(self.me)
        item = Thing(self.game, "handle")
        parent.addComposite(item)
        container = Container(self.game, "place")
        self.start_room.addThing(container)

        self.game.turnMain(f"set handle in place")

        self.assertIn("is attached to", self.app.print_stack.pop())
        self.assertIs(item.location, self.me)
Ejemplo n.º 4
0
    def test_set_composite_child_under_gives_attached_message(self):
        parent = Thing(self.game, "thing")
        parent.moveTo(self.me)
        item = Thing(self.game, "handle")
        parent.addComposite(item)
        underspace = UnderSpace(self.game, "place")
        self.start_room.addThing(underspace)

        self.game.turnMain(f"set handle under place")

        self.assertIn("is attached to", self.app.print_stack.pop())
        self.assertIs(item.location, self.me)
Ejemplo n.º 5
0
    def test_set_composite_child_on_floor_gives_attached_message(self):
        parent = Thing(self.game, "thing")
        parent.moveTo(self.me)
        item = Thing(self.game, "handle")
        parent.addComposite(item)

        self.assertIsNot(item.location, self.start_room)

        self.game.turnMain(f"set handle on floor")

        self.assertIn("is attached to", self.app.print_stack.pop())
        self.assertIs(item.location, self.me)
Ejemplo n.º 6
0
class TestFullInventory(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.parent = Thing(self.game, "cube")
        self.child = Container(self.game, "slot")
        self.container = Container(self.game, "box")
        self.nested_item = Thing(self.game, "bead")
        self.nested_item.moveTo(self.container)
        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.clothing3 = Clothing(self.game, "hat")

        self.me.addThing(self.parent)
        self.me.addThing(self.child)
        self.me.addThing(self.container)
        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)
        self.me.addThing(self.clothing3)

        self.game.turnMain("wear scarf")
        self.game.turnMain("wear hat")
        self.game.turnMain("wear mitten")
        self.game.turnMain("wear mitten")

    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"

        self.game.turnMain("i")
        self.app.print_stack.pop()
        inv_desc = self.app.print_stack.pop()

        self.assertIn("You have", inv_desc)

        stacked_desc = (
            f"{len(self.me.contains[self.stacked1.ix])} {self.stacked1.plural}"
        )
        self.assertIn(stacked_desc, inv_desc,
                      "Stacked item description should be in inv desc")

        self.assertIn(
            "a cube",
            inv_desc,
        )

        self.assertIn("a box (in the box is a bead.)", inv_desc)

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

        self.game.turnMain("i")
        wearing_desc = self.app.print_stack.pop()

        self.assertIn(
            "a hat",
            wearing_desc,
            "Clothing item description should be in inv desc",
        )
        self.assertIn(
            "a scarf",
            wearing_desc,
            "Clothing item description should be in inv desc",
        )
        self.assertIn(
            "mittens",
            wearing_desc,
            "Stacked clothing item description should be in inv desc",
        )