Esempio n. 1
0
def test_entity_components_has_all(world, empty_entity, component_a,
                                   component_b):
    ca = component_a()
    cb = component_b()
    add_components(empty_entity, (ca, cb), world=world)
    assert entity_components(empty_entity, (component_a, component_b),
                             world=world) == {
                                 component_a: ca,
                                 component_b: cb
                             }
Esempio n. 2
0
def test_add_duplicate_components_error(world, empty_entity, component_a):
    c1 = component_a()
    c2 = component_a()
    with pytest.raises(
            ValueError,
            match=f"duplicate components.*{component_a.__name__}",
    ):
        add_components(empty_entity, (c1, c2), world=world)
    assert world._entities[empty_entity] == {}
    assert empty_entity not in set().union(*world._entity_cache.values())
Esempio n. 3
0
def test_add_existing_component_error(world, empty_entity, component_a,
                                      component_b):
    c = component_a()
    add_component(empty_entity, c, world=world)
    ca = component_a()
    cb = component_b()
    with pytest.raises(
            ValueError,
            match=f"duplicate components.*{component_a.__name__}",
    ):
        add_components(empty_entity, (ca, cb), world=world)
    assert world._entities[empty_entity][component_a] == c
    assert empty_entity in world._entity_cache[component_a]
    assert component_b not in world._entities[empty_entity]
    assert empty_entity not in world._entity_cache.get(component_b, {})
    assert not world._entity_bitmasks[empty_entity] & component_b._bitmask
Esempio n. 4
0
def test_add_components(world, empty_entity, component_a, component_b):
    assert empty_entity not in world._entity_cache.get(component_a, {})
    assert component_a not in world._entities[empty_entity]
    assert empty_entity not in world._entity_cache.get(component_b, {})
    assert component_b not in world._entities[empty_entity]
    assert not world._entity_bitmasks[empty_entity] & (component_a._bitmask
                                                       | component_b._bitmask)
    ca = component_a()
    cb = component_b()
    add_components(empty_entity, (ca, cb), world=world)
    assert world._entities[empty_entity][component_a] == ca
    assert empty_entity in world._entity_cache[component_a]
    assert world._entities[empty_entity][component_b] == cb
    assert empty_entity in world._entity_cache[component_b]
    assert world._entity_bitmasks[empty_entity] & (component_a._bitmask
                                                   | component_b._bitmask)
Esempio n. 5
0
def test_add_component_no_entity(world, component_a):
    with pytest.raises(KeyError):
        add_components(23, component_a(), world=world)
Esempio n. 6
0
def test_has_components_all(empty_entity, world, component_a, component_b):
    add_components(empty_entity, (component_a(), component_b()), world)
    assert has_components(empty_entity, (component_a, component_b), world)
Esempio n. 7
0
 def snecs_add_component(ents):
     for ent in ents:
         add_components(ent, (c1, c2, c3), snecs_world)