Skip to content
Snippets Groups Projects
Commit 04ae295a authored by I. Nüske's avatar I. Nüske
Browse files

TST: Additional filter tests based on docstring

parent 0d26d998
No related branches found
No related tags found
3 merge requests!159Release 0.16.o,!158F list filter,!157compare entities and parent/property lists
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment