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)
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)
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)
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)
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 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)
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)
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)
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)
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")
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)
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)
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)
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))
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))
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])
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])
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", )
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()
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
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))
def setUp(self): super().setUp() self.surface = Surface(self.game, "bench") self.start_room.addThing(self.surface)
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)