From: Gerhard H?r. <gha...@us...> - 2002-04-21 21:05:46
|
Update of /cvsroot/pypgsql/pypgsql/test/regression In directory usw-pr-cvs1:/tmp/cvs-serv22372/test/regression Modified Files: array.py Log Message: 21APR2002 gh Added some more mean testcases, which test for control characters and other special characters inside strings, and multi-dimensional arrays. Index: array.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/test/regression/array.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** array.py 17 Apr 2002 00:18:22 -0000 1.1 --- array.py 21 Apr 2002 21:05:43 -0000 1.2 *************** *** 35,38 **** --- 35,41 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 21APR2002 gh Added some more mean testcases, which test for control | + # characters and other special characters inside strings, | + # and multi-dimensional arrays. | # 16APR2002 gh Initial release by Gerhard Häring. | #-----------------------------------------------------------------------+ *************** *** 44,47 **** --- 47,51 ---- def setUp(self): self.conn = PgSQL.connect(database="pypgsql") + self.conn.autocommit = 1 def checkEqual(self, real, planned): *************** *** 52,55 **** --- 56,63 ---- ivalues = [3,4,5] cursor = self.conn.cursor() + try: + cursor.execute("drop table test") + except: + pass cursor.execute("create table test (ia int[])") cursor.execute("insert into test(ia) values (%s)", (ivalues,)) *************** *** 59,63 **** "the integer array isn't returned as a list") self.checkEqual(result.ia, ivalues) - self.conn.rollback() def CheckForNumericInsert(self): --- 67,70 ---- *************** *** 65,68 **** --- 72,79 ---- cursor = self.conn.cursor() + try: + cursor.execute("drop table test") + except: + pass cursor.execute("create table test(na numeric[])") cursor.execute("insert into test(na) values (%s)", (numlist,)) *************** *** 72,79 **** "the numeric array isn't returned as a list") self.checkEqual(result.na, numlist) - self.conn.rollback() def CheckForStringInsert(self): - #self.conn.conn.toggleShowQuery cursor = self.conn.cursor() --- 83,88 ---- *************** *** 88,92 **** for stringlist in stringlists: ! cursor.execute("create table test(va varchar[])") cursor.execute("insert into test(va) values (%s)", (stringlist,)) cursor.execute("select va from test") --- 97,105 ---- for stringlist in stringlists: ! try: ! cursor.execute("drop table test") ! except: ! pass ! cursor.execute("create table test(va varchar[])") cursor.execute("insert into test(va) values (%s)", (stringlist,)) cursor.execute("select va from test") *************** *** 95,99 **** "the varchar array isn't returned as a list") self.checkEqual(result.va, stringlist) ! self.conn.rollback() if __name__ == "__main__": --- 108,183 ---- "the varchar array isn't returned as a list") self.checkEqual(result.va, stringlist) ! ! def CheckForStringInsertBruteForce(self): ! cursor = self.conn.cursor() ! ! chars = "\"'{}\\\n%s%sabc" % (chr(14), chr(5)) ! ! try: ! cursor.execute("drop table test") ! except: ! pass ! cursor.execute("create table test(va varchar[])") ! self.conn.commit() ! for i in chars: ! for j in chars: ! for k in chars: ! cursor.execute("insert into test(va) values (%s)", ([i+j+k],)) ! cursor.execute("select va from test where oid=%s", cursor.oidValue) ! result = cursor.fetchone() ! self.failUnlessEqual(type(result.va), types.ListType, \ ! "the varchar array isn't returned as a list") ! self.checkEqual(result.va, [i+j+k]) ! ! def CheckForStringInsertMultiDim(self): ! cursor = self.conn.cursor() ! ! stringlists = [[["a", "b"], ["c", "d"]], ! [[["a", "b"], ["c", "d"]], [["e", None], ["g", "h"]]], ! [[["{}", "\005{}\\'"], ["'asf'", "[\\{]"]], [["e", "f"], ["g", "h"]]], ! [["a", "b"], ["c", "d"]]] ! ! for stringlist in stringlists: ! try: ! cursor.execute("drop table test") ! except: ! pass ! cursor.execute("create table test(va varchar[])") ! cursor.execute("insert into test(va) values (%s)", (stringlist,)) ! cursor.execute("select va from test") ! result = cursor.fetchone() ! self.failUnlessEqual(type(result.va), types.ListType, \ ! "the varchar array isn't returned as a list") ! ! expected = stringlist[:] ! try: ! if expected[1][0][1] is None: ! expected[1][0][1] = '' ! except IndexError, reason: ! pass ! ! self.checkEqual(result.va, expected) ! ! def CheckForIntInsertMultiDim(self): ! cursor = self.conn.cursor() ! ! intlists = [[[1,2], [3,4]], ! [[-5,3,4], [2, None, 10]]] ! ! excpected_intlists = [[[1,2], [3,4]], ! [[-5,3,4], [2, 0, 10]]] ! ! for intlist, expected in zip(intlists, excpected_intlists): ! try: ! cursor.execute("drop table test") ! except: ! pass ! cursor.execute("create table test(ia int[])") ! cursor.execute("insert into test(ia) values (%s)", (intlist,)) ! cursor.execute("select ia from test") ! result = cursor.fetchone() ! self.failUnlessEqual(type(result.ia), types.ListType, \ ! "the int array isn't returned as a list") ! self.checkEqual(result.ia, expected) if __name__ == "__main__": *************** *** 103,106 **** --- 187,193 ---- TestSuite.addTest(ArrayTestCases("CheckForNumericInsert")) TestSuite.addTest(ArrayTestCases("CheckForStringInsert")) + #TestSuite.addTest(ArrayTestCases("CheckForStringInsertBruteForce")) + TestSuite.addTest(ArrayTestCases("CheckForStringInsertMultiDim")) + TestSuite.addTest(ArrayTestCases("CheckForIntInsertMultiDim")) runner = unittest.TextTestRunner() |