From 54e0280e0aa837deaf0251fa512ada30ce84023c Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 18 Apr 2010 14:16:03 -0700 Subject: [PATCH] Database tests should be skipped if simplejson isn't installed. --- tests/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 0ed0338..72cf7e7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -171,22 +171,28 @@ def get_database_auth(): connect function. """ import os - import simplejson + retval = {'MySQLdb':{'host': 'localhost','user': 'root','passwd': ''}, + 'psycopg2':{'user':'test'}} + try: + import simplejson + except ImportError: + return retval + if 'EVENTLET_DB_TEST_AUTH' in os.environ: return simplejson.loads(os.environ.get('EVENTLET_DB_TEST_AUTH')) + files = [os.path.join(os.path.dirname(__file__), '.test_dbauth'), os.path.join(os.path.expanduser('~'), '.test_dbauth')] for f in files: try: auth_utf8 = simplejson.load(open(f)) - # have to convert unicode objects to str objects because mysqldb is dum - # using a doubly-nested list comprehension because we know that the structure - # of the structure is a two-level dict + # Have to convert unicode objects to str objects because + # mysqldb is dum. Using a doubly-nested list comprehension + # because we know that the structure is a two-level dict. return dict([(str(modname), dict([(str(k), str(v)) for k, v in connectargs.items()])) for modname, connectargs in auth_utf8.items()]) - except (IOError, ImportError): + except IOError: pass - return {'MySQLdb':{'host': 'localhost','user': 'root','passwd': ''}, - 'psycopg2':{'user':'test'}} + return retval