From 677c987ad91413293772bc042d62943a5feface6 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Tue, 2 Aug 2011 23:26:50 -0700 Subject: [PATCH] Test that tornado.database is at least importable on all supported pythons. Fix a problem preventing import on pypy (but apparently there are still other issues with running MySQLdb on pypy, so the module will not actually work yet). --- tornado/database.py | 4 ++-- tornado/test/import_test.py | 27 +++++++++++++++++++++++++++ tox.ini | 23 +++++++++++++++++------ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/tornado/database.py b/tornado/database.py index e0f16e706..4a437fbf7 100644 --- a/tornado/database.py +++ b/tornado/database.py @@ -180,14 +180,14 @@ class Row(dict): # Fix the access conversions to properly recognize unicode/binary FIELD_TYPE = MySQLdb.constants.FIELD_TYPE FLAG = MySQLdb.constants.FLAG -CONVERSIONS = copy.deepcopy(MySQLdb.converters.conversions) +CONVERSIONS = copy.copy(MySQLdb.converters.conversions) field_types = [FIELD_TYPE.BLOB, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING] if 'VARCHAR' in vars(FIELD_TYPE): field_types.append(FIELD_TYPE.VARCHAR) for field_type in field_types: - CONVERSIONS[field_type].insert(0, (FLAG.BINARY, str)) + CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type] # Alias some common MySQL exceptions diff --git a/tornado/test/import_test.py b/tornado/test/import_test.py index b146eb90e..7da1a1ef9 100644 --- a/tornado/test/import_test.py +++ b/tornado/test/import_test.py @@ -28,3 +28,30 @@ class ImportTest(unittest.TestCase): import tornado.web import tornado.websocket import tornado.wsgi + + # for modules with dependencies, if those dependencies can be loaded, + # load them too. + + def test_import_pycurl(self): + try: + import pycurl + except ImportError: + pass + else: + import tornado.curl_httpclient + + def test_import_mysqldb(self): + try: + import MySQLdb + except ImportError: + pass + else: + import tornado.database + + def test_import_twisted(self): + try: + import twisted + except ImportError: + pass + else: + import tornado.platform.twisted diff --git a/tox.ini b/tox.ini index 4816171f5..cdcce3452 100644 --- a/tox.ini +++ b/tox.ini @@ -5,10 +5,15 @@ # # See also tornado/test/run_pyversion_tests.py, which is faster but # less thorough. +# +# On my macports-based setup, the environment variable +# ARCHFLAGS='-arch x86_64' must be set when building pycurl, and a +# symlink from mysql_config to mysql_config5 must exist when building +# MySQL-python. [tox] # "-full" variants include optional dependencies, to ensure # that things work both in a bare install and with all the extras. -envlist = py25, py25-full, py26, py26-full, py27, py27-full, pypy, py32 +envlist = py25, py25-full, py26, py26-full, py27, py27-full, pypy, pypy-full, py32 [testenv] commands = python -m tornado.test.runtests {posargs:} @@ -26,10 +31,8 @@ deps = simplejson [testenv:py25-full] basepython = python2.5 -# pycurl doesn't install cleanly for me from pip on 2.5, so get it from -# the system python. -sitepackages = True deps = + MySQL-python pycurl simplejson twisted @@ -37,14 +40,22 @@ deps = [testenv:py26-full] basepython = python2.6 deps = + MySQL-python pycurl twisted [testenv:py27-full] basepython = python2.7 deps = + MySQL-python pycurl twisted -# No pypy-full yet: pycurl doesn't build, and installing twisted -# under pypy takes a *very* long time. Neither package works on python3. +[testenv:pypy-full] +# pycurl doesn't build with pypy, and installing twisted under pypy takes +# a *very* long time +basepython = pypy +deps = + MySQL-python + +# No py32-full yet: none of our dependencies currently work on python3. -- 2.47.2