[DB-SIG] DB-API unittests

M.-A. Lemburg mal at egenix.com
Thu Dec 1 11:07:07 CET 2005


Andrew Chambers wrote:
> Hi All,
> 
> I've been doing some work on some unittests for the Python DB-API.

I wonder whether you are aware of the existing test suite
for DB-API 2.0 by Stuart Bishop:

http://stuartbishop.net/Software/DBAPI20TestSuite/

In particular, it tests psycopg.

> So far, I've created tests for...
> 
>    - Attempt to connect using invalid dbname should raise Error
>    - Attempt to divide by zero should raise DataError
>    - Attempt to violate foreign/primery key should raise IntegrityError
>    - Attempt to create identical tables should raise ProgrammingError
>    - Connection object should have minimum set of methods
>    - Cursor object should have minimum set of methods
>    - Simple select query should result in expected description/rowcount
>    - Type_codes in description attr should evaluate to corresponding
>      Singletons.
> 
> It only works for postgresql drivers since it connects to template1
> which should be present on most postgresql databases 
> 
> It raises a few points (these may have been discussed here before but
> googling the archives didn't reveal them.
> 
> - Evidently there is ambiguity about the way that dates should be entered.
>   pgdb - curs.execute("select '%s'" % Date(2005, 01, 01))
>   psycopg - curs.execute("select %s" % Date(2005, 01, 01))
>   Don't know about the others - I don't have them installed

psycopg is doing the right thing here - whatever Date() returns
should be directly usable with the %s parameter marker.

> - Exceptions.  My interpretation of the API seems to deviate from that
>   of psycopg and pgdb.  Does anyone have any views on which is correct?
>   I wrote the tests without having any existing implementation in mind 
>   just going from the spec.  Are the tests at fault?

Hard to tell... what are your views ?

> I'd also be interested in what else you think should be tested.  I've
> started to write some performance tests that simply query the pg_type
> table for a fixed time period (30 secs).  These need more work though.
> I'll post if anyone asks.
> 
> Finally, I couldn't think of a way to run these tests across a number of
> modules without duplicating the code (although to be honest I haven't
> given it much thought yet.  If anyone has any ideas I'd be interested to 
> hear those too.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Dec 01 2005)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the DB-SIG mailing list