Skip to content

Commit

Permalink
Tested okay with Python 3.0, includes last minute patches from Mark H.
Browse files Browse the repository at this point in the history
  • Loading branch information
vernondcole committed Feb 6, 2009
1 parent 8d492a4 commit 7c98664
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
5 changes: 3 additions & 2 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def DateObjectFromCOMDate(self,comDate):
fcomDate = float(comDate)
secondsperday=86400 # 24*60*60
#ComDate is number of days since 1899-12-31, gmtime epoch is 1970-1-1 = 25569 days
t=time.gmtime(secondsperday*(fcomDate-25569.0))
t=time.localtime(secondsperday*(fcomDate-25569.0))
return t #year,month,day,hour,minute,second,weekday,julianday,daylightsaving=t

def Date(self,year,month,day):
Expand Down Expand Up @@ -724,7 +724,8 @@ def _executeHelper(self,operation,isStoredProcedureCall,parameters=None):
if parmIndx >= 0:
tbk += u'-- Trying parameter %d = %s\n' \
%(parmIndx, repr(parameters[parmIndx]))
tblist=traceback.format_exception(sys.exc_type,sys.exc_value,sys.exc_traceback,8)
exc_type,exc_value,exc_traceback = sys.exc_info()
tblist=traceback.format_exception(exc_type,exc_value,exc_traceback,8)
tb=''.join(tblist)
tracebackhistory = tbk + tb + u'-- on command: "%s"\n-- with parameters: %s' \
%(operation,parameters)
Expand Down
8 changes: 5 additions & 3 deletions adodbapi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ or:
............
Whats new in version 2.2.6
1. Actually works in Python 3.0 (using pywin32 212.6) after running thru 2to3
2. (Produces an error in dbapi20 test when trying adodbapi.Buffer('This is a string') in Python 3.0)
3. When a value with an exact midnight time is retrieved from a DATETIME column, return a datetime.datetime,
not a datetime.date.
2. RESTRICTION: Python Time (as opposed to datetime.datetime, which is the default) may return
incorrect results. We believe this happens when used with Southern Hemisphere time zones.
To avoid this problem, do not use adodbapi.pythonTimeConverter.
3. Several improvements in the test routines, including alteration of dbapi20 for Python 3.0 compatibility.
(Some requirements of PEP249 are incompatible with Python 3.0)

Whats new in version 2.2.5
1. Exception definition cleanups for for Python 3.0 readiness [Mark Hammond]
Expand Down
23 changes: 5 additions & 18 deletions adodbapi/tests/RunTests.bat
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
if not "%PYTHON%"=="" goto skip_python
set PYTHON=python
:skip_python
Echo on
echo .
echo .
del *.pyc
echo .
REM unit test
adodbapitest.py
%PYTHON% adodbapitest.py
echo .
echo .
REM generic test
@echo .
test_adodbapi_dbapi20.py
%PYTHON% test_adodbapi_dbapi20.py
echo .
echo .
db_print.py
echo .
del *.pyc
del *.pyo
del ..\adodbapi.pyc
echo .
call ipy.bat adodbapitest.py
echo .
echo .
REM generic test
@echo .
call ipy.bat test_adodbapi_dbapi20.py
echo .
call ipy.bat db_print.py
echo .
pause Testing complete
10 changes: 7 additions & 3 deletions adodbapi/tests/adodbapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
except ImportError:
import win32com.decimal_23 as decimal

def str2bytes(sval):
if sys.version_info < (3,0) and isinstance(sval, str):
sval = sval.decode("latin1")
return sval.encode("latin1")

class CommonDBTests(unittest.TestCase):
"Self contained super-simple tests in easy syntax, should work on everything between mySQL and Oracle"

Expand Down Expand Up @@ -248,7 +253,7 @@ def testDataTypeInt(self):
pyDataInputAlternatives='2137483647')
if self.getEngine() != 'ACCESS':
self.helpTestDataType("bit",'NUMBER',1) #Does not work correctly with access
self.helpTestDataType("bigint",'NUMBER',3000000000L)
self.helpTestDataType("bigint",'NUMBER',3000000000)

def testDataTypeChar(self):
for sqlDataType in ("char(6)","nchar(6)"):
Expand All @@ -274,8 +279,7 @@ def testDataTypeBinary(self):
if self.getEngine() == 'MySQL':
pass #self.helpTestDataType("BLOB",'BINARY',adodbapi.Binary('\x00\x01\xE2\x40'))
else:
# python 3.0 syntax -> binfld = b'\x00\x01\xE2\x40'
binfld = '\x00\x01\xE2\x40'
binfld = str2bytes('\x00\x01\xE2\x40')
self.helpTestDataType("binary(4)",'BINARY',adodbapi.Binary(binfld))
self.helpTestDataType("varbinary(100)",'BINARY',adodbapi.Binary(binfld))
self.helpTestDataType("image",'BINARY',adodbapi.Binary(binfld))
Expand Down
12 changes: 9 additions & 3 deletions adodbapi/tests/dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
-- Ian Bicking
'''

__rcs_id__ = '$Id$'
__version__ = '$Revision$'[11:-2]
__author__ = 'Stuart Bishop <zen@shangri-la.dropbear.id.au>'

import unittest
import time
import sys

# Revision 3.0 2009/2/4 kf7xm
# Updates to make Python 3.0 compatible
#
# $Log$
# Revision 1.1.1.1.2.1 2008/09/20 19:54:59 rupole
# Include latest changes from main branch
Expand Down Expand Up @@ -69,6 +71,10 @@
# nothing
# - Fix bugs in test_setoutputsize_basic and test_setinputsizes
#
def str2bytes(sval):
if sys.version_info < (3,0) and isinstance(sval, str):
sval = sval.decode("latin1")
return sval.encode("latin1")

class DatabaseAPI20Test(unittest.TestCase):
''' Test a database self.driver for DB API 2.0 compatibility.
Expand Down Expand Up @@ -832,8 +838,8 @@ def test_Timestamp(self):
# self.assertEqual(str(t1),str(t2))

def test_Binary(self):
b = self.driver.Binary('Something')
b = self.driver.Binary('')
b = self.driver.Binary(str2bytes('Something'))
b = self.driver.Binary(str2bytes(''))

def test_STRING(self):
self.failUnless(hasattr(self.driver,'STRING'),
Expand Down
4 changes: 2 additions & 2 deletions adodbapi/tests/test_adodbapi_dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import dbapi20
import unittest
import os, sys, string
import os, sys

#attempt to find adodbapi in this directory's parent
cwd = os.getcwd()
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(self,arg):
dbapi20.DatabaseAPI20Test.__init__(self,arg)

def testMethodName(self):
return string.split(self.id(),'.')[-1]
return self.id().split('.')[-1]

def setUp(self):
# Call superclass setUp In case this does something in the
Expand Down

0 comments on commit 7c98664

Please sign in to comment.