def test_is_not_in_inventory(world, room, item): actor = world.create_entity( RoomPresence(room=room._uid), Inventory(), ) world._flush_component_updates() assert not is_in_inventory(item, actor)
def test_can_not_drop_item_that_actor_does_not_have_exception(world, room, item): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(throw_exc=True), 1) actor = world.create_entity( RoomPresence(room=room._uid), Inventory(), DropAction(item=item._uid), ) with pytest.raises(ItemNotInInventory): world.update()
def test_can_not_take_nonexistant_item_exception(world, room): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(throw_exc=True), 1) actor = world.create_entity( RoomPresence(room=room._uid), Inventory(), TakeAction(item=UID()), ) with pytest.raises(NoSuchUID): world.update()
def test_is_in_inventory(world, room): item = world.create_entity( Takeable(), ) actor = world.create_entity( RoomPresence(room=room._uid), Inventory(contents=[item._uid]), ) world._flush_component_updates() assert is_in_inventory(item, actor)
def can_not_drop_untakeable_item_exception(world, room): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(throw_exc=True), 1) item = world.create_entity() actor = world.create_entity( RoomPresence(room=room._uid), Inventory(contents=[item._uid]), DropAction(item=item._uid), ) with pytest.raises(NotTakeable): world.update()
def test_can_not_take_from_the_void_exception(world): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(throw_exc=True), 1) item = world.create_entity( Takeable(), ) actor = world.create_entity( Inventory(contents=[item._uid]), DropAction(item=item._uid), ) with pytest.raises(ActorNotInRoom): world.update()
def test_can_not_take_nonexistant_item(world, room): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) actor = world.create_entity( RoomPresence(room=room._uid), Inventory(), TakeAction(item=UID()), ) world.update() assert actor.get_component(Inventory).contents == [] assert not actor.has_component(TakeAction)
def test_can_not_drop_item_that_actor_does_not_have(world, room, item): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) actor = world.create_entity( RoomPresence(room=room._uid), Inventory(), DropAction(item=item._uid), ) world.update() assert actor.get_component(Inventory).contents == [] assert not actor.has_component(DropAction) assert item.has_component(RoomPresence)
def test_can_not_take_item_from_other_room_exception(world, room, item): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(throw_exc=True), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) other_room = world.create_entity( Room(), ) actor = world.create_entity( RoomPresence(room=other_room._uid), Inventory(), TakeAction(item=item._uid), ) with pytest.raises(ItemNotInRoom): world.update()
def test_can_not_take_from_the_void(world): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) item = world.create_entity( Takeable(), ) actor = world.create_entity( Inventory(), TakeAction(item=item._uid), ) world.update() assert actor.get_component(Inventory).contents == [] assert not actor.has_component(TakeAction)
def can_not_drop_untakeable_item(world, room): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) item = world.create_entity() actor = world.create_entity( RoomPresence(room=room._uid), Inventory(contents=[item._uid]), DropAction(item=item._uid), ) world.update() assert actor.get_component(Inventory).contents == [item._uid] assert not actor.has_component(DropAction) assert not item.has_component(RoomPresence)
def test_can_not_take_item_from_other_room(world, room, item): world.add_system(PerceiveRoom(), 0) world.add_system(TakeOrDrop(), 1) world.add_system(PerceiveRoom(), 2, add_duplicates=True) other_room = world.create_entity( Room(), ) actor = world.create_entity( RoomPresence(room=other_room._uid), Inventory(), TakeAction(item=item._uid), ) world.update() assert actor.get_component(Inventory).contents == [] assert not actor.has_component(TakeAction) assert item.has_component(RoomPresence)