@@ -705,11 +705,14 @@ def setUp(self):
705
705
try :
706
706
import pymysql
707
707
self .driver = pymysql
708
-
709
708
except ImportError :
710
- raise nose .SkipTest
709
+ raise nose .SkipTest ('pymysql not installed' )
710
+
711
+ try :
712
+ self .conn = self .connect ()
713
+ except self .driver .err .OperationalError :
714
+ raise nose .SkipTest ("Can't connect to MySQL server" )
711
715
712
- self .conn = self .connect ()
713
716
self .pandasSQL = sql .PandasSQLLegacy (self .conn , 'mysql' )
714
717
715
718
self ._load_iris_data ()
@@ -725,53 +728,55 @@ def tearDown(self):
725
728
726
729
727
730
class TestMySQLAlchemy (_TestSQLAlchemy ):
728
- flavor = 'mysql'
729
-
730
- def connect (self ):
731
- return sqlalchemy .create_engine (
732
- 'mysql+{driver}://root@localhost/pandas_nosetest' .format (driver = self .driver ))
731
+ flavor = 'mysql'
733
732
734
- def setUp (self ):
735
- if not SQLALCHEMY_INSTALLED :
736
- raise nose . SkipTest ( 'SQLAlchemy not installed' )
733
+ def connect (self ):
734
+ return sqlalchemy . create_engine (
735
+ 'mysql+{driver}://root@localhost/pandas_nosetest' . format ( driver = self . driver ) )
737
736
738
- try :
739
- import pymysql
740
- self . driver = 'pymysql'
737
+ def setUp ( self ) :
738
+ if not SQLALCHEMY_INSTALLED :
739
+ raise nose . SkipTest ( 'SQLAlchemy not installed' )
741
740
742
- except ImportError :
743
- raise nose .SkipTest
741
+ try :
742
+ import pymysql
743
+ self .driver = 'pymysql'
744
+ except ImportError :
745
+ raise nose .SkipTest ('pymysql not installed' )
744
746
747
+ try :
745
748
self .conn = self .connect ()
746
749
self .pandasSQL = sql .PandasSQLAlchemy (self .conn )
750
+ except sqlalchemy .exc .OperationalError :
751
+ raise nose .SkipTest ("Can't connect to MySQL server" )
747
752
748
- self ._load_iris_data ()
749
- self ._load_raw_sql ()
753
+ self ._load_iris_data ()
754
+ self ._load_raw_sql ()
750
755
751
- self ._load_test1_data ()
756
+ self ._load_test1_data ()
757
+
758
+ def tearDown (self ):
759
+ c = self .conn .execute ('SHOW TABLES' )
760
+ for table in c .fetchall ():
761
+ self .conn .execute ('DROP TABLE %s' % table [0 ])
752
762
753
- def tearDown (self ):
754
- c = self .conn .execute ('SHOW TABLES' )
755
- for table in c .fetchall ():
756
- self .conn .execute ('DROP TABLE %s' % table [0 ])
763
+ def test_default_type_conversion (self ):
764
+ df = sql .read_table ("types_test_data" , self .conn )
757
765
758
- def test_default_type_conversion (self ):
759
- df = sql .read_table ("types_test_data" , self .conn )
760
-
761
- self .assertTrue (issubclass (df .FloatCol .dtype .type , np .floating ),
762
- "FloatCol loaded with incorrect type" )
763
- self .assertTrue (issubclass (df .IntCol .dtype .type , np .integer ),
764
- "IntCol loaded with incorrect type" )
765
- # MySQL has no real BOOL type (it's an alias for TINYINT)
766
- self .assertTrue (issubclass (df .BoolCol .dtype .type , np .integer ),
767
- "BoolCol loaded with incorrect type" )
768
-
769
- # Int column with NA values stays as float
770
- self .assertTrue (issubclass (df .IntColWithNull .dtype .type , np .floating ),
771
- "IntColWithNull loaded with incorrect type" )
772
- # Bool column with NA = int column with NA values => becomes float
773
- self .assertTrue (issubclass (df .BoolColWithNull .dtype .type , np .floating ),
774
- "BoolColWithNull loaded with incorrect type" )
766
+ self .assertTrue (issubclass (df .FloatCol .dtype .type , np .floating ),
767
+ "FloatCol loaded with incorrect type" )
768
+ self .assertTrue (issubclass (df .IntCol .dtype .type , np .integer ),
769
+ "IntCol loaded with incorrect type" )
770
+ # MySQL has no real BOOL type (it's an alias for TINYINT)
771
+ self .assertTrue (issubclass (df .BoolCol .dtype .type , np .integer ),
772
+ "BoolCol loaded with incorrect type" )
773
+
774
+ # Int column with NA values stays as float
775
+ self .assertTrue (issubclass (df .IntColWithNull .dtype .type , np .floating ),
776
+ "IntColWithNull loaded with incorrect type" )
777
+ # Bool column with NA = int column with NA values => becomes float
778
+ self .assertTrue (issubclass (df .BoolColWithNull .dtype .type , np .floating ),
779
+ "BoolColWithNull loaded with incorrect type" )
775
780
776
781
777
782
class TestPostgreSQLAlchemy (_TestSQLAlchemy ):
@@ -780,26 +785,28 @@ class TestPostgreSQLAlchemy(_TestSQLAlchemy):
780
785
def connect (self ):
781
786
return sqlalchemy .create_engine (
782
787
'postgresql+{driver}://postgres@localhost/pandas_nosetest' .format (driver = self .driver ))
783
-
788
+
784
789
def setUp (self ):
785
790
if not SQLALCHEMY_INSTALLED :
786
791
raise nose .SkipTest ('SQLAlchemy not installed' )
787
-
792
+
788
793
try :
789
794
import psycopg2
790
795
self .driver = 'psycopg2'
791
-
792
796
except ImportError :
793
- raise nose .SkipTest
794
-
795
- self .conn = self .connect ()
796
- self .pandasSQL = sql .PandasSQLAlchemy (self .conn )
797
-
797
+ raise nose .SkipTest ('psycopg2 not installed' )
798
+
799
+ try :
800
+ self .conn = self .connect ()
801
+ self .pandasSQL = sql .PandasSQLAlchemy (self .conn )
802
+ except sqlalchemy .exc .OperationalError :
803
+ raise nose .SkipTest ("Can't connect to PostgreSQL server" )
804
+
798
805
self ._load_iris_data ()
799
806
self ._load_raw_sql ()
800
-
807
+
801
808
self ._load_test1_data ()
802
-
809
+
803
810
def tearDown (self ):
804
811
c = self .conn .execute (
805
812
"SELECT table_name FROM information_schema.tables"
0 commit comments