def test_del(world, null_entity, null_component): del null_entity[NullComponent] assert NullComponent in null_entity assert null_entity[NullComponent] is null_component world._flush_component_updates() assert NullComponent not in null_entity
def test_resolving_reference(world): to_entity = world.create_entity() from_entity = world.create_entity() from_entity.add_component(Reference(uid=to_entity._uid)) world._flush_component_updates() reference = world.get_entity(from_entity.get_component(Reference).uid) assert reference is to_entity
def clock(world, entity): dt = 0.01 clock = SettableClock(dt) entity[Clock] = Clock(clock=clock) world._flush_component_updates() assert dt < entity[Clock].max_timestep return clock
def test_get(world, entity, null_component): entity.add_component(null_component) world._flush_component_updates() assert entity[NullComponent] is null_component assert entity.get(NullComponent) is null_component assert entity.get("missing") is None assert entity.get("missing", "default_value") is "default_value"
def test_addition_to_system__entity_first(world, null_system): entity = world.create_entity(NullComponent()) world._flush_component_updates() world.add_system(null_system, 0) assert entity in null_system.entities['null'] assert len(null_system.entries) == 1 assert null_system.entries[0] == (['null'], entity)
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_resolving_dangling_reference(world): to_entity = world.create_entity() from_entity = world.create_entity() from_entity.add_component(Reference(uid=to_entity._uid)) world.destroy_entity(to_entity) world._flush_component_updates() with pytest.raises(NoSuchUID): world.get_entity(from_entity.get_component(Reference).uid)
def test_add_component(world, entity): component = NullComponent() entity[NullComponent] = component assert entity in world._addition_pool with pytest.raises(KeyError): entity[NullComponent] world._flush_component_updates() assert entity not in world._addition_pool assert entity[NullComponent] is component
def test_remove_aspect_from_entity(world): aspect = Aspect([Component_A]) entity = world.create_entity(*aspect()) world._flush_component_updates() assert aspect.in_entity(entity) components = aspect.remove(entity) world._flush_component_updates() assert not aspect.in_entity(entity) assert Component_A not in entity assert len(components) == 1 assert isinstance(components[0], Component_A)
def test_remove_system(world, null_system): entity = world.create_entity(NullComponent()) world._flush_component_updates() world.add_system(null_system, 0) world.remove_system(NullSystem) assert null_system.entities['null'] == set() assert len(null_system.exits) == 1 assert null_system.entries[0] == (['null'], entity) assert world.systems == {} assert not world.has_system(NullSystem)
def test_basic_clock(world): world.add_system(DetermineTimestep(), sort=0) dt = 0.01 clock = SettableClock(dt) entity = world.create_entity(Clock(clock=clock)) world._flush_component_updates() assert dt < entity[Clock].max_timestep world.update() assert entity[Clock].timestep == dt
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 test_remove_component(world, entity): component = NullComponent() entity[NullComponent] = component world._flush_component_updates() del entity[NullComponent] assert entity in world._removal_pool assert entity[NullComponent] is component world._flush_component_updates() assert entity not in world._removal_pool with pytest.raises(KeyError): entity[NullComponent]
def test_proxying_system__proxy_type(world): class NonBareTypeProxy(ProxyingNullSystem): proxies = { 'null_proxy': ProxyType(NullComponent), } system = NonBareTypeProxy() world.add_system(system, 0) entity = world.create_entity(NullComponent()) world._flush_component_updates() assert entity in system.entities["null"] assert len(system.entries) == 1 assert system.entries[0] == (['null'], entity)
def test_compound_filter_1(world, entity): sub_filter_1 = and_filter([ComponentA]) f = and_filter([sub_filter_1]) s = set() assert not f(s) assert not f(entity) s = set([ComponentA]) assert f(s) entity.add_component(ComponentA()) world._flush_component_updates() assert f(entity)
def test_compound_filter_3(world, entity): sub_filter_1 = and_filter([ComponentA]) sub_filter_2 = or_filter([ComponentB, ComponentC]) f = or_filter([sub_filter_1, sub_filter_2]) s = set() assert not f(s) assert not f(entity) s = set([ComponentA]) assert f(s) entity.add_component(ComponentA()) world._flush_component_updates() assert f(entity) s = set([ComponentB]) assert f(s) entity.remove_component(ComponentA) entity.add_component(ComponentB()) world._flush_component_updates() assert f(entity) s = set([ComponentC]) assert f(s) entity.remove_component(ComponentB) entity.add_component(ComponentC()) world._flush_component_updates() assert f(entity)
def test_or_filter_with_entity(world, entity): f = or_filter([ComponentA, ComponentB]) assert not f(entity) entity.add_component(ComponentA()) world._flush_component_updates() assert f(entity) entity.add_component(ComponentB()) world._flush_component_updates() assert f(entity) entity.remove_component(ComponentA) world._flush_component_updates() assert f(entity) entity.remove_component(ComponentB) world._flush_component_updates() assert not f(entity)
def test_compound_filter_4(world, entity): sub_filter_1 = and_filter([ComponentA]) sub_filter_2 = or_filter([ComponentB, ComponentC]) f = and_filter([sub_filter_1, sub_filter_2]) # A and (B or C) # Empty s = set() assert not f(s) assert not f(entity) # A s = set([ComponentA]) assert not f(s) entity.add_component(ComponentA()) world._flush_component_updates() assert not f(entity) entity.remove_component(ComponentA) world._flush_component_updates() # B s = set([ComponentB]) assert not f(s) entity.add_component(ComponentB()) world._flush_component_updates() assert not f(entity) # A, B s = set([ComponentA, ComponentB]) assert f(s) entity.add_component(ComponentA()) world._flush_component_updates() assert f(entity) # A, C s = set([ComponentA, ComponentC]) assert f(s) entity.remove_component(ComponentB) entity.add_component(ComponentC()) world._flush_component_updates() assert f(entity) # C s = set([ComponentC]) assert not f(s) entity.remove_component(ComponentA) world._flush_component_updates() assert not f(entity)
def test_set(world, entity, null_component): entity[NullComponent] = null_component world._flush_component_updates()
def test_adding_aspect_to_entity(world): aspect = Aspect([Component_A]) entity = world.create_entity() aspect.add(entity) world._flush_component_updates() assert Component_A in entity
def test_contains(world, entity, null_component): entity.add_component(null_component) assert NullComponent not in entity world._flush_component_updates() assert NullComponent in entity
def test_get(world, entity, null_component): entity.add_component(null_component) world._flush_component_updates() assert entity[NullComponent] is null_component
def test_aspect_in_entity(world): aspect = Aspect([Component_A]) entity = world.create_entity() aspect.add(entity) world._flush_component_updates() assert aspect.in_entity(entity)