From: Billy G. A. <bal...@us...> - 2002-11-03 19:53:25
|
Update of /cvsroot/pypgsql/pypgsql/test/regression In directory usw-pr-cvs1:/tmp/cvs-serv31831/test/regression Modified Files: array.py Log Message: 02NOV2002 bga Modified code to use the PgArray class for PostgreSQL arrays. Index: array.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/test/regression/array.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** array.py 21 Apr 2002 21:05:43 -0000 1.2 --- array.py 3 Nov 2002 19:53:22 -0000 1.3 *************** *** 35,38 **** --- 35,40 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 02NOV2002 bga Modified code to use the PgArray class for PostgreSQL | + # arrays. | # 21APR2002 gh Added some more mean testcases, which test for control | # characters and other special characters inside strings, | *************** *** 43,46 **** --- 45,49 ---- import sys from pyPgSQL import PgSQL + PgArray = PgSQL.PgArray class ArrayTestCases(unittest.TestCase): *************** *** 50,58 **** def checkEqual(self, real, planned): ! self.failUnlessEqual(real, planned, \ "Received %s, should have been %s" % (repr(real), repr(planned))) def CheckForIntegerInsert(self): ! ivalues = [3,4,5] cursor = self.conn.cursor() try: --- 53,61 ---- def checkEqual(self, real, planned): ! self.failUnlessEqual(real.value, planned.value, \ "Received %s, should have been %s" % (repr(real), repr(planned))) def CheckForIntegerInsert(self): ! ivalues = PgArray([3,4,5]) cursor = self.conn.cursor() try: *************** *** 61,73 **** pass cursor.execute("create table test (ia int[])") ! cursor.execute("insert into test(ia) values (%s)", (ivalues,)) cursor.execute("select ia from test") result = cursor.fetchone() ! self.failUnlessEqual(type(result.ia), types.ListType, \ ! "the integer array isn't returned as a list") self.checkEqual(result.ia, ivalues) def CheckForNumericInsert(self): ! numlist = map(PgSQL.PgNumeric, ['4.7', '-3.2', '23.17']) cursor = self.conn.cursor() --- 64,76 ---- pass cursor.execute("create table test (ia int[])") ! cursor.execute("insert into test(ia) values (%s)", ivalues) cursor.execute("select ia from test") result = cursor.fetchone() ! self.failUnless(isinstance(result.ia, PgArray), \ ! "the integer array isn't returned as a PgArray") self.checkEqual(result.ia, ivalues) def CheckForNumericInsert(self): ! numlist = PgArray(map(PgSQL.PgNumeric, ['4.7', '-3.2', '23.17'])) cursor = self.conn.cursor() *************** *** 77,85 **** pass cursor.execute("create table test(na numeric[])") ! cursor.execute("insert into test(na) values (%s)", (numlist,)) cursor.execute("select na from test") result = cursor.fetchone() ! self.failUnlessEqual(type(result.na), types.ListType, \ ! "the numeric array isn't returned as a list") self.checkEqual(result.na, numlist) --- 80,88 ---- pass cursor.execute("create table test(na numeric[])") ! cursor.execute("insert into test(na) values (%s)", numlist) cursor.execute("select na from test") result = cursor.fetchone() ! self.failUnless(isinstance(result.na, PgArray), \ ! "the numeric array isn't returned as a PgArray") self.checkEqual(result.na, numlist) *************** *** 87,98 **** cursor = self.conn.cursor() ! stringlists = [['hey', 'you', 'there'], ! ['fancy', ',', '{chars}', '"'], ! ['what about', 'some \\backslashes'], ! ['some more \\', '\\ and \\ etc'], ! ['aa', '%s\n%s' % (chr(10), chr(29))], ! ['what about backslashes', 'at the end\\'], ! ['interesting', '"', '\\"', '\\"\\'], ! ['{}\\', '"\\}}\\\'"']] for stringlist in stringlists: --- 90,101 ---- cursor = self.conn.cursor() ! stringlists = PgArray([['hey', 'you', 'there'], ! ['fancy', ',', '{chars}', '"'], ! ['what about', 'some \\backslashes'], ! ['some more \\', '\\ and \\ etc'], ! ['aa', '%s\n%s' % (chr(10), chr(29))], ! ['what about backslashes', 'at the end\\'], ! ['interesting', '"', '\\"', '\\"\\'], ! ['{}\\', '"\\}}\\\'"']]) for stringlist in stringlists: *************** *** 102,110 **** 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") self.checkEqual(result.va, stringlist) --- 105,113 ---- 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.failUnless(isinstance(result.va, PgArray), \ ! "the varchar array isn't returned as a PgArray") self.checkEqual(result.va, stringlist) *************** *** 123,131 **** 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]) --- 126,134 ---- for j in chars: for k in chars: ! cursor.execute("insert into test(va) values (%s)", PgArray([i+j+k])) cursor.execute("select va from test where oid=%s", cursor.oidValue) result = cursor.fetchone() ! self.failUnless(isinstance(result.va, PgArray), \ ! "the varchar array isn't returned as a PgArray") self.checkEqual(result.va, [i+j+k]) *************** *** 133,140 **** 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: --- 136,145 ---- cursor = self.conn.cursor() ! stringlists = PgArray([[["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: *************** *** 144,152 **** 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[:] --- 149,157 ---- 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.failUnless(isinstance(result.va, PgArray), \ ! "the varchar array isn't returned as a PgArray") expected = stringlist[:] *************** *** 162,170 **** 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): --- 167,175 ---- cursor = self.conn.cursor() ! intlists = PgArray([[[1,2], [3,4]], ! [[-5,3,4], [2, None, 10]]]) ! excpected_intlists = PgArray([[[1,2], [3,4]], ! [[-5,3,4], [2, 0, 10]]]) for intlist, expected in zip(intlists, excpected_intlists): *************** *** 174,182 **** 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) --- 179,187 ---- 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.failUnless(isinstance(result.ia, PgArray), \ ! "the int array isn't returned as a PgArray") self.checkEqual(result.ia, expected) |