From: Billy G. A. <bal...@us...> - 2001-09-07 00:19:29
|
Update of /cvsroot/pypgsql/pypgsql/test/regression In directory usw-pr-cvs1:/tmp/cvs-serv13423 Modified Files: pgresult.py Log Message: 06SEP2001 bga Finished the test cases for PgResult's members. Just have to do test cases for PgResult's methods. Index: pgresult.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/test/regression/pgresult.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pgresult.py 2001/09/05 04:53:01 1.2 --- pgresult.py 2001/09/07 00:19:26 1.3 *************** *** 34,37 **** --- 34,39 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 06SEP2001 bga Completed the PgResult Member test cases, just have to | + # do the PgResult Method test cases. | # 04SEP2001 bga Expanded the test cases. Still more to do. | # 02SEP2001 bga Initial release by Billy G. Allie. | *************** *** 46,66 **** version = ((((version[0] * 100) + version[1]) * 100) + version[2]) ! class PgResultMethodTestCases(unittest.TestCase): def setUp(self): ! self.cnx = libpq.PQconnectdb('dbname=pypgsql') ! self.vstr = "%(major)d.%(minor)d" % self.cnx.version.__dict__ self.members = ['binaryTuples', 'cmdStatus', 'cmdTuples', 'nfields', ! 'ntuples', 'oidValue', 'resultErrorMessage', 'resultStatus', 'resultType'] self.methods = ['clear', 'fname', 'fnumber', 'fsize', 'ftype', 'getisnull', 'getlength', 'getvalue'] - - def tearDown(self): - try: - self.cnx.finish() - except AttributeError: - pass - except libpq.InterfaceError: - pass def CheckForMembers(self, res): --- 48,68 ---- version = ((((version[0] * 100) + version[1]) * 100) + version[2]) ! # Get a connection and a version string to be used globally. ! cnx = libpq.PQconnectdb("dbname=pypgsql") ! vstr = "%(major)d.%(minor)d" % cnx.version.__dict__ ! ! class PgResultMemberTestCases(unittest.TestCase): ! def setUp(self): ! global cnx ! global vstr ! ! self.cnx = cnx ! self.vstr = vstr self.members = ['binaryTuples', 'cmdStatus', 'cmdTuples', 'nfields', ! 'ntuples', 'oidValue', 'resultErrorMessage', 'resultStatus', 'resultType'] self.methods = ['clear', 'fname', 'fnumber', 'fsize', 'ftype', 'getisnull', 'getlength', 'getvalue'] def CheckForMembers(self, res): *************** *** 85,89 **** def CheckDropPgResult(self): ! query = "drop table pgresult_test" res = self.cnx.query(query) self.CheckForMembers(res) --- 87,91 ---- def CheckDropPgResult(self): ! query = "DROP TABLE pgresult_test" res = self.cnx.query(query) self.CheckForMembers(res) *************** *** 94,181 **** self.failUnlessRaises(libpq.OperationalError, self.cnx.query, query) ! # def CheckDeclareBinaryPgResult(self): ! # res = self.cnx.query("""declare pgres_bin_cursor cursor as ! # select * from pgresult_test"""); ! # self.CheckForMembers(res) ! # self.CheckForMethods(res) ! # self.assertEquals(res.binaryTuples, 0, ! # "PgResult.binaryTuples is %d, should be 0." % res.binaryTuples) ! # self.assertEquals(res.cmdStatus, 'SELECT', ! # "PgResult.cmdStatus is '%s', should be 'SELECT'." % res.cmdStatus) ! # self.assertEquals(res.cmdTuples, None, ! # "PgResult.cmdTuples is %s, should be None." % res.cmdTuples) ! # self.assertEquals(res.ntuples, 1, ! # "PgResult.ntuples is %d, should be 1." % res.ntuples) ! # self.assertEquals(res.nfields, 7, ! # "PgResult.nfields is %d, should be 1." % res.nfields) ! # self.assertEquals(res.resultErrorMessage, None, ! # "PgResult.resultErrorMessage is '%s', should be None." % \ ! # res.resultErrorMessage) ! # ! # def CheckFetchBinaryPgResult(self): ! # res = self.cnx.query("fetch 1 from pgres_bin_cursor"); ! # self.CheckForMembers(res) ! # self.CheckForMethods(res) ! # expected = [0, 'SELECT', None, 1, 7, None, 2, 1 ] ! # ! # def CheckDeclarePgResult(self): ! # res = self.cnx.query("""declare pgres_curosr cursor as ! # select * from pgresult_test"""); ! # self.CheckForMembers(res) ! # self.CheckForMethods(res) ! # self.assertEquals(res.binaryTuples, 0, ! # "PgResult.binaryTuples is %d, should be 0." % res.binaryTuples) ! # self.assertEquals(res.cmdStatus, 'SELECT', ! # "PgResult.cmdStatus is '%s', should be 'SELECT'." % res.cmdStatus) ! # self.assertEquals(res.cmdTuples, None, ! # "PgResult.cmdTuples is %s, should be None." % res.cmdTuples) ! # self.assertEquals(res.ntuples, 1, ! # "PgResult.ntuples is %d, should be 1." % res.ntuples) ! # self.assertEquals(res.nfields, 7, ! # "PgResult.nfields is %d, should be 1." % res.nfields) ! # self.assertEquals(res.resultErrorMessage, None, ! # "PgResult.resultErrorMessage is '%s', should be None." % \ ! # res.resultErrorMessage) ! # ! # def CheckFetchPgResult(self): ! # res = self.cnx.query("""select * from pg_database ! # where datname = 'pypgsql'"""); ! # self.CheckForMembers(res) ! # self.CheckForMethods(res) ! # self.assertEquals(res.binaryTuples, 0, ! # "PgResult.binaryTuples is %d, should be 0." % res.binaryTuples) ! # self.assertEquals(res.cmdStatus, 'SELECT', ! # "PgResult.cmdStatus is '%s', should be 'SELECT'." % res.cmdStatus) ! # self.assertEquals(res.cmdTuples, None, ! # "PgResult.cmdTuples is %s, should be None." % res.cmdTuples) ! # self.assertEquals(res.ntuples, 1, ! # "PgResult.ntuples is %d, should be 1." % res.ntuples) ! # self.assertEquals(res.nfields, 7, ! # "PgResult.nfields is %d, should be 1." % res.nfields) ! # self.assertEquals(res.resultErrorMessage, None, ! # "PgResult.resultErrorMessage is '%s', should be None." % \ ! # res.resultErrorMessage) ! # ! # def CheckUpdatePgResult(self): ! # res = self.cnx.query("select * from pgresult_test") ! # self.CheckForMembers(res) ! # self.CheckForMethods(res) ! # self.assertEquals(res.binaryTuples, 0, ! # "PgResult.binaryTuples is %d, should be 0." % res.binaryTuples) ! # self.assertEquals(res.cmdStatus, 'SELECT', ! # "PgResult.cmdStatus is '%s', should be 'SELECT'." % res.cmdStatus) ! # self.assertEquals(res.cmdTuples, None, ! # "PgResult.cmdTuples is %s, should be None." % res.cmdTuples) ! # self.assertEquals(res.ntuples, 1, ! # "PgResult.ntuples is %d, should be 1." % res.ntuples) ! # self.assertEquals(res.nfields, 7, ! # "PgResult.nfields is %d, should be 1." % res.nfields) ! # self.assertEquals(res.resultErrorMessage, None, ! # "PgResult.resultErrorMessage is '%s', should be None." % \ ! # res.resultErrorMessage) ! # def CheckInsertPgResult(self): ! res = self.cnx.query("""insert into pgresult_test ! values (1, 'This is a test (1)')"""); self.CheckForMembers(res) self.CheckForMethods(res) --- 96,201 ---- self.failUnlessRaises(libpq.OperationalError, self.cnx.query, query) ! def CheckEndPgResult(self): ! res = self.cnx.query("END WORK") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'COMMIT', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckCloseBinaryPgResult(self): ! res = self.cnx.query("CLOSE pgres_cursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'CLOSE', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckNoticePgResult(self): ! # The following query will cause a notice to be generated, but not ! # an error. ! res = self.cnx.query("FETCH FROM pgres_cursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'FETCH', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! self.assertEquals(len(self.cnx.notices), 1, ! "A notice should of been generated, none was!") ! n = self.cnx.notices.pop() ! e = 'NOTICE: PerformPortalFetch: portal "pgres_cursor" not found\n' ! self.assertEquals(n, e, "The notice did not match expected results"); ! ! def CheckClosePgResult(self): ! res = self.cnx.query("CLOSE pgres_cursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'CLOSE', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckFetchBinaryPgResult(self): ! res = self.cnx.query("FETCH 3 FROM pgres_bcursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [1, 'FETCH', None, 2, 3, None, None, 2, 1 ] ! self.CheckMemberValues(res, expected) ! ! def CheckDeclareBinaryPgResult(self): ! res = self.cnx.query("""DECLARE pgres_bcursor BINARY CURSOR FOR ! SELECT * FROM pgresult_test""") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'SELECT', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckMovePgResult(self): ! res = self.cnx.query("MOVE BACKWARD ALL IN pgres_cursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'MOVE', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! res = self.cnx.query("FETCH ALL FROM pgres_cursor") ! expected = [0, 'FETCH', None, 2, 4, None, None, 2, 1 ] ! self.CheckMemberValues(res, expected) ! ! def CheckFetchPgResult(self): ! res = self.cnx.query("FETCH 2 FROM pgres_cursor") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'FETCH', None, 2, 2, None, None, 2, 1 ] ! self.CheckMemberValues(res, expected) ! ! def CheckDeclarePgResult(self): ! res = self.cnx.query("""DECLARE pgres_cursor CURSOR FOR ! SELECT * FROM pgresult_test""") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'SELECT', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckBeginPgResult(self): ! res = self.cnx.query("BEGIN WORK") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'BEGIN', None, 0, 0, None, None, 1, 2 ] ! self.CheckMemberValues(res, expected) ! ! def CheckSelectPgResult(self): ! res = self.cnx.query("SELECT * FROM pgresult_test") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! expected = [0, 'SELECT', None, 2, 4, None, None, 2, 1 ] ! self.CheckMemberValues(res, expected) ! ! def CheckUpdatePgResult(self): ! res = self.cnx.query("""UPDATE pgresult_test ! SET f2 = 'This is a test (3u)' ! WHERE f1 = 3""") ! self.CheckForMembers(res) ! self.CheckForMethods(res) ! cs = 'UPDATE %s' % res.cmdTuples ! expected = [0, cs, 1, 0, 0, None, None, 1, 3 ] ! self.CheckMemberValues(res, expected) ! def CheckInsertPgResult(self): ! res = self.cnx.query("""INSERT INTO pgresult_test ! VALUES (1, 'This is a test (1)')""") self.CheckForMembers(res) self.CheckForMethods(res) *************** *** 187,199 **** "PgResult.oidValue is None, it shouldn't be None.") self.CheckMemberValues(res, expected) ! res = self.cnx.query("""insert into pgresult_test ! values (2, 'This is a test (2)')"""); ! res = self.cnx.query("""insert into pgresult_test ! values (3, 'This is a test (3)')"""); ! res = self.cnx.query("""insert into pgresult_test ! values (4, 'This is a test (4)')"""); def CheckCreatePgResult(self): ! query = "create table pgresult_test(f1 int, f2 text)" res = self.cnx.query(query) self.CheckForMembers(res) --- 207,219 ---- "PgResult.oidValue is None, it shouldn't be None.") self.CheckMemberValues(res, expected) ! res = self.cnx.query("""INSERT INTO pgresult_test ! VALUES (2, 'This is a test (2)')""") ! res = self.cnx.query("""INSERT INTO pgresult_test ! VALUES (3, 'This is a test (3)')""") ! res = self.cnx.query("""INSERT INTO pgresult_test ! VALUES (4, 'This is a test (4)')""") def CheckCreatePgResult(self): ! query = "CREATE TABLE pgresult_test(f1 INT, f2 TEXT)" res = self.cnx.query(query) self.CheckForMembers(res) *************** *** 205,209 **** def CheckPgResult(self): ! res = self.cnx.query("select * from pg_database limit 3") self.CheckForMembers(res) self.CheckForMethods(res) --- 225,229 ---- def CheckPgResult(self): ! res = self.cnx.query("SELECT * FROM pg_database LIMIT 3") self.CheckForMembers(res) self.CheckForMethods(res) *************** *** 242,253 **** if __name__ == "__main__": TestSuite = unittest.TestSuite() ! TestSuite.addTest(PgResultMethodTestCases("CheckPgResult")) ! TestSuite.addTest(PgResultMethodTestCases("CheckCreatePgResult")) ! TestSuite.addTest(PgResultMethodTestCases("CheckInsertPgResult")) ! #TestSuite.addTest(PgResultMethodTestCases("CheckSelectPgResult")) ! #TestSuite.addTest(PgResultMethodTestCases("CheckUpdatePgResult")) ! #TestSuite.addTest(PgResultMethodTestCases("CheckDeclarePgResult")) ! #TestSuite.addTest(PgResultMethodTestCases("CheckFetchPgResult")) ! TestSuite.addTest(PgResultMethodTestCases("CheckDropPgResult")) TestSuite.addTest(PgResultTestCases("CheckSelectOfNonPrintableString")) --- 262,282 ---- if __name__ == "__main__": TestSuite = unittest.TestSuite() ! TestSuite.addTest(PgResultMemberTestCases("CheckPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckCreatePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckInsertPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckUpdatePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckSelectPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckBeginPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckDeclarePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckFetchPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckMovePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckDeclareBinaryPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckFetchBinaryPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckClosePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckNoticePgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckCloseBinaryPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckEndPgResult")) ! TestSuite.addTest(PgResultMemberTestCases("CheckDropPgResult")) ! TestSuite.addTest(PgResultTestCases("CheckSelectOfNonPrintableString")) |