Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv21972

Modified Files:
        dbapi20.py pgdb.py 
Log Message:
Updated the dbapi20 test module. Exposed the exceptions as attributes of the 
connection.
To see the diffs for this commit:
   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/dbapi20.py.diff?r1=1.3&r2=1.4

Index: dbapi20.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/dbapi20.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- dbapi20.py  16 Sep 2008 14:35:21 -0000      1.3
+++ dbapi20.py  1 Nov 2008 18:37:55 -0000       1.4
@@ -11,22 +11,23 @@
     -- Ian Bicking
 '''
 
-__rcs_id__  = '$Id: dbapi20.py,v 1.3 2008/09/16 14:35:21 cito Exp $'
-__version__ = '$Revision: 1.3 $'[11:-2]
+__rcs_id__  = '$Id: dbapi20.py,v 1.4 2008/11/01 18:37:55 cito Exp $'
+__version__ = '$Revision: 1.4 $'[11:-2]
 __author__ = 'Stuart Bishop <[EMAIL PROTECTED]>'
 
 import unittest
 import time
 
 # $Log: dbapi20.py,v $
-# Revision 1.3  2008/09/16 14:35:21  cito
-# Removed spurious tab.
+# Revision 1.4  2008/11/01 18:37:55  cito
+# Updated the dbapi20 test module. Exposed the exceptions as attributes of the 
connection.
 #
-# Revision 1.2  2006/01/22 13:16:48  darcy
-# Make error message a little more explanatory.
+# Revision 1.10  2003/10/09 03:14:14  zenzen
+# Add test for DB API 2.0 optional extension, where database exceptions
+# are exposed as attributes on the Connection object.
 #
-# Revision 1.1  2006/01/19 11:31:25  darcy
-# Add dbapi20 module for testing.
+# Revision 1.9  2003/08/13 01:16:36  zenzen
+# Minor tweak from Stefan Fleiter
 #
 # Revision 1.8  2003/04/10 00:13:25  zenzen
 # Changes, as per suggestions by M.-A. Lemburg
@@ -115,7 +116,7 @@
 
     def tearDown(self):
         ''' self.drivers should override this method to perform required 
cleanup
-            if any is necessary, such as deleting the dest database.
+            if any is necessary, such as deleting the test database.
             The default drops the tables that may be created.
         '''
         con = self._connect()
@@ -200,6 +201,26 @@
             issubclass(self.driver.NotSupportedError,self.driver.Error)
             )
 
+    def test_ExceptionsAsConnectionAttributes(self):
+        # OPTIONAL EXTENSION
+        # Test for the optional DB API 2.0 extension, where the exceptions
+        # are exposed as attributes on the Connection object
+        # I figure this optional extension will be implemented by any
+        # driver author who is using this test suite, so it is enabled
+        # by default.
+        con = self._connect()
+        drv = self.driver
+        self.failUnless(con.Warning is drv.Warning)
+        self.failUnless(con.Error is drv.Error)
+        self.failUnless(con.InterfaceError is drv.InterfaceError)
+        self.failUnless(con.DatabaseError is drv.DatabaseError)
+        self.failUnless(con.OperationalError is drv.OperationalError)
+        self.failUnless(con.IntegrityError is drv.IntegrityError)
+        self.failUnless(con.InternalError is drv.InternalError)
+        self.failUnless(con.ProgrammingError is drv.ProgrammingError)
+        self.failUnless(con.NotSupportedError is drv.NotSupportedError)
+
+
     def test_commit(self):
         con = self._connect()
         try:
@@ -283,8 +304,8 @@
             cur = con.cursor()
             self.executeDDL1(cur)
             self.assertEqual(cur.rowcount,-1,
-                'cursor.rowcount should be -1, not %r '
-                'after executing no-result statements' % cur.rowcount
+                'cursor.rowcount should be -1 after executing no-result '
+                'statements'
                 )
             cur.execute("insert into %sbooze values ('Victoria Bitter')" % (
                 self.table_prefix
@@ -531,7 +552,6 @@
 
             cur.execute('select name from %sbooze' % self.table_prefix)
             r = cur.fetchmany()
-            import sys
             self.assertEqual(len(r),1,
                 'cursor.fetchmany retrieved incorrect number of rows, '
                 'default of arraysize is one.'
@@ -684,7 +704,7 @@
     def help_nextset_setUp(self,cur):
         ''' Should create a procedure called deleteme
             that returns two result sets, first the
-            number of rows in booze then "name from booze"
+           number of rows in booze then "name from booze"
         '''
         raise NotImplementedError,'Helper not implemented'
         #sql="""
@@ -790,7 +810,7 @@
 
     def test_Time(self):
         t1 = self.driver.Time(13,45,30)
-        t2 = self.driver.TimeFromTicks(time.mktime((0,0,0,13,45,30,0,0,0)))
+        t2 = self.driver.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
         # Can we assume this? API doesn't specify, but it seems implied
         # self.assertEqual(str(t1),str(t2))
 

   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pgdb.py.diff?r1=1.44&r2=1.45

Index: pgdb.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pgdb.py,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- pgdb.py     1 Nov 2008 18:21:12 -0000       1.44
+++ pgdb.py     1 Nov 2008 18:37:55 -0000       1.45
@@ -4,7 +4,7 @@
 #
 # Written by D'Arcy J.M. Cain
 #
-# $Id: pgdb.py,v 1.44 2008/11/01 18:21:12 cito Exp $
+# $Id: pgdb.py,v 1.45 2008/11/01 18:37:55 cito Exp $
 #
 
 """pgdb - DB-API 2.0 compliant module for PygreSQL.
@@ -347,6 +347,17 @@
 class pgdbCnx(object):
     """Connection Object."""
 
+    # expose the exceptions as attributes on the connection object
+    Warning = Warning
+    Error = Error
+    InterfaceError = InterfaceError
+    DatabaseError = DatabaseError
+    OperationalError = OperationalError
+    IntegrityError = IntegrityError
+    InternalError = InternalError
+    ProgrammingError = ProgrammingError
+    NotSupportedError = NotSupportedError
+
     def __init__(self, cnx):
         """Create a database connection object."""
         self._cnx = cnx # connection

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to