1717
1818import numpy as np
1919import pytest
20+ from sqlalchemy import text
21+ from sqlalchemy .engine import Connection
2022
2123from pandas ._config import using_string_dtype
2224
@@ -4355,22 +4357,15 @@ def test_xsqlite_if_exists(sqlite_buildin):
43554357 drop_table (table_name , sqlite_buildin )
43564358
43574359
4358- @pytest .mark .db
4359- def test_exists_temporary_table (mysql_pymysql_engine ):
4360- df_true = DataFrame (
4361- {
4362- "id" : [1 , 2 ],
4363- "name" : ["Siegfried" , "Isolde" ],
4364- }
4365- )
4360+ @pytest .mark .parametrize ("conn" , mysql_connectable )
4361+ def test_exists_temporary_table (conn , test_frame1 , request ):
4362+ conn = request .getfixturevalue (conn )
43664363
4367- pandas_sql = pandasSQL_builder (
4368- mysql_pymysql_engine , schema = None , need_transaction = True
4369- )
4364+ pandas_sql = pandasSQL_builder (conn , schema = None , need_transaction = True )
43704365 table = sql .SQLTable (
4371- name = "DF_TRUE " ,
4366+ name = "test_frame1 " ,
43724367 pandas_sql_engine = pandas_sql ,
4373- frame = df_true ,
4368+ frame = test_frame1 ,
43744369 index = False ,
43754370 if_exists = "fail" ,
43764371 prefixes = ["TEMPORARY" ],
@@ -4381,66 +4376,66 @@ def test_exists_temporary_table(mysql_pymysql_engine):
43814376 assert True if table .exists () else False
43824377
43834378
4384- @pytest .mark .db
4385- def test_to_sql_temporary_table_replace (mysql_pymysql_engine ):
4386- from sqlalchemy import text
4387-
4388- df_true = DataFrame (
4389- {
4390- "id" : [1 , 2 ],
4391- "name" : ["Siegried" , "Isolde" ],
4392- }
4393- )
4379+ @pytest .mark .parametrize ("conn" , mysql_connectable )
4380+ def test_to_sql_temporary_table_replace (conn , test_frame1 , request ):
4381+ conn = request .getfixturevalue (conn )
43944382
43954383 query = """
4396- CREATE TEMPORARY TABLE DF_TRUE (
4397- ID SMALLINT,
4398- NAME VARCHAR(20)
4384+ CREATE TEMPORARY TABLE test_frame1 (
4385+ `INDEX` TEXT,
4386+ A FLOAT(53),
4387+ B FLOAT(53),
4388+ C FLOAT(53),
4389+ D FLOAT(53)
43994390 )
44004391 """
44014392
4402- with mysql_pymysql_engine .begin () as conn :
4403- conn .execute (text (query ))
4393+ if isinstance (conn , Connection ):
4394+ con = conn
4395+ else :
4396+ con = conn .connect ()
44044397
4405- df_true .to_sql (
4406- name = "DF_TRUE" ,
4407- con = conn ,
4408- if_exists = "replace" ,
4409- index = False ,
4410- prefixes = ["TEMPORARY" ],
4411- )
4398+ con .execute (text (query ))
44124399
4413- df_test = pd .read_sql ("SELECT * FROM DF_TRUE" , conn )
4400+ test_frame1 .to_sql (
4401+ name = "test_frame1" ,
4402+ con = con ,
4403+ if_exists = "replace" ,
4404+ index = False ,
4405+ prefixes = ["TEMPORARY" ],
4406+ )
44144407
4415- assert_frame_equal ( df_true , df_test )
4408+ df_test = pd . read_sql ( "SELECT * FROM test_frame1" , con )
44164409
4410+ assert_frame_equal (test_frame1 , df_test )
44174411
4418- @pytest .mark .db
4419- def test_to_sql_temporary_table_fail (mysql_pymysql_engine ):
4420- from sqlalchemy import text
44214412
4422- df_true = DataFrame (
4423- {
4424- "id" : [1 , 2 ],
4425- "name" : ["Siegfried" , "Isolde" ],
4426- }
4427- )
4413+ @pytest .mark .parametrize ("conn" , mysql_connectable )
4414+ def test_to_sql_temporary_table_fail (conn , test_frame1 , request ):
4415+ conn = request .getfixturevalue (conn )
44284416
44294417 query = """
4430- CREATE TEMPORARY TABLE DF_TRUE (
4431- ID SMALLINT,
4432- NAME VARCHAR(20)
4418+ CREATE TEMPORARY TABLE test_frame1 (
4419+ `INDEX` TEXT,
4420+ A FLOAT(53),
4421+ B FLOAT(53),
4422+ C FLOAT(53),
4423+ D FLOAT(53)
44334424 )
44344425 """
44354426
4436- with mysql_pymysql_engine .begin () as conn :
4437- conn .execute (text (query ))
4427+ if isinstance (conn , Connection ):
4428+ con = conn
4429+ else :
4430+ con = conn .connect ()
44384431
4439- with pytest .raises (ValueError , match = r"Table 'DF_TRUE' already exists." ):
4440- df_true .to_sql (
4441- name = "DF_TRUE" ,
4442- con = conn ,
4443- if_exists = "fail" ,
4444- index = False ,
4445- prefixes = ["TEMPORARY" ],
4446- )
4432+ con .execute (text (query ))
4433+
4434+ with pytest .raises (ValueError , match = r"Table 'test_frame1' already exists." ):
4435+ test_frame1 .to_sql (
4436+ name = "test_frame1" ,
4437+ con = con ,
4438+ if_exists = "fail" ,
4439+ index = False ,
4440+ prefixes = ["TEMPORARY" ],
4441+ )
0 commit comments