@@ -868,24 +868,38 @@ class _TestSQLAlchemy(PandasSQLTest):
868
868
"""
869
869
flavor = None
870
870
871
+ @classmethod
872
+ def setUpClass (cls ):
873
+ cls .setup_import ()
874
+ cls .setup_driver ()
875
+
876
+ # test connection
877
+ try :
878
+ conn = cls .connect ()
879
+ conn .connect ()
880
+ except sqlalchemy .exc .OperationalError :
881
+ msg = "{0} - can't connect to {1} server" .format (cls , cls .flavor )
882
+ raise nose .SkipTest (msg )
883
+
871
884
def setUp (self ):
872
- self .setup_import ()
873
- self .setup_driver ()
874
885
self .setup_connect ()
875
886
876
887
self ._load_iris_data ()
877
888
self ._load_raw_sql ()
878
889
self ._load_test1_data ()
879
890
880
- def setup_import (self ):
891
+ @classmethod
892
+ def setup_import (cls ):
881
893
# Skip this test if SQLAlchemy not available
882
894
if not SQLALCHEMY_INSTALLED :
883
895
raise nose .SkipTest ('SQLAlchemy not installed' )
884
896
885
- def setup_driver (self ):
897
+ @classmethod
898
+ def setup_driver (cls ):
886
899
raise NotImplementedError ()
887
900
888
- def connect (self ):
901
+ @classmethod
902
+ def connect (cls ):
889
903
raise NotImplementedError ()
890
904
891
905
def setup_connect (self ):
@@ -1221,12 +1235,14 @@ class TestSQLiteAlchemy(_TestSQLAlchemy):
1221
1235
"""
1222
1236
flavor = 'sqlite'
1223
1237
1224
- def connect (self ):
1238
+ @classmethod
1239
+ def connect (cls ):
1225
1240
return sqlalchemy .create_engine ('sqlite:///:memory:' )
1226
1241
1227
- def setup_driver (self ):
1242
+ @classmethod
1243
+ def setup_driver (cls ):
1228
1244
# sqlite3 is built-in
1229
- self .driver = None
1245
+ cls .driver = None
1230
1246
1231
1247
def tearDown (self ):
1232
1248
# in memory so tables should not be removed explicitly
@@ -1275,14 +1291,16 @@ class TestMySQLAlchemy(_TestSQLAlchemy):
1275
1291
"""
1276
1292
flavor = 'mysql'
1277
1293
1278
- def connect (self ):
1279
- return sqlalchemy .create_engine (
1280
- 'mysql+{driver}://root@localhost/pandas_nosetest' .format (driver = self .driver ))
1294
+ @classmethod
1295
+ def connect (cls ):
1296
+ url = 'mysql+{driver}://root@localhost/pandas_nosetest'
1297
+ return sqlalchemy .create_engine (url .format (driver = cls .driver ))
1281
1298
1282
- def setup_driver (self ):
1299
+ @classmethod
1300
+ def setup_driver (cls ):
1283
1301
try :
1284
1302
import pymysql
1285
- self .driver = 'pymysql'
1303
+ cls .driver = 'pymysql'
1286
1304
except ImportError :
1287
1305
raise nose .SkipTest ('pymysql not installed' )
1288
1306
@@ -1347,14 +1365,16 @@ class TestPostgreSQLAlchemy(_TestSQLAlchemy):
1347
1365
"""
1348
1366
flavor = 'postgresql'
1349
1367
1350
- def connect (self ):
1368
+ @classmethod
1369
+ def connect (cls ):
1351
1370
url = 'postgresql+{driver}://postgres@localhost/pandas_nosetest'
1352
- return sqlalchemy .create_engine (url .format (driver = self .driver ))
1371
+ return sqlalchemy .create_engine (url .format (driver = cls .driver ))
1353
1372
1354
- def setup_driver (self ):
1373
+ @classmethod
1374
+ def setup_driver (cls ):
1355
1375
try :
1356
1376
import psycopg2
1357
- self .driver = 'psycopg2'
1377
+ cls .driver = 'psycopg2'
1358
1378
except ImportError :
1359
1379
raise nose .SkipTest ('psycopg2 not installed' )
1360
1380
@@ -1431,7 +1451,8 @@ class TestSQLiteFallback(PandasSQLTest):
1431
1451
"""
1432
1452
flavor = 'sqlite'
1433
1453
1434
- def connect (self ):
1454
+ @classmethod
1455
+ def connect (cls ):
1435
1456
return sqlite3 .connect (':memory:' )
1436
1457
1437
1458
def drop_table (self , table_name ):
@@ -1582,6 +1603,28 @@ class TestMySQLLegacy(TestSQLiteFallback):
1582
1603
"""
1583
1604
flavor = 'mysql'
1584
1605
1606
+ @classmethod
1607
+ def setUpClass (cls ):
1608
+ cls .setup_driver ()
1609
+
1610
+ # test connection
1611
+ try :
1612
+ cls .connect ()
1613
+ except cls .driver .err .OperationalError :
1614
+ raise nose .SkipTest ("{0} - can't connect to MySQL server" .format (cls ))
1615
+
1616
+ @classmethod
1617
+ def setup_driver (cls ):
1618
+ try :
1619
+ import pymysql
1620
+ cls .driver = pymysql
1621
+ except ImportError :
1622
+ raise nose .SkipTest ('pymysql not installed' )
1623
+
1624
+ @classmethod
1625
+ def connect (cls ):
1626
+ return cls .driver .connect (host = '127.0.0.1' , user = 'root' , passwd = '' , db = 'pandas_nosetest' )
1627
+
1585
1628
def drop_table (self , table_name ):
1586
1629
cur = self .conn .cursor ()
1587
1630
cur .execute ("DROP TABLE IF EXISTS %s" % table_name )
@@ -1594,16 +1637,7 @@ def _count_rows(self, table_name):
1594
1637
rows = cur .fetchall ()
1595
1638
return rows [0 ][0 ]
1596
1639
1597
- def connect (self ):
1598
- return self .driver .connect (host = '127.0.0.1' , user = 'root' , passwd = '' , db = 'pandas_nosetest' )
1599
-
1600
1640
def setUp (self ):
1601
- try :
1602
- import pymysql
1603
- self .driver = pymysql
1604
- except ImportError :
1605
- raise nose .SkipTest ('pymysql not installed' )
1606
-
1607
1641
try :
1608
1642
self .conn = self .connect ()
1609
1643
except self .driver .err .OperationalError :
@@ -1941,6 +1975,35 @@ def clean_up(test_table_to_drop):
1941
1975
1942
1976
class TestXMySQL (tm .TestCase ):
1943
1977
1978
+ @classmethod
1979
+ def setUpClass (cls ):
1980
+ _skip_if_no_pymysql ()
1981
+
1982
+ # test connection
1983
+ import pymysql
1984
+ try :
1985
+ # Try Travis defaults.
1986
+ # No real user should allow root access with a blank password.
1987
+ pymysql .connect (host = 'localhost' , user = 'root' , passwd = '' ,
1988
+ db = 'pandas_nosetest' )
1989
+ except :
1990
+ pass
1991
+ else :
1992
+ return
1993
+ try :
1994
+ pymysql .connect (read_default_group = 'pandas' )
1995
+ except pymysql .ProgrammingError as e :
1996
+ raise nose .SkipTest (
1997
+ "Create a group of connection parameters under the heading "
1998
+ "[pandas] in your system's mysql default file, "
1999
+ "typically located at ~/.my.cnf or /etc/.my.cnf. " )
2000
+ except pymysql .Error as e :
2001
+ raise nose .SkipTest (
2002
+ "Cannot connect to database. "
2003
+ "Create a group of connection parameters under the heading "
2004
+ "[pandas] in your system's mysql default file, "
2005
+ "typically located at ~/.my.cnf or /etc/.my.cnf. " )
2006
+
1944
2007
def setUp (self ):
1945
2008
_skip_if_no_pymysql ()
1946
2009
import pymysql
0 commit comments