Some (many) tests actually pass now on Python 3. May no longer be backwards-compatible with Python < 2.6.

This commit is contained in:
adustman
2012-09-08 20:24:45 +00:00
parent fe917fcced
commit 8041cc6df6
8 changed files with 24 additions and 20 deletions

View File

@ -77,7 +77,7 @@ def Binary(x):
def Connect(*args, **kwargs): def Connect(*args, **kwargs):
"""Factory function for connections.Connection.""" """Factory function for connections.Connection."""
from connections import Connection from MySQLdb.connections import Connection
return Connection(*args, **kwargs) return Connection(*args, **kwargs)
connect = Connection = Connect connect = Connection = Connect

View File

@ -6,7 +6,7 @@ want to make your own subclasses. In most cases, you will probably
override Connection.default_cursor with a non-standard Cursor class. override Connection.default_cursor with a non-standard Cursor class.
""" """
import cursors from MySQLdb import cursors
from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \ from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \
DatabaseError, OperationalError, IntegrityError, InternalError, \ DatabaseError, OperationalError, IntegrityError, InternalError, \
NotSupportedError, ProgrammingError NotSupportedError, ProgrammingError
@ -33,7 +33,7 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
connection.messages.append(error) connection.messages.append(error)
del cursor del cursor
del connection del connection
raise errorclass, errorvalue raise errorclass(errorvalue)
re_numeric_part = re.compile(r"^(\d+)") re_numeric_part = re.compile(r"^(\d+)")
@ -143,8 +143,8 @@ class Connection(_mysql.connection):
documentation for the MySQL C API for some hints on what they do. documentation for the MySQL C API for some hints on what they do.
""" """
from constants import CLIENT, FIELD_TYPE from MySQLdb.constants import CLIENT, FIELD_TYPE
from converters import conversions from MySQLdb.converters import conversions
from weakref import proxy, WeakValueDictionary from weakref import proxy, WeakValueDictionary
import types import types

View File

@ -33,8 +33,8 @@ MySQL.connect().
""" """
from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
from constants import FIELD_TYPE, FLAG from MySQLdb.constants import FIELD_TYPE, FLAG
from times import * from MySQLdb.times import *
import types import types
import array import array

View File

@ -7,8 +7,13 @@ default, MySQLdb uses the Cursor class.
import re import re
import sys import sys
from types import ListType, TupleType, UnicodeType try:
from types import ListType, TupleType, UnicodeType
except ImportError:
# Python 3
ListType = list
TupleType = tuple
UnicodeType = str
restr = (r"\svalues\s*" restr = (r"\svalues\s*"
r"(\(((?<!\\)'[^\)]*?\)[^\)]*(?<!\\)?'" r"(\(((?<!\\)'[^\)]*?\)[^\)]*(?<!\\)?'"
@ -161,7 +166,7 @@ class BaseCursor(object):
try: try:
r = None r = None
r = self._query(query) r = self._query(query)
except TypeError, m: except TypeError as m:
if m.args[0] in ("not enough arguments for format string", if m.args[0] in ("not enough arguments for format string",
"not all arguments converted"): "not all arguments converted"):
self.messages.append((ProgrammingError, m.args[0])) self.messages.append((ProgrammingError, m.args[0]))
@ -212,7 +217,7 @@ class BaseCursor(object):
qv = m.group(1) qv = m.group(1)
try: try:
q = [ qv % db.literal(a) for a in args ] q = [ qv % db.literal(a) for a in args ]
except TypeError, msg: except TypeError as msg:
if msg.args[0] in ("not enough arguments for format string", if msg.args[0] in ("not enough arguments for format string",
"not all arguments converted"): "not all arguments converted"):
self.errorhandler(self, ProgrammingError, msg.args[0]) self.errorhandler(self, ProgrammingError, msg.args[0])
@ -365,7 +370,7 @@ class CursorStoreResultMixIn(object):
r = value r = value
else: else:
self.errorhandler(self, ProgrammingError, self.errorhandler(self, ProgrammingError,
"unknown scroll mode %s" % `mode`) "unknown scroll mode %s" % repr(mode))
if r < 0 or r >= len(self._rows): if r < 0 or r >= len(self._rows):
self.errorhandler(self, IndexError, "out of range") self.errorhandler(self, IndexError, "out of range")
self.rownumber = r self.rownumber = r

View File

@ -2979,8 +2979,8 @@ init_mysql(void)
if (!module) return; /* this really should never happen */ if (!module) return; /* this really should never happen */
#endif #endif
#ifdef IS_PY3K #ifdef IS_PY3K
/* Py_TYPE(_mysql_ConnectionObject_Type) = &PyType_Type; Py_TYPE(&_mysql_ConnectionObject_Type) = &PyType_Type;
Py_TYPE(_mysql_ResultObject_Type) = &PyType_Type; */ Py_TYPE(&_mysql_ResultObject_Type) = &PyType_Type;
#else #else
_mysql_ConnectionObject_Type.ob_type = &PyType_Type; _mysql_ConnectionObject_Type.ob_type = &PyType_Type;
_mysql_ResultObject_Type.ob_type = &PyType_Type; _mysql_ResultObject_Type.ob_type = &PyType_Type;

View File

@ -706,7 +706,7 @@ class DatabaseAPI20Test(unittest.TestCase):
that returns two result sets, first the 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' raise NotImplementedError('Helper not implemented')
#sql=""" #sql="""
# create procedure deleteme as # create procedure deleteme as
# begin # begin
@ -718,7 +718,7 @@ class DatabaseAPI20Test(unittest.TestCase):
def help_nextset_tearDown(self,cur): def help_nextset_tearDown(self,cur):
'If cleaning up is needed after nextSetTest' 'If cleaning up is needed after nextSetTest'
raise NotImplementedError,'Helper not implemented' raise NotImplementedError('Helper not implemented')
#cur.execute("drop procedure deleteme") #cur.execute("drop procedure deleteme")
def test_nextset(self): def test_nextset(self):
@ -751,7 +751,7 @@ class DatabaseAPI20Test(unittest.TestCase):
con.close() con.close()
def test_nextset(self): def test_nextset(self):
raise NotImplementedError,'Drivers need to override this test' raise NotImplementedError('Drivers need to override this test')
def test_arraysize(self): def test_arraysize(self):
# Not much here - rest of the tests for this are in test_fetchmany # Not much here - rest of the tests for this are in test_fetchmany
@ -786,7 +786,7 @@ class DatabaseAPI20Test(unittest.TestCase):
def test_setoutputsize(self): def test_setoutputsize(self):
# Real test for setoutputsize is driver dependant # Real test for setoutputsize is driver dependant
raise NotImplementedError,'Driver need to override this test' raise NotImplementedError('Driver need to override this test')
def test_None(self): def test_None(self):
con = self._connect() con = self._connect()

View File

@ -77,7 +77,7 @@ class test_MySQLdb(capabilities.DatabaseTest):
from MySQLdb.constants import ER from MySQLdb.constants import ER
try: try:
self.cursor.execute("describe some_non_existent_table"); self.cursor.execute("describe some_non_existent_table");
except self.connection.ProgrammingError as msg: except self.connection.ProgrammingError as (msg,):
self.assertTrue(msg[0] == ER.NO_SUCH_TABLE) self.assertTrue(msg[0] == ER.NO_SUCH_TABLE)
def test_bug_3514287(self): def test_bug_3514287(self):

View File

@ -203,4 +203,3 @@ class test_MySQLdb(dbapi20.DatabaseAPI20Test):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
print '''"Huh-huh, he said 'unit'." -- Butthead'''