コード例 #1
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)
コード例 #2
0
    def test_read_non_readable(self):
        item = Surface(self.game, "desk")
        item.moveTo(self.start_room)

        self.game.turnMain("read desk")

        self.assertIn("There's nothing written there. ", self.app.print_stack)
コード例 #3
0
 def test_desc_contains_contents_if_desc_reveal(self):
     subject = Surface(self.game, self._get_unique_noun())
     subject.desc_reveal = True
     content = Thing(self.game, self._get_unique_noun())
     subject.addThing(content)
     self.start_room.addThing(subject)
     self.game.turnMain(f"l")
     msg = self.app.print_stack.pop()
     self.assertIn(content.verbose_name, msg)
コード例 #4
0
 def test_xdesc_does_not_contain_contents_if_not_xdesc_reveal(self):
     subject = Surface(self.game, self._get_unique_noun())
     subject.xdesc_reveal = 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)
コード例 #5
0
    def test_exit_surface(self):
        thing = Surface(self.game, "tray")
        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")
コード例 #6
0
class TestSaveLoadNested(IFPTestCase):
    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)

    def test_load(self):
        l = LoadGame(self.game, self.path)
        self.assertTrue(l.is_valid(), "Save file invalid. Cannot proceed.")
        l.load()

        self.assertItemExactlyOnceIn(self.item1, self.start_room.contains,
                                     "Failed to load top level item.")

        self.assertItemExactlyOnceIn(
            self.item2, self.item1.contains,
            "Failed to load item nested with depth 1.")

        self.assertItemExactlyOnceIn(
            self.item3, self.item2.contains,
            "Failed to load item nested with depth 2.")

        self.assertItemExactlyOnceIn(
            self.item5, self.item2.contains,
            "Failed to load item nested with depth 2.")

        self.assertItemExactlyOnceIn(
            self.item4, self.item3.contains,
            "Failed to load item nested with depth 3.")

    def tearDown(self):
        super().tearDown()
        os.remove(self.path)
コード例 #7
0
    def test_get_item_when_pc_is_on_surface(self):
        loc = Surface(self.game, "desk")
        loc.moveTo(self.start_room)
        loc.can_contain_standing_player = True

        sub_loc = Surface(self.game, "box")
        sub_loc.moveTo(loc)
        sub_loc.can_contain_standing_player = True

        self.game.me.moveTo(sub_loc)

        self.game.turnMain("take desk")

        self.assertIn("You climb down from the desk. ", self.app.print_stack)
コード例 #8
0
 def test_add_remove_composite_item_from_Surface(self):
     parent = Surface(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)
コード例 #9
0
 def setUp(self):
     super().setUp()
     self.surface = Surface(self.game, "bench")
     self.surface.can_contain_standing_player = True
     self.start_room.addThing(self.surface)
     ClimbOnVerb()._runVerbFuncAndEvents(self.game, self.surface)
     self.assertIs(self.me.location, self.surface)
コード例 #10
0
 def setUp(self):
     super().setUp()
     self.surface = Surface(self.game, "bench")
     self.surface.can_contain_standing_player = True
     self.start_room.addThing(self.surface)
     self.game.turnMain("climb on bench")
     self.assertIs(self.me.location, self.surface)
コード例 #11
0
    def test_composite_object_redirection(self):
        bench = Surface(self.game, "bench")
        self.start_room.addThing(bench)
        underbench = UnderSpace(self.game, "space")
        bench.addComposite(underbench)

        widget = Thing(self.game, "widget")
        underbench.addThing(widget)

        self.game.turnMain("look under bench")
        msg = self.app.print_stack.pop()

        self.assertIn(
            widget.verbose_name,
            msg,
            "Unexpected response attempting to use a component redirection",
        )
コード例 #12
0
 def test_cannot_set_non_lock_as_door_lock(self):
     room2 = Room(
         self.game, "A different place", "Description of a different place. "
     )
     c = DoorConnector(self.game, self.start_room, "n", room2, "s")
     lock = Surface(self.game, "lock?")
     with self.assertRaises(IFPError):
         c.setLock(lock)
コード例 #13
0
 def test_add_remove_item_with_lock_from_Surface(self):
     parent = Surface(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)
コード例 #14
0
    def test_gets_correct_verb_with_preposition_dobj_and_iobj(self):
        dobj = Thing(self.game, self._get_unique_noun())
        self.start_room.addThing(dobj)
        iobj = Surface(self.game, self._get_unique_noun())
        self.start_room.addThing(iobj)

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

        self.assertIs(self.game.parser.command.verb, SetOnVerb)
        self.assertIs(self.game.parser.command.dobj.target, dobj)
        self.assertIs(self.game.parser.command.iobj.target, iobj)
コード例 #15
0
ファイル: test_set_verbs.py プロジェクト: JSMaika/intficpy
    def test_set_composite_child_on_gives_attached_message(self):
        parent = Thing(self.game, "thing")
        parent.moveTo(self.me)
        item = Thing(self.game, "handle")
        parent.addComposite(item)
        surface = Surface(self.game, "place")
        self.start_room.addThing(surface)

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

        self.assertIn("is attached to", self.app.print_stack.pop())
        self.assertIs(item.location, self.me)
コード例 #16
0
ファイル: test_set_verbs.py プロジェクト: JSMaika/intficpy
    def test_set_on_adds_item(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.me.addThing(item)
        surface = Surface(self.game, self._get_unique_noun())
        self.start_room.addThing(surface)

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

        self.game.turnMain(
            f"set {item.verbose_name} on {surface.verbose_name}")

        self.assertIn(item.ix, surface.contains)
        self.assertIn(item, surface.contains[item.ix])
コード例 #17
0
    def test_set_on_adds_item(self):
        item = Thing(self.game, self._get_unique_noun())
        item.invItem = True
        self.me.addThing(item)
        surface = Surface(self.game, self._get_unique_noun())
        self.start_room.addThing(surface)

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

        success = SetOnVerb()._runVerbFuncAndEvents(self.game, item, surface)
        self.assertTrue(success)

        self.assertIn(item.ix, surface.contains)
        self.assertIn(item, surface.contains[item.ix])
コード例 #18
0
    def test_take_all_does_not_take_items_that_are_not_discovered(self):
        desk = Surface(self.game, "desk")
        desk.inv_item = False
        desk.desc_reveal = False  # don't reveal the contents with "look"
        desk.moveTo(self.start_room)
        hat = Thing(self.game, "hat")
        hat.moveTo(desk)

        self.game.turnMain("l")
        self.game.turnMain("take all")

        self.assertTrue(self.game.me.containsItem(hat))
コード例 #19
0
    def test_take_all_takes_known_objects_from_sub_locations(self):
        desk = Surface(self.game, "desk")
        desk.inv_item = False
        desk.desc_reveal = True
        desk.moveTo(self.start_room)
        hat = Thing(self.game, "hat")
        hat.moveTo(desk)

        self.game.turnMain("l")
        self.game.turnMain("take all")

        self.assertTrue(self.game.me.containsItem(hat))
コード例 #20
0
    def setUp(self):
        super().setUp()
        FILENAME = "_ifp_tests_saveload__0003.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.EXPECTED_ATTR = {
            "data": {
                "sarah_has_seen": True,
                "containers": [self.item1],
            },
            "owner": self.me,
        }

        self.item1.custom_attr = self.EXPECTED_ATTR.copy()

        SaveGame(self.game, self.path)
        self.item1.custom_attr.clear()
コード例 #21
0
ファイル: testgame.py プロジェクト: JSMaika/intficpy

def takeOpalFunc(game):
    if not me.opaltaken:
        game.addText(
            "As you hold the opal in your hand, you're half-sure you can feel the air cooling around you. A shiver runs down your spine. Something is not right here.",
        )
        me.opaltaken = True
        opalAchievement.award(game)
        print(opal.ix)
        print(opal.ix in me.knows_about)


opal.getVerbDobj = takeOpalFunc

bench = Surface(game, "bench")
bench.can_contain_sitting_player = True
bench.can_contain_standing_player = True
bench.invItem = False
bench.description = "A rough wooden bench sits against the wall. "
bench.x_description = (
    "The wooden bench is splintering, and faded grey. It looks very old. ")
bench.moveTo(startroom)

underbench = UnderSpace(game, "space")
underbench.contains_preposition = "in"
bench.addComposite(underbench)
# UnderSpaces that are components of another item are not described if their "description"
# attribute is None
# This also means that we cannot see what's underneath
# Set description to an empty string so we can show what's underneath without
コード例 #22
0
 def setUp(self):
     super().setUp()
     self.surface = Surface(self.game, "bench")
     self.start_room.addThing(self.surface)
コード例 #23
0
 def test_add_remove_from_Surface(self):
     parent = Surface(self.game, "parent")
     child = Thing(self.game, "child")
     self.start_room.addThing(parent)
     self._assert_can_add_remove(parent, child)
コード例 #24
0
ファイル: test_set_verbs.py プロジェクト: JSMaika/intficpy
 def test_set_surface_on_itself(self):
     item = Surface(self.game, "thing")
     item.moveTo(self.start_room)
     self.game.turnMain("set thing on thing")
     self.assertIn("You cannot", self.app.print_stack.pop())
     self.assertFalse(item.containsItem(item))