def test_pour_out_non_liquid_non_container_from_container(self): item = Thing(self.game, "bead") item.size = 2 item.moveTo(self.old_container) self.old_container.removeThing(self.liquid) self.game.turnMain("pour bottle into bowl") self.assertIn("You dump the bottle", self.app.print_stack.pop())
def test_fill_container_from_container_containing_only_non_liquids(self): item = Thing(self.game, "bead") item.size = 2 item.moveTo(self.old_container) self.old_container.removeThing(self.liquid) self.game.turnMain("fill bowl from bottle") self.assertIn("no liquid in", self.app.print_stack.pop())
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))
def test_pour_out_non_liquid_non_container_item_too_large(self): item = Thing(self.game, "bead") item.size = 100 item.moveTo(self.old_container) self.old_container.removeThing(self.liquid) self.game.turnMain("pour bottle into bowl") self.assertIn("too large to fit inside", self.app.print_stack.pop())
def test_doff_player_not_wearing_gives_player_not_wearing_message(self): item = Thing(self.game, "item") item.moveTo(self.start_room) self.game.turnMain("doff item") self.assertIn( "aren't wearing", self.app.print_stack.pop(), "Did not receive expected 'not wearing' scope message", )
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))
def test_fill_container_containing_non_liquid_item(self): item = Thing(self.game, "bead") item.moveTo(self.new_container) self.game.turnMain("fill bowl from bottle") self.assertIn("You fill the bowl", self.app.print_stack.pop()) self.assertIn("You dump", self.app.print_stack.pop()) self.assertIs(item.location, self.start_room) self.assertIs(self.liquid.location, self.new_container)
def test_set_on_floor_add_item_to_outer_room(self): item = Thing(self.game, "thing") item.invItem = True item.moveTo(self.game.me) self.assertIsNot(item.location, self.start_room) self.game.turnMain(f"set thing on floor") self.assertIs(item.location, self.start_room)
def test_player_cannot_light_non_light_source(self): item = Thing(self.game, "ball") item.moveTo(self.me) self.game.turnMain("look") self.assertNotIn(self.start_room.desc, self.app.print_stack) self.assertIn("dark", self.app.print_stack.pop()) self.game.turnMain("light ball") self.assertIn("not a light source", self.app.print_stack.pop()) self.game.turnMain("look") self.assertNotIn(self.start_room.desc, self.app.print_stack)
def test_pour_non_liquid_into_non_container(self): item = Thing(self.game, "bead") item.size = 2 item.moveTo(self.old_container) self.old_container.removeThing(self.liquid) rock = Thing(self.game, "rock") rock.moveTo(self.start_room) self.game.turnMain("pour bottle into rock") self.assertIn("not a container", self.app.print_stack.pop())
def test_pour_liquid_into_container_containing_non_liquid_item(self): item = Thing(self.game, "bead") item.moveTo(self.new_container) self.game.turnMain("pour bottle into bowl") self.assertIn("You pour", self.app.print_stack.pop()) self.assertIn("You dump the contents of the bowl", self.app.print_stack.pop()) self.assertIs(item.location, self.start_room) self.assertIs(self.liquid.location, self.new_container)
def test_pour_out_non_liquid_non_container_item_too_large(self): item = Thing(self.game, "bead") item.size = 100 item.moveTo(self.old_container) self.old_container.removeThing(self.liquid) self.game.turnMain("pour bottle into bowl") self.assertIn( self.new_container.does_not_fit_msg.format( item=item, self=self.new_container), self.app.print_stack, )
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)
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)
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)
def test_pour_liquid_into_container_containing_non_liquid_item(self): # TODO: rethink the handling of priority. item = Thing(self.game, "bead") item.moveTo(self.new_container) self.game.turnMain("pour bottle into bowl") self.assertIn("You dump the bottle in the bowl", self.app.print_stack.pop()) self.assertIn("You dump out the bowl", self.app.print_stack.pop()) self.assertIn("(First trying to dump out the bowl", self.app.print_stack.pop()) self.assertIs(item.location, self.start_room) self.assertIs(self.liquid.location, self.new_container)
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", )
def test_player_cannot_extinguish_non_light_source(self): item = Thing(self.game, "ball") item.moveTo(self.me) self.game.turnMain("put out ball") self.assertIn("not a light source", self.app.print_stack.pop())
def test_fill_non_container(self): item = Thing(self.game, "bead") item.moveTo(self.start_room) self.game.turnMain("fill bead from bottle") self.assertIn("can't fill that", self.app.print_stack.pop())
def test_pour_out_non_liquid_non_container(self): item = Thing(self.game, "bead") item.moveTo(self.start_room) self.game.turnMain("pour bead into bowl") self.assertIn("has nothing on", self.app.print_stack.pop())
def test_fill_container_non_container_non_liquid(self): item = Thing(self.game, "rock") item.moveTo(self.start_room) self.game.turnMain("fill bowl from rock") self.assertIn("no liquid in the rock", self.app.print_stack.pop())