From dc267ca98ea88174705bf7a99ab14bc518eb50e2 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Tue, 19 Jan 2021 09:53:51 +0000 Subject: [PATCH] Introduce tests for semantic select query --- tests/test_select.py | 67 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/tests/test_select.py b/tests/test_select.py index 66c3992..dcf83aa 100644 --- a/tests/test_select.py +++ b/tests/test_select.py @@ -41,15 +41,22 @@ def setup_module(): name="TestPropertyOne", value="v1").add_property( name="TestPropertyTwo", value="v2").insert() rt_house = db.RecordType("TestHouse", description="TestHouseDesc").insert() - db.RecordType("TestWindow").insert() + db.RecordType("TestHousePart", description="TestHousePartDesc").insert() + db.RecordType("TestWindow").add_parent("TestHousePart").insert() + db.RecordType("TestDoor").add_parent("TestHousePart").insert() rt_person = db.RecordType("TestPerson", description="TestPersonDesc").insert() db.RecordType("TestParty", description="TestPartyDesc").insert() + db.Property("TestHouseProperty", datatype=db.TEXT).insert() db.Property("TestHeight", description="TestHeightDesc", datatype=db.DOUBLE, - unit="ft").insert() + unit="ft").add_parent("TestHouseProperty").insert() db.Property("TestDate", description="TestDateDesc", datatype=db.DATETIME).insert() + door = db.Record("Door1", + description="Door1Desc").add_parent("TestDoor") + door.add_property("TestHeight", "21.5", unit="ft") + door.insert() window = db.Record("Window1", description="Window1Desc").add_parent("TestWindow") window.add_property("TestHeight", 20.5, unit="ft") @@ -61,7 +68,9 @@ def setup_module(): house.description = "A rather large house" house.add_parent("TestHouse") house.add_property(rt_person, name="TestOwner", value=owner) - house.add_property("TestWindow", window).insert() + house.add_property("TestWindow", window) + house.add_property("TestDoor", door) + house.insert() g1 = db.Record().add_parent("TestPerson").insert() g2 = db.Record().add_parent("TestPerson").insert() @@ -326,3 +335,55 @@ def test_select_name(): "RECORD TestWindow", unique=True) column = s.get_property_values(("TestHeight", "name", "TestWindow")) assert column == (None,) + + +def test_select_with_subtyping_semantics(): + s = db.execute_query( + "SELECT name FROM RECORD TestHouse WITH TestHousePart", + unique=True) + column = s.get_property_values("name") + assert column == ("Buckingham Palace",) + + s = db.execute_query( + "SELECT TestWindow.TestHeight FROM RECORD TestHouse WITH TestHousePart", + unique=True) + column = s.get_property_values(("TestWindow", "TestHeight")) + assert column == (20.5,) + + s = db.execute_query( + "SELECT TestHousePart.TestHeight FROM RECORD TestHouse WITH TestHousePart", + unique=True) + column = s.get_property_values(("TestHousePart", "TestHeight")) + # this is a current limitation of get_property_values which will only + # return the value of the first matching property + assert column == (20.5,) + + assert len(s.properties) == 2 + # both the door and the window have been returned + assert (s.properties[0].name, + s.properties[1].name) == ("TestHousePart", "TestHousePart") + assert (s.properties[0].value.properties[0].value, + s.properties[1].value.properties[0].value) == (20.5, 21.5) + + +def test_select_with_subtyping_semantics_second_level(): + s = db.execute_query( + "SELECT TestHousePart.TestHouseProperty FROM RECORD TestHouse WITH TestHousePart", + unique=True) + column = s.get_property_values(("TestHousePart", "TestHouseProperty")) + # this is a current limitation of get_property_values which will only + # return the value of the first matching property + assert column == (20.5,) + + assert len(s.properties) == 2 + # both the door and the window have been returned + assert (s.properties[0].name, + s.properties[1].name) == ("TestHousePart", "TestHousePart") + assert (s.properties[0].value.properties[0].value, + s.properties[1].value.properties[0].value) == (20.5, 21.5) + + +def test_select_with_subtyping_semantics_and_name_duplicates(): + db.Property(name="TestHousePart", description="This is a duplicate", + datatype=db.TEXT).insert(unique=False) + test_select_with_subtyping_semantics() -- GitLab