fix the skip print notices in mysql_requirement so they are actually visible on stderr when run from nose (plus some stuff pyflakes recommended and a few cosmetic ws and line-len changes)
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
"Test cases for db_pool"
|
"Test cases for db_pool"
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from unittest import TestCase, main
|
||||||
|
|
||||||
from tests import skipped, skip_unless, skip_with_pyevent
|
from tests import skipped, skip_unless, skip_with_pyevent
|
||||||
from unittest import TestCase, main
|
|
||||||
from eventlet import event
|
from eventlet import event
|
||||||
from eventlet import db_pool
|
from eventlet import db_pool
|
||||||
import eventlet
|
import eventlet
|
||||||
import os
|
|
||||||
|
|
||||||
class DBTester(object):
|
class DBTester(object):
|
||||||
__test__ = False # so that nose doesn't try to execute this directly
|
__test__ = False # so that nose doesn't try to execute this directly
|
||||||
@@ -26,7 +28,7 @@ class DBTester(object):
|
|||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.drop_db()
|
self.drop_db()
|
||||||
|
|
||||||
def set_up_dummy_table(self, connection = None):
|
def set_up_dummy_table(self, connection=None):
|
||||||
close_connection = False
|
close_connection = False
|
||||||
if connection is None:
|
if connection is None:
|
||||||
close_connection = True
|
close_connection = True
|
||||||
@@ -84,7 +86,7 @@ class DBConnectionPool(DBTester):
|
|||||||
self.assert_(False)
|
self.assert_(False)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise
|
raise
|
||||||
except Exception, e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
@@ -144,7 +146,6 @@ class DBConnectionPool(DBTester):
|
|||||||
curs.execute(SHORT_QUERY)
|
curs.execute(SHORT_QUERY)
|
||||||
results.append(2)
|
results.append(2)
|
||||||
evt.send()
|
evt.send()
|
||||||
evt2 = event.Event()
|
|
||||||
eventlet.spawn(a_query)
|
eventlet.spawn(a_query)
|
||||||
results.append(1)
|
results.append(1)
|
||||||
self.assertEqual([1], results)
|
self.assertEqual([1], results)
|
||||||
@@ -299,7 +300,10 @@ class DBConnectionPool(DBTester):
|
|||||||
|
|
||||||
@skipped
|
@skipped
|
||||||
def test_max_idle(self):
|
def test_max_idle(self):
|
||||||
# This test is timing-sensitive. Rename the function without the "dont" to run it, but beware that it could fail or take a while.
|
# This test is timing-sensitive. Rename the function without
|
||||||
|
# the "dont" to run it, but beware that it could fail or take
|
||||||
|
# a while.
|
||||||
|
|
||||||
self.pool = self.create_pool(max_size=2, max_idle=0.02)
|
self.pool = self.create_pool(max_size=2, max_idle=0.02)
|
||||||
self.connection = self.pool.get()
|
self.connection = self.pool.get()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
@@ -319,7 +323,10 @@ class DBConnectionPool(DBTester):
|
|||||||
|
|
||||||
@skipped
|
@skipped
|
||||||
def test_max_idle_many(self):
|
def test_max_idle_many(self):
|
||||||
# This test is timing-sensitive. Rename the function without the "dont" to run it, but beware that it could fail or take a while.
|
# This test is timing-sensitive. Rename the function without
|
||||||
|
# the "dont" to run it, but beware that it could fail or take
|
||||||
|
# a while.
|
||||||
|
|
||||||
self.pool = self.create_pool(max_size=2, max_idle=0.02)
|
self.pool = self.create_pool(max_size=2, max_idle=0.02)
|
||||||
self.connection, conn2 = self.pool.get(), self.pool.get()
|
self.connection, conn2 = self.pool.get(), self.pool.get()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
@@ -332,7 +339,10 @@ class DBConnectionPool(DBTester):
|
|||||||
|
|
||||||
@skipped
|
@skipped
|
||||||
def test_max_age(self):
|
def test_max_age(self):
|
||||||
# This test is timing-sensitive. Rename the function without the "dont" to run it, but beware that it could fail or take a while.
|
# This test is timing-sensitive. Rename the function without
|
||||||
|
# the "dont" to run it, but beware that it could fail or take
|
||||||
|
# a while.
|
||||||
|
|
||||||
self.pool = self.create_pool(max_size=2, max_age=0.05)
|
self.pool = self.create_pool(max_size=2, max_age=0.05)
|
||||||
self.connection = self.pool.get()
|
self.connection = self.pool.get()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
@@ -347,7 +357,10 @@ class DBConnectionPool(DBTester):
|
|||||||
|
|
||||||
@skipped
|
@skipped
|
||||||
def test_max_age_many(self):
|
def test_max_age_many(self):
|
||||||
# This test is timing-sensitive. Rename the function without the "dont" to run it, but beware that it could fail or take a while.
|
# This test is timing-sensitive. Rename the function without
|
||||||
|
# the "dont" to run it, but beware that it could fail or take
|
||||||
|
# a while.
|
||||||
|
|
||||||
self.pool = self.create_pool(max_size=2, max_age=0.15)
|
self.pool = self.create_pool(max_size=2, max_age=0.15)
|
||||||
self.connection, conn2 = self.pool.get(), self.pool.get()
|
self.connection, conn2 = self.pool.get(), self.pool.get()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
@@ -424,7 +437,8 @@ class RaisingDBModule(object):
|
|||||||
|
|
||||||
class TpoolConnectionPool(DBConnectionPool):
|
class TpoolConnectionPool(DBConnectionPool):
|
||||||
__test__ = False # so that nose doesn't try to execute this directly
|
__test__ = False # so that nose doesn't try to execute this directly
|
||||||
def create_pool(self, max_size = 1, max_idle = 10, max_age = 10, connect_timeout=0.5, module=None):
|
def create_pool(self, max_size=1, max_idle=10, max_age=10,
|
||||||
|
connect_timeout=0.5, module=None):
|
||||||
if module is None:
|
if module is None:
|
||||||
module = self._dbmodule
|
module = self._dbmodule
|
||||||
return db_pool.TpooledConnectionPool(module,
|
return db_pool.TpooledConnectionPool(module,
|
||||||
@@ -447,7 +461,8 @@ class TpoolConnectionPool(DBConnectionPool):
|
|||||||
|
|
||||||
class RawConnectionPool(DBConnectionPool):
|
class RawConnectionPool(DBConnectionPool):
|
||||||
__test__ = False # so that nose doesn't try to execute this directly
|
__test__ = False # so that nose doesn't try to execute this directly
|
||||||
def create_pool(self, max_size = 1, max_idle = 10, max_age = 10, connect_timeout= 0.5, module=None):
|
def create_pool(self, max_size=1, max_idle=10, max_age=10,
|
||||||
|
connect_timeout=0.5, module=None):
|
||||||
if module is None:
|
if module is None:
|
||||||
module = self._dbmodule
|
module = self._dbmodule
|
||||||
return db_pool.RawConnectionPool(module,
|
return db_pool.RawConnectionPool(module,
|
||||||
@@ -458,8 +473,9 @@ class RawConnectionPool(DBConnectionPool):
|
|||||||
|
|
||||||
|
|
||||||
def get_auth():
|
def get_auth():
|
||||||
"""Looks in the local directory and in the user's home directory for a file named ".test_dbauth",
|
"""Looks in the local directory and in the user's home directory
|
||||||
which contains a json map of parameters to the connect function.
|
for a file named ".test_dbauth", which contains a json map of
|
||||||
|
parameters to the connect function.
|
||||||
"""
|
"""
|
||||||
files = [os.path.join(os.path.dirname(__file__), '.test_dbauth'),
|
files = [os.path.join(os.path.dirname(__file__), '.test_dbauth'),
|
||||||
os.path.join(os.path.expanduser('~'), '.test_dbauth')]
|
os.path.join(os.path.expanduser('~'), '.test_dbauth')]
|
||||||
@@ -473,7 +489,7 @@ def get_auth():
|
|||||||
return dict([(str(modname), dict([(str(k), str(v))
|
return dict([(str(modname), dict([(str(k), str(v))
|
||||||
for k, v in connectargs.items()]))
|
for k, v in connectargs.items()]))
|
||||||
for modname, connectargs in auth_utf8.items()])
|
for modname, connectargs in auth_utf8.items()])
|
||||||
except (IOError, ImportError), e:
|
except (IOError, ImportError):
|
||||||
pass
|
pass
|
||||||
return {'MySQLdb':{'host': 'localhost','user': 'root','passwd': ''},
|
return {'MySQLdb':{'host': 'localhost','user': 'root','passwd': ''},
|
||||||
'psycopg2':{'user':'test'}}
|
'psycopg2':{'user':'test'}}
|
||||||
@@ -487,12 +503,12 @@ def mysql_requirement(_f):
|
|||||||
MySQLdb.connect(**auth)
|
MySQLdb.connect(**auth)
|
||||||
return True
|
return True
|
||||||
except MySQLdb.OperationalError:
|
except MySQLdb.OperationalError:
|
||||||
print "Skipping mysql tests, error when connecting"
|
print >> sys.stderr, ">> Skipping mysql tests, error when connecting:"
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Skipping mysql tests, MySQLdb not importable"
|
print >> sys.stderr, ">> Skipping mysql tests, MySQLdb not importable"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class MysqlConnectionPool(object):
|
class MysqlConnectionPool(object):
|
||||||
@@ -600,7 +616,6 @@ class Psycopg2ConnectionPool(object):
|
|||||||
|
|
||||||
def drop_db(self):
|
def drop_db(self):
|
||||||
auth = self._auth.copy()
|
auth = self._auth.copy()
|
||||||
dbname = auth.pop('database')
|
|
||||||
conn = self._dbmodule.connect(**auth)
|
conn = self._dbmodule.connect(**auth)
|
||||||
conn.set_isolation_level(0)
|
conn.set_isolation_level(0)
|
||||||
db = conn.cursor()
|
db = conn.cursor()
|
||||||
|
Reference in New Issue
Block a user