Example #1
0
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()
Example #2
0
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()
Example #3
0
def test_can_not_take_without_an_inventory_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)
    actor = world.create_entity(
        RoomPresence(room=room._uid),
        TakeAction(item=item._uid),
    )
    with pytest.raises(ActorHasNoInventory):
        world.update()
Example #4
0
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()
Example #5
0
def test_can_not_take_without_an_inventory(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),
        TakeAction(item=item._uid),
    )
    world.update()

    assert not actor.has_component(TakeAction)
    assert item.has_component(RoomPresence)
Example #6
0
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()
Example #7
0
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)
Example #8
0
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)
Example #9
0
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()
Example #10
0
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)
Example #11
0
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)
Example #12
0
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)