From eaf34b8c29658dc42fe80aa5db8f9110329e396e Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Mon, 25 Jan 2021 21:51:49 +0100
Subject: [PATCH] WIP

---
 tests/test_select.py | 216 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 174 insertions(+), 42 deletions(-)

diff --git a/tests/test_select.py b/tests/test_select.py
index f20022c..af2bf3a 100644
--- a/tests/test_select.py
+++ b/tests/test_select.py
@@ -192,33 +192,71 @@ def test_sub2():
 
 
 def test_subref():
-    window = db.execute_query("FIND RECORD TestWindow", unique=True)
-    s = db.execute_query("SELECT name, TestWindow.TestHeight.value, "
-                         "TestWindow.TestHeight.unit FROM RECORD TestHouse")
+    door = db.execute_query("FIND RECORD TestDoor", unique=True)
+    s = db.execute_query("SELECT name, TestDoor.TestHeight.value, "
+                         "TestDoor.TestHeight.unit FROM RECORD TestHouse")
 
     assert len(s) == 1
 
-    row = s.get_property_values("name", "TestWindow")[0]
+    row = s.get_property_values("name", "TestDoor")[0]
     assert row[0] == "Buckingham Palace"
-    assert row[1] == window.id
+    assert row[1] == door.id
 
-    row = s.get_property_values("name", ("TestWindow", "TestHeight"))[0]
+    row = s.get_property_values("name", ("TestDoor", "TestHeight"))[0]
     assert row[0] == "Buckingham Palace"
-    assert row[1] == 20.5
+    assert row[1] == 21.5
 
     row = s.get_property_values(
-        "name", ("TestWindow", "TestHeight", "unit"))[0]
+        "name", ("TestDoor", "TestHeight", "unit"))[0]
     assert row[0] == "Buckingham Palace"
     assert row[1] == "ft"
 
 
+def test_subref_list():
+    window = db.execute_query("FIND RECORD TestWindow", unique=True)
+    s = db.execute_query("SELECT name, TestWindow.TestHeight.value, "
+                         "TestWindow.TestHeight.unit FROM RECORD TestHouse")
+
+    assert len(s) == 1
+
+    row = s.get_property_values("name", "TestWindow")[0]
+    assert row[0] == "Buckingham Palace"
+    assert row[1][0].id == window.id
+
+    # current limitation of get_property_values - no lists
+    # row = s.get_property_values("name", ("TestWindow", "TestHeight"))[0]
+    # assert row[0] == "Buckingham Palace"
+    # assert row[1] == 20.5
+    assert row[1][0].get_property("TestHeight").value == 20.5
+
+    # current limitation of get_property_values - no lists
+    # row = s.get_property_values(
+    # "name", ("TestWindow", "TestHeight", "unit"))[0]
+    # assert row[0] == "Buckingham Palace"
+    # assert row[1] == "ft"
+    assert row[1][0].get_property("TestHeight").unit == "ft"
+
+
 def test_subref_deep():
     p = db.execute_query(
-        "SELECT name, Testdate, location, location.TestWindow.Testheight FROM "
+        "SELECT name, Testdate, location, location.TestDoor.Testheight FROM "
         "RECORD TestParty", unique=True)
     row = p.get_property_values("name", "Testdate",
-                                ("location", "Testwindow", "Testheight"))
-    assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 20.5)
+                                ("location", "Testdoor", "Testheight"))
+    assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 21.5)
+
+
+def test_subref_deep_list():
+    p = db.execute_query(
+        "SELECT name, Testdate, location, location.TestWindow.Testheight FROM "
+        "RECORD TestParty", unique=True)
+
+    # current limitation of get_property_values - no lists
+    # row = p.get_property_values("name", "Testdate",
+    # ("location", "Testwindow", "Testheight"))
+    # assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 20.5)
+    assert p.get_property_values(("location", "TestWindow"))[
+        0][0].get_property("TestHeight").value == 20.5
 
 
 def test_select_list():
@@ -227,6 +265,7 @@ def test_select_list():
     s = db.execute_query("SELECT guests FROM RECORD TestParty", unique=True)
 
     column = s.get_property_values("guests")[0]
+    print(s)
     assert len(column) == len(guests)
 
     for eid in [e.id for e in guests]:
@@ -242,17 +281,35 @@ def test_select_unit():
     column = s.get_property_values("unit")
     assert column == ("ft",)
 
-    s = db.execute_query("SELECT TestWindow.TestHeight.unit FROM "
+    s = db.execute_query("SELECT TestDoor.TestHeight.unit FROM "
                          "RECORD TestHouse", unique=True)
-    column = s.get_property_values(("TestWindow", "TestHeight", "unit"))
+    column = s.get_property_values(("TestDoor", "TestHeight", "unit"))
     assert column == ("ft",)
 
-    s = db.execute_query("SELECT TestHeight.unit.TestWindow FROM "
-                         "RECORD TestWindow", unique=True)
-    column = s.get_property_values(("TestHeight", "unit", "TestWindow"))
+    s = db.execute_query("SELECT TestHeight.unit.TestDoor FROM "
+                         "RECORD TestDoor", unique=True)
+    column = s.get_property_values(("TestHeight", "unit", "TestDoor"))
     assert column == (None,)
 
 
+def test_select_unit_list():
+    s = db.execute_query("SELECT unit FROM RECORD TestHouse", unique=True)
+    column = s.get_property_values("unit")
+    assert column == (None,)
+
+    s = db.execute_query("SELECT unit FROM PROPERTY TestHeight", unique=True)
+    column = s.get_property_values("unit")
+    assert column == ("ft",)
+
+    s = db.execute_query("SELECT TestWindow.TestHeight.unit FROM "
+                         "RECORD TestHouse", unique=True)
+    # current limitation of get_property_values - no lists
+    # column = s.get_property_values(("TestWindow", "TestHeight", "unit"))
+    # assert column == ("ft",)
+    assert s.get_property_values(("TestWindow"))[
+        0][0].get_property("TestHeight").unit == "ft"
+
+
 def test_select_description():
     s = db.execute_query("SELECT description FROM RECORD TestPerson")
     column = s.get_property_values("description")
@@ -269,21 +326,50 @@ def test_select_description():
     assert column == ("A rather large house",)
 
     s = db.execute_query("SELECT TestHeight.description FROM "
-                         "RECORD TestWindow", unique=True)
+                         "RECORD TestDoor", unique=True)
     column = s.get_property_values(("TestHeight", "description"))
     assert column == ('TestHeightDesc',)
 
-    s = db.execute_query("SELECT TestWindow.TestHeight.description FROM "
+    s = db.execute_query("SELECT TestDoor.TestHeight.description FROM "
                          "RECORD TestHouse", unique=True)
-    column = s.get_property_values(("TestWindow", "TestHeight", "description"))
+    column = s.get_property_values(("TestDoor", "TestHeight", "description"))
     assert column == ('TestHeightDesc',)
 
-    s = db.execute_query("SELECT TestHeight.description.TestWindow FROM "
-                         "RECORD TestWindow", unique=True)
-    column = s.get_property_values(("TestHeight", "description", "TestWindow"))
+    s = db.execute_query("SELECT TestHeight.description.TestDoor FROM "
+                         "RECORD TestDoor", unique=True)
+    column = s.get_property_values(("TestHeight", "description", "TestDoor"))
     assert column == (None,)
 
 
+def test_select_description_list():
+    s = db.execute_query("SELECT description FROM RECORD TestPerson")
+    column = s.get_property_values("description")
+    assert column == [(None,), (None,), (None,), (None,)]
+
+    s = db.execute_query("SELECT description"
+                         "FROM RECORD TestHouse", unique=True)
+    column = s.get_property_values(("description"))
+    assert column == ("A rather large house",)
+
+    s = db.execute_query("SELECT location.description"
+                         "FROM RECORD TestParty", unique=True)
+    column = s.get_property_values(("location", "description"))
+    assert column == ("A rather large house",)
+
+    s = db.execute_query("SELECT TestHeight.description FROM "
+                         "RECORD TestWindow", unique=True)
+    column = s.get_property_values(("TestHeight", "description"))
+    assert column == ('TestHeightDesc',)
+
+    s = db.execute_query("SELECT TestWindow.TestHeight.description FROM "
+                         "RECORD TestHouse", unique=True)
+    # current limitation of get_property_values - no lists
+    # column = s.get_property_values(("TestWindow", "TestHeight", "description"))
+    # assert column == ('TestHeightDesc',)
+    assert s.get_property_values(("TestWindow"))[0][0].get_property(
+        "TestHeight").description == "TestHeightDesc"
+
+
 def test_select_id():
     house_id = db.execute_query("FIND RECORD TestHouse", unique=True).id
     s = db.execute_query("SELECT id FROM RECORD TestHouse", unique=True)
@@ -301,17 +387,43 @@ def test_select_id():
     column = s.get_property_values("id")
     assert column == (height_id,)
 
-    s = db.execute_query("SELECT TestWindow.TestHeight.id FROM "
+    s = db.execute_query("SELECT TestDoor.TestHeight.id FROM "
                          "RECORD TestHouse", unique=True)
-    column = s.get_property_values(("TestWindow", "TestHeight", "id"))
+    column = s.get_property_values(("TestDoor", "TestHeight", "id"))
     assert column == (height_id,)
 
-    s = db.execute_query("SELECT TestHeight.id.TestWindow FROM "
-                         "RECORD TestWindow", unique=True)
-    column = s.get_property_values(("TestHeight", "id", "TestWindow"))
+    s = db.execute_query("SELECT TestHeight.id.TestDoor FROM "
+                         "RECORD TestDoor", unique=True)
+    column = s.get_property_values(("TestHeight", "id", "TestDoor"))
     assert column == (None,)
 
 
+def test_select_id_list():
+    house_id = db.execute_query("FIND RECORD TestHouse", unique=True).id
+    s = db.execute_query("SELECT id FROM RECORD TestHouse", unique=True)
+    column = s.get_property_values("id")
+    assert column == (house_id,)
+
+    s = db.execute_query(
+        "SELECT location.id FROM RECORD TestHouse",
+        unique=True)
+    column = s.get_property_values("id")
+    assert column == (house_id,)
+
+    height_id = db.execute_query("FIND PROPERTY TestHeight", unique=True).id
+    s = db.execute_query("SELECT id FROM PROPERTY TestHeight", unique=True)
+    column = s.get_property_values("id")
+    assert column == (height_id,)
+
+    s = db.execute_query("SELECT TestWindow.TestHeight.id FROM "
+                         "RECORD TestHouse", unique=True)
+    # current limitation of get_property_values - no lists
+    # column = s.get_property_values(("TestWindow", "TestHeight", "id"))
+    # assert column == (height_id,)
+    assert s.get_property_values(("TestWindow"))[0][0].get_property(
+        "TestHeight").id == height_id
+
+
 def test_select_name():
     s = db.execute_query("SELECT name FROM RECORD TestHouse", unique=True)
     column = s.get_property_values("name")
@@ -326,17 +438,40 @@ def test_select_name():
     column = s.get_property_values("name")
     assert column == ("TestHeight",)
 
-    s = db.execute_query("SELECT TestWindow.TestHeight.name FROM "
+    s = db.execute_query("SELECT TestDoor.TestHeight.name FROM "
                          "RECORD TestHouse", unique=True)
-    column = s.get_property_values(("TestWindow", "TestHeight", "name"))
+    column = s.get_property_values(("TestDoor", "TestHeight", "name"))
     assert column == ("TestHeight",)
 
-    s = db.execute_query("SELECT TestHeight.name.TestWindow FROM "
-                         "RECORD TestWindow", unique=True)
-    column = s.get_property_values(("TestHeight", "name", "TestWindow"))
+    s = db.execute_query("SELECT TestHeight.name.TestDoor FROM "
+                         "RECORD TestDoor", unique=True)
+    column = s.get_property_values(("TestHeight", "name", "TestDoor"))
     assert column == (None,)
 
 
+def test_select_name_list():
+    s = db.execute_query("SELECT name FROM RECORD TestHouse", unique=True)
+    column = s.get_property_values("name")
+    assert column == ("Buckingham Palace",)
+
+    s = db.execute_query("SELECT location.name FROM RECORD TestHouse",
+                         unique=True)
+    column = s.get_property_values("name")
+    assert column == ("Buckingham Palace",)
+
+    s = db.execute_query("SELECT name FROM PROPERTY TestHeight", unique=True)
+    column = s.get_property_values("name")
+    assert column == ("TestHeight",)
+
+    s = db.execute_query("SELECT TestWindow.TestHeight.name FROM "
+                         "RECORD TestHouse", unique=True)
+    # current limitation of get_property_values - no lists
+    # column = s.get_property_values(("TestWindow", "TestHeight", "name"))
+    # assert column == ("TestHeight",)
+    assert s.get_property_values(("TestWindow"))[0][0].get_property(
+        "TestHeight").name == "TestHeight"
+
+
 def test_select_with_subtyping_semantics():
     s = db.execute_query(
         "SELECT name FROM RECORD TestHouse WITH TestHousePart",
@@ -345,10 +480,10 @@ def test_select_with_subtyping_semantics():
     assert column == ("Buckingham Palace",)
 
     s = db.execute_query(
-        "SELECT TestWindow.TestHeight FROM RECORD TestHouse WITH TestHousePart",
+        "SELECT TestDoor.TestHeight FROM RECORD TestHouse WITH TestHousePart",
         unique=True)
-    column = s.get_property_values(("TestWindow", "TestHeight"))
-    assert column == (20.5,)
+    column = s.get_property_values(("TestDoor", "TestHeight"))
+    assert column == (21.5,)
 
     s = db.execute_query(
         "SELECT TestHousePart.TestHeight FROM RECORD TestHouse WITH TestHousePart",
@@ -356,13 +491,14 @@ def test_select_with_subtyping_semantics():
     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 column == ([[20.5], 21.5,])
 
     assert len(s.properties) == 2
     # both the door and the window have been returned
+    print(s.properties[0].value)
     assert (s.properties[0].name,
             s.properties[1].name) == ("TestHousePart", "TestHousePart")
-    assert (s.properties[0].value.properties[0].value,
+    assert (s.properties[0].value[0].properties[0].value,
             s.properties[1].value.properties[0].value) == (20.5, 21.5)
 
 
@@ -370,16 +506,12 @@ 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,
+    assert (s.properties[0].value[0].properties[0].value,
             s.properties[1].value.properties[0].value) == (20.5, 21.5)
 
 
-- 
GitLab