From 93d6e78dc71d1cf3ee5f8bb6f16fadfaf9b0c15e Mon Sep 17 00:00:00 2001 From: Christopher Lee Date: Fri, 4 Sep 2009 21:54:39 -0700 Subject: [PATCH] added test for GraphView inverse and improved MapView inverse test --- tests/sqltable_test.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/sqltable_test.py b/tests/sqltable_test.py index 0230b3c..cefd1bf 100644 --- a/tests/sqltable_test.py +++ b/tests/sqltable_test.py @@ -167,14 +167,15 @@ class SQLTable_Test(SQLTable_Setup): SELECT t1.my_id FROM %s t1, %s t2 WHERE t2.third_id=%%s and t1.other_id=t2.other_id """ % (self.joinTable1,self.joinTable2)) - assert m[self.sourceDB[2]] == self.targetDB[7] - assert m[self.sourceDB[3]] == self.targetDB[99] - assert self.sourceDB[2] in m r = ~m # get the inverse assert self.sourceDB[2] == r[self.targetDB[7]] assert self.sourceDB[3] == r[self.targetDB[99]] assert self.targetDB[7] in r - + + m = ~r # get the inverse of the inverse! + assert m[self.sourceDB[2]] == self.targetDB[7] + assert m[self.sourceDB[3]] == self.targetDB[99] + assert self.sourceDB[2] in m try: d = m[self.sourceDB[4]] raise AssertionError('failed to trap non-unique mapping') @@ -191,6 +192,30 @@ class SQLTable_Test(SQLTable_Setup): assert self.targetDB[6] in d and self.targetDB[8] in d assert self.sourceDB[2] in m + def test_graphview_inverse(self): + 'test inverse GraphView of SQL join' + m = GraphView(self.sourceDB, self.targetDB,"""\ + SELECT t2.third_id FROM %s t1, %s t2 + WHERE t1.my_id=%%s and t1.other_id=t2.other_id + """ % (self.joinTable1,self.joinTable2), serverInfo=self.serverInfo, + inverseSQL="""\ + SELECT t1.my_id FROM %s t1, %s t2 + WHERE t2.third_id=%%s and t1.other_id=t2.other_id + """ % (self.joinTable1,self.joinTable2)) + r = ~m # get the inverse + assert self.sourceDB[2] in r[self.targetDB[7]] + assert self.sourceDB[3] in r[self.targetDB[99]] + assert self.targetDB[7] in r + d = r[self.targetDB[6]] + assert len(d) == 1 + assert self.sourceDB[4] in d + + m = ~r # get inverse of the inverse! + d = m[self.sourceDB[4]] + assert len(d) == 2 + assert self.targetDB[6] in d and self.targetDB[8] in d + assert self.sourceDB[2] in m + class SQLiteBase(testutil.SQLite_Mixin): def sqlite_load(self): self.load_data('sqltable_test', writeable=self.writeable) -- 2.11.4.GIT