From: Gerhard H?r. <gha...@us...> - 2002-04-17 00:18:27
|
Update of /cvsroot/pypgsql/pypgsql/test/regression In directory usw-pr-cvs1:/tmp/cvs-serv8720/test/regression Added Files: array.py Log Message: 17APR2002 gh Testcases for the array handling that demonstrate the current bugs on PostgreSQL 7.1 and 7.2. 7.2 is slightly better, but the un-escaping of libpq results will certainly still have to be much improved. --- NEW FILE: array.py --- #!/usr/local/bin/python #ident "@(#) $Id: array.py,v 1.1 2002/04/17 00:18:22 ghaering Exp $" # vi:set sw=4 ts=8 showmode ai: #-----------------------------------------------------------------------+ # Name: array.py | # | # Description: array.py contains test cases for using the PostgreSQL | # array type from within the PgSQL module. | # | # Note: These test cases requires that a test database named | # pypgsql exists and that the person running the test has | # full rights to the database. | #=======================================================================| # Copyright 2002 by Gerhard Häring. | # All rights reserved. | # | # Permission to use, copy, modify, and distribute this software and its | # documentation for any purpose and without fee is hereby granted, pro- | # vided that the above copyright notice appear in all copies and that | # both that copyright notice and this permission notice appear in sup- | # porting documentation, and that the copyright owner's name not be | # used in advertising or publicity pertaining to distribution of the | # software without specific, written prior permission. | # | # THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | # NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR | # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE | # USE OR PERFORMANCE OF THIS SOFTWARE. | #=======================================================================| # Revision History: | # | # Date Ini Description | # --------- --- ------------------------------------------------------- | # 16APR2002 gh Initial release by Gerhard Häring. | #-----------------------------------------------------------------------+ import unittest, types import sys from pyPgSQL import PgSQL class ArrayTestCases(unittest.TestCase): def setUp(self): self.conn = PgSQL.connect(database="pypgsql") 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() 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) self.conn.rollback() def CheckForNumericInsert(self): numlist = map(PgSQL.PgNumeric, ['4.7', '-3.2', '23.17']) cursor = self.conn.cursor() 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) self.conn.rollback() def CheckForStringInsert(self): #self.conn.conn.toggleShowQuery 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: 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) self.conn.rollback() if __name__ == "__main__": TestSuite = unittest.TestSuite() TestSuite.addTest(ArrayTestCases("CheckForIntegerInsert")) TestSuite.addTest(ArrayTestCases("CheckForNumericInsert")) TestSuite.addTest(ArrayTestCases("CheckForStringInsert")) runner = unittest.TextTestRunner() runner.run(TestSuite) |