Changeset 347


Ignore:
Timestamp:
Nov 1, 2008, 2:37:55 PM (11 years ago)
Author:
cito
Message:

Updated the dbapi20 test module. Exposed the exceptions as attributes of the connection.

Location:
trunk/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/dbapi20.py

    r325 r347  
    1212'''
    1313
    14 __rcs_id__  = '$Id: dbapi20.py,v 1.3 2008-09-16 14:35:21 cito Exp $'
    15 __version__ = '$Revision: 1.3 $'[11:-2]
     14__rcs_id__  = '$Id: dbapi20.py,v 1.4 2008-11-01 18:37:55 cito Exp $'
     15__version__ = '$Revision: 1.4 $'[11:-2]
    1616__author__ = 'Stuart Bishop <zen@shangri-la.dropbear.id.au>'
    1717
     
    2020
    2121# $Log: not supported by cvs2svn $
    22 # Revision 1.2  2006/01/22 13:16:48  darcy
    23 # Make error message a little more explanatory.
     22# Revision 1.10  2003/10/09 03:14:14  zenzen
     23# Add test for DB API 2.0 optional extension, where database exceptions
     24# are exposed as attributes on the Connection object.
    2425#
    25 # Revision 1.1  2006/01/19 11:31:25  darcy
    26 # Add dbapi20 module for testing.
     26# Revision 1.9  2003/08/13 01:16:36  zenzen
     27# Minor tweak from Stefan Fleiter
    2728#
    2829# Revision 1.8  2003/04/10 00:13:25  zenzen
     
    113114    def tearDown(self):
    114115        ''' self.drivers should override this method to perform required cleanup
    115             if any is necessary, such as deleting the dest database.
     116            if any is necessary, such as deleting the test database.
    116117            The default drops the tables that may be created.
    117118        '''
     
    197198            issubclass(self.driver.NotSupportedError,self.driver.Error)
    198199            )
     200
     201    def test_ExceptionsAsConnectionAttributes(self):
     202        # OPTIONAL EXTENSION
     203        # Test for the optional DB API 2.0 extension, where the exceptions
     204        # are exposed as attributes on the Connection object
     205        # I figure this optional extension will be implemented by any
     206        # driver author who is using this test suite, so it is enabled
     207        # by default.
     208        con = self._connect()
     209        drv = self.driver
     210        self.failUnless(con.Warning is drv.Warning)
     211        self.failUnless(con.Error is drv.Error)
     212        self.failUnless(con.InterfaceError is drv.InterfaceError)
     213        self.failUnless(con.DatabaseError is drv.DatabaseError)
     214        self.failUnless(con.OperationalError is drv.OperationalError)
     215        self.failUnless(con.IntegrityError is drv.IntegrityError)
     216        self.failUnless(con.InternalError is drv.InternalError)
     217        self.failUnless(con.ProgrammingError is drv.ProgrammingError)
     218        self.failUnless(con.NotSupportedError is drv.NotSupportedError)
     219
    199220
    200221    def test_commit(self):
     
    281302            self.executeDDL1(cur)
    282303            self.assertEqual(cur.rowcount,-1,
    283                 'cursor.rowcount should be -1, not %r '
    284                 'after executing no-result statements' % cur.rowcount
     304                'cursor.rowcount should be -1 after executing no-result '
     305                'statements'
    285306                )
    286307            cur.execute("insert into %sbooze values ('Victoria Bitter')" % (
     
    529550            cur.execute('select name from %sbooze' % self.table_prefix)
    530551            r = cur.fetchmany()
    531             import sys
    532552            self.assertEqual(len(r),1,
    533553                'cursor.fetchmany retrieved incorrect number of rows, '
     
    682702        ''' Should create a procedure called deleteme
    683703            that returns two result sets, first the
    684             number of rows in booze then "name from booze"
     704            number of rows in booze then "name from booze"
    685705        '''
    686706        raise NotImplementedError,'Helper not implemented'
     
    788808    def test_Time(self):
    789809        t1 = self.driver.Time(13,45,30)
    790         t2 = self.driver.TimeFromTicks(time.mktime((0,0,0,13,45,30,0,0,0)))
     810        t2 = self.driver.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
    791811        # Can we assume this? API doesn't specify, but it seems implied
    792812        # self.assertEqual(str(t1),str(t2))
  • trunk/module/pgdb.py

    r346 r347  
    55# Written by D'Arcy J.M. Cain
    66#
    7 # $Id: pgdb.py,v 1.44 2008-11-01 18:21:12 cito Exp $
     7# $Id: pgdb.py,v 1.45 2008-11-01 18:37:55 cito Exp $
    88#
    99
     
    348348    """Connection Object."""
    349349
     350    # expose the exceptions as attributes on the connection object
     351    Warning = Warning
     352    Error = Error
     353    InterfaceError = InterfaceError
     354    DatabaseError = DatabaseError
     355    OperationalError = OperationalError
     356    IntegrityError = IntegrityError
     357    InternalError = InternalError
     358    ProgrammingError = ProgrammingError
     359    NotSupportedError = NotSupportedError
     360
    350361    def __init__(self, cnx):
    351362        """Create a database connection object."""
Note: See TracChangeset for help on using the changeset viewer.