diff --git a/unittests/test_entity.py b/unittests/test_entity.py index 3fb014f864b5e79844be7165e3b0093bca731451..2127ce028f4de55b8ef0ca704c1e69959c24ba82 100644 --- a/unittests/test_entity.py +++ b/unittests/test_entity.py @@ -233,3 +233,52 @@ def test_filter(): t.add_parent(ent) for ent in t_pars: assert ent in t_pars.filter(ent) + + # Grid-Based + r7 = Record() + r7.add_property(Property()).add_property(name="A").add_property(name="B") + r7.add_property(id=27).add_property(id=27, name="A").add_property(id=27, name="B") + r7.add_property(id=43).add_property(id=43, name="A").add_property(id=43, name="B") + assert len(r7.properties.filter(pid=27)) == 3 + assert len(r7.properties.filter(pid=43)) == 3 + assert len(r7.properties.filter(pid=43, conjunction=True)) == 3 + assert len(r7.properties.filter(name="A")) == 3 + assert len(r7.properties.filter(name="B")) == 3 + assert len(r7.properties.filter(name="B", conjunction=True)) == 3 + assert len(r7.properties.filter(pid=1, name="A")) == 1 + assert len(r7.properties.filter(pid=1, name="A", conjunction=True)) == 0 + assert len(r7.properties.filter(pid=27, name="B")) == 4 + assert len(r7.properties.filter(pid=27, name="B", conjunction=True)) == 1 + assert len(r7.properties.filter(pid=27, name="C")) == 3 + assert len(r7.properties.filter(pid=27, name="C", conjunction=True)) == 0 + # Entity based filtering behaves the same + assert (r7.properties.filter(pid=27) == + r7.properties.filter(Property(id=27))) + assert (r7.properties.filter(pid=43, conjunction=True) == + r7.properties.filter(Property(id=43), conjunction=True)) + assert (r7.properties.filter(name="A") == + r7.properties.filter(Property(name="A"))) + assert (r7.properties.filter(name="B") == + r7.properties.filter(Property(name="B"))) + assert (r7.properties.filter(name="B", conjunction=True) == + r7.properties.filter(Property(name="B"), conjunction=True)) + assert (r7.properties.filter(pid=1, name="A") == + r7.properties.filter(Property(id=1, name="A"))) + assert (r7.properties.filter(pid=1, name="A", conjunction=True) == + r7.properties.filter(Property(id=1, name="A"), conjunction=True)) + assert (r7.properties.filter(pid=27, name="B") == + r7.properties.filter(Property(id=27, name="B"))) + assert (r7.properties.filter(pid=27, name="B", conjunction=True) == + r7.properties.filter(Property(id=27, name="B"), conjunction=True)) + assert (r7.properties.filter(pid=27, name="C") == + r7.properties.filter(Property(id=27, name="C"))) + assert (r7.properties.filter(pid=27, name="C", conjunction=True) == + r7.properties.filter(Property(id=27, name="C"), conjunction=True)) + # Name only matching and name overwrite + r8 = Record().add_property(name="A").add_property(name="B").add_property(name="B") + r8.add_property(Property(name="A"), name="B") + r8.add_property(Property(name="A", id=12), name="C") + assert len(r8.properties.filter(name="A")) == 1 + assert len(r8.properties.filter(name="B")) == 3 + assert len(r8.properties.filter(name="C")) == 1 + assert len(r8.properties.filter(pid=12)) == 1