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)
Exemple #2
0
    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")
Exemple #3
0
 def test_add_remove_item_with_lock_from_Container(self):
     parent = Container(self.game, "parent")
     child = Container(self.game, "child")
     child.has_lid = True
     lock = Lock(self.game, "lock", None)
     child.setLock(lock)
     self.start_room.addThing(parent)
     self._assert_can_add_remove(parent, child)
 def setUp(self):
     super().setUp()
     self.old_container = Container(self.game, "bottle")
     self.old_container.holds_liquid = True
     self.new_container = Container(self.game, "bowl")
     self.new_container.size = 50
     self.new_container.holds_liquid = True
     self.liquid = Liquid(self.game, "wine", "wine")
     self.liquid.moveTo(self.old_container)
     self.old_container.moveTo(self.start_room)
     self.new_container.moveTo(self.start_room)
    def test_get_item_when_pc_is_in_container(self):
        loc = Container(self.game, "box")
        loc.moveTo(self.start_room)
        loc.can_contain_standing_player = True

        sub_loc = Container(self.game, "vase")
        sub_loc.moveTo(loc)
        sub_loc.can_contain_standing_player = True

        self.game.me.moveTo(sub_loc)

        self.game.turnMain("take box")

        self.assertIn("You climb out of the box. ", self.app.print_stack)
Exemple #6
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)
 def setUp(self):
     super().setUp()
     self.container = Container(self.game, "box")
     self.container.can_contain_standing_player = True
     self.start_room.addThing(self.container)
     self.game.turnMain("climb in box")
     self.assertIs(self.me.location, self.container)
Exemple #8
0
 def setUp(self):
     super().setUp()
     self.container = Container(self.game, "box")
     self.container.can_contain_standing_player = True
     self.start_room.addThing(self.container)
     ClimbInVerb()._runVerbFuncAndEvents(self.game, self.container)
     self.assertIs(self.me.location, self.container)
Exemple #9
0
 def test_desc_contains_lock_state(self):
     subject = Container(self.game, self._get_unique_noun())
     subject.giveLid()
     lock = Lock(self.game, False, None)
     subject.setLock(lock)
     self.game.turnMain(f"x {subject.verbose_name}")
     msg = self.app.print_stack.pop()
     self.assertNotIn("is locked", msg)
Exemple #10
0
 def test_add_remove_item_with_lock_from_Room(self):
     parent = Room(self.game, "parent", "This is a room. ")
     parent.revealed = True
     child = Container(self.game, "child")
     child.has_lid = True
     lock = Lock(self.game, "lock", None)
     child.setLock(lock)
     self._assert_can_add_remove(parent, child)
Exemple #11
0
    def test_implicit_exit_container(self):
        meta_thing = Container(self.game, "metabox")
        thing = Container(self.game, "box")
        thing.moveTo(meta_thing)
        meta_thing.moveTo(self.start_room)
        self.game.me.moveTo(thing)

        room2 = Room(self.game, "new place", "You are in a new place.")
        self.start_room.east = room2

        self.assertTrue(self.start_room.subLevelContainsItem(self.game.me))

        self.game.turnMain("e")

        self.assertFalse(thing.containsItem(self.game.me),
                         "Player should have left the Container")
        self.assertFalse(self.start_room.subLevelContainsItem(self.game.me))
Exemple #12
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")
Exemple #13
0
    def test_exit_container(self):
        thing = Container(self.game, "box")
        thing.moveTo(self.start_room)
        self.game.me.moveTo(thing)

        self.game.turnMain("exit")

        self.assertFalse(thing.containsItem(self.game.me),
                         "Player should have left the Container")
    def test_get_liquid_in_container_gets_container(self):
        container = Container(self.game, "cup")
        container.moveTo(self.start_room)
        item = Liquid(self.game, "broth", "broth")
        item.moveTo(container)

        self.game.turnMain("take broth")

        self.assertIn("You take the cup. ", self.app.print_stack)
Exemple #15
0
 def test_drop_liquid_in_container(self):
     cup = Container(self.game, "cup")
     water = Liquid(self.game, "water", "water")
     water.moveTo(cup)
     cup.moveTo(self.me)
     self.game.turnMain("drop water")
     self.assertIn("You drop the cup", self.app.print_stack.pop())
     self.assertFalse(self.game.me.containsItem(cup))
     self.assertTrue(cup.containsItem(water))
Exemple #16
0
 def test_desc_contains_lid_state(self):
     subject = Container(self.game, self._get_unique_noun())
     subject.giveLid()
     content = Thing(self.game, self._get_unique_noun())
     subject.addThing(content)
     self.start_room.addThing(subject)
     subject.is_open = False
     self.game.turnMain(f"x {subject.verbose_name}")
     msg = self.app.print_stack.pop()
     self.assertIn("is closed", msg)
Exemple #17
0
 def setUp(self):
     super().setUp()
     self.container = Container(self.game, "chest")
     self.container.has_lid = True
     self.container.is_open = False
     self.key = Key(self.game, "key")
     self.me.addThing(self.key)
     self.lock = Lock(self.game, False, self.key)
     self.lock.is_locked = False
     self.container.setLock(self.lock)
Exemple #18
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)
Exemple #19
0
    def test_move_to_removes_item_from_old_superlocation_subcontains(self):
        room = Room(self.game, "old", "It is old")
        old = Container(self.game, "box")
        room.addThing(old)
        child = Thing(self.game, "child")
        old.addThing(child)

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

        self.assertItemIn(
            child, room.sub_contains, "Item not removed from old location"
        )

        child.moveTo(new)

        self.assertItemNotIn(
            child, room.sub_contains, "Item not removed from old location"
        )
        self.assertIs(child.location, new, "Item not added to new location")
Exemple #20
0
 def test_desc_does_not_contain_contents_if_lid_is_closed(self):
     subject = Container(self.game, self._get_unique_noun())
     subject.giveLid()
     subject.is_open = False
     content = Thing(self.game, self._get_unique_noun())
     subject.addThing(content)
     self.start_room.addThing(subject)
     self.game.turnMain(f"x {subject.verbose_name}")
     msg = self.app.print_stack.pop()
     self.assertNotIn(content.verbose_name, msg)
    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)
Exemple #22
0
    def test_look_in_closed_container_implies_open_first(self):
        parent = Container(self.game, "shoebox")
        parent.giveLid()
        parent.is_open = False
        child = Thing(self.game, "penny")
        parent.addThing(child)
        parent.moveTo(self.start_room)

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

        self.assertIn("You open the shoebox", self.app.print_stack.pop(-2))
Exemple #23
0
    def test_move_to_removes_item_from_old_location_and_adds_to_new_location(self):
        old = Room(self.game, "old", "It is old")
        child = Thing(self.game, "child")
        old.addThing(child)

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

        self.assertItemIn(child, new.contains, "Item not added to new location")
        self.assertItemNotIn(child, old.contains, "Item not removed from old location")
        self.assertIs(child.location, new, "Item not added to new location")
Exemple #24
0
    def test_move_item_to_nested_adding_container_first_then_item(self):
        container = Container(self.game, "cup")
        item = Thing(self.game, "bead")

        container.moveTo(self.start_room)
        self.assertIs(container.location, self.start_room)

        item.moveTo(container)

        self.assertIs(item.location, container)
        self.assertTrue(container.topLevelContainsItem(item))
Exemple #25
0
    def test_set_in_gives_too_big_message_if_item_too_big(self):
        item = Thing(self.game, "giant")
        item.size = 100000
        self.me.addThing(item)
        place = Container(self.game, "place")
        self.start_room.addThing(place)

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

        self.assertIn("too big", self.app.print_stack.pop())
        self.assertFalse(place.containsItem(item))
Exemple #26
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)
Exemple #27
0
    def test_cannot_set_item_in_if_container_already_contains_liquid(self):
        item = Thing(self.game, "item")
        self.me.addThing(item)
        place = Container(self.game, "place")
        self.start_room.addThing(place)
        liquid = Liquid(self.game, "water", "water")
        liquid.moveTo(place)

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

        self.assertIn("already full of water", self.app.print_stack.pop())
        self.assertFalse(place.containsItem(item))
Exemple #28
0
    def test_set_in_adds_item(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.me.addThing(item)
        container = Container(self.game, self._get_unique_noun())
        self.start_room.addThing(container)

        self.assertNotIn(item.ix, container.contains)

        success = SetInVerb()._runVerbFuncAndEvents(self.game, item, container)
        self.assertTrue(success)

        self.assertIn(item.ix, container.contains)
        self.assertIn(item, container.contains[item.ix])
Exemple #29
0
    def test_set_in_adds_item(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.me.addThing(item)
        container = Container(self.game, self._get_unique_noun())
        self.start_room.addThing(container)

        self.assertNotIn(item.ix, container.contains)

        self.game.turnMain(
            f"set {item.verbose_name} in {container.verbose_name}")

        self.assertIn(item.ix, container.contains)
        self.assertIn(item, container.contains[item.ix])
    def test_get_thing_nested_in_thing_in_inventory(self):
        container = Container(self.game, "cup")
        container.moveTo(self.start_room)
        item = Thing(self.game, "bead")

        container.moveTo(self.game.me)
        item.moveTo(container)

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

        self.game.turnMain("take bead")

        self.assertIn("You remove the bead from the cup. ",
                      self.app.print_stack)