6666# @pytest.fixture
6767def create_uuid (uuid_value ):
6868 # def _return_uuid(content):
69- return f'{ uuid_value } _{ uuid .uuid4 ().hex } '
69+ return f'{ uuid_value } _{ uuid .uuid4 ().hex } ' [ 0 : 30 ]
7070 # return _return_uuid
7171
7272 # return f'{getattr(request, "param", "None")}_{uuid.uuid4().hex}'
@@ -77,8 +77,15 @@ def repeat(constant):
7777 yield constant
7878
7979
80- def setup (connection_variables , uuid_constant ):
81- return list (map (lambda * args : args , connection_variables , repeat (uuid_constant )))
80+ def setup (connection_variables , uuid_tables = None , uuid_views = None ):
81+
82+ conn = []
83+ for each in connection_variables :
84+ if type (each ) == type ("str" ):
85+ conn .append (each )
86+ else :
87+ conn .append (each [0 ][0 ])
88+ return list (map (lambda * args : args , conn , repeat (uuid_tables ), repeat (uuid_views )))
8289
8390
8491@pytest .fixture
@@ -547,22 +554,9 @@ def get_all_views(conn):
547554 results .append (view_name )
548555
549556 return results
550- elif type (conn ) == type ("str" ):
551- pytest .skip ("sqlite str does not support inspect" )
552- with open ("get_all_views_dump.txt" , "a" ) as file :
553- file .write ('\n \n ' )
554- file .write ((repr (conn )))
555- if "sqlite" in conn :
556- return
557557 else :
558- with open ("get_all_views_dump.txt" , "a" ) as file :
559- file .write ('\n \n ' )
560- file .write (str (type (conn )))
561558 from sqlalchemy import inspect
562559
563- with open ("view_dump.txt" , "a" ) as file :
564- file .write ('\n \n ' )
565- file .write ((repr (conn )))
566560
567561 return inspect (conn ).get_view_names ()
568562
@@ -589,37 +583,32 @@ def get_all_tables(conn):
589583
590584 return inspect (conn ).get_table_names ()
591585
592- #TODO
593- # test1.py has a parameter that runs in a subrequest as a fixture.
594- # I need to modify this behaviour to create a subrequest in a fixture
595- # so I need to see if I can modify the request inside the test, and then
596- # run it with the fixture.
597586
598587#TODO See if I can inject something in the request object
599588def filter_get_all_tables (conn , extract_this_value ):
600589 tables = get_all_tables (conn )
601- with open ("tables.txt" , "w" ) as file :
602- file .write (str (tables ))
590+ # with open("tables.txt", "w") as file:
591+ # file.write(str(tables))
603592 return_val = []
604- with open ("collected.txt" , "w" ) as file :
605- file .write ('\n ' )
606- for t in tables :
607- if t in extract_this_value :
608- file .write (str (t ))
609- return_val .append (t )
593+ # with open("collected.txt", "w") as file:
594+ # file.write('\n')
595+ for t in tables :
596+ if t in extract_this_value :
597+ # file.write(str(t))
598+ return_val .append (t )
610599 return return_val
611600
612601def filter_get_all_views (conn , extract_this_value ):
613602 views = get_all_views (conn )
614- with open ("views.txt" , "w" ) as file :
615- file .write (str (views ))
603+ # with open("views.txt", "w") as file:
604+ # file.write(str(views))
616605 return_val = []
617606
618607 with open ("collected.txt" , "a" ) as file :
619- file .write ('\n ' )
608+ # file.write('\n')
620609 for v in views :
621610 if v in extract_this_value :
622- file .write (str (v ))
611+ # file.write(str(v))
623612 return_val .append (v )
624613 return return_val
625614
@@ -1071,77 +1060,58 @@ def sqlite_buildin_types(sqlite_buildin, types_data):
10711060@pytest .fixture
10721061def connect_and_uuid (request ):
10731062 conn = request .param [0 ]
1074- while True :
1075- try :
1076- c = conn [0 ]
1077- assert type (c ) != type ("string" )
1078- conn = c
1079-
1080- except AssertionError :
1081- if type (conn ) != type ("string" ):
1082- conn = conn [0 ]
1083- break
1084- with open ("raw_conn.txt" , "a" ) as file :
1085- file .write ('\n \n ' )
1086- file .write (repr (conn ))
1063+ table_uuid = None if request .param [1 ] is None else "table_" + create_uuid (request .param [1 ])
1064+ view_uuid = None if request .param [2 ] is None else "view_" + create_uuid (request .param [2 ])
10871065 conn = request .getfixturevalue (conn )
1088- with open ("conn .txt" , "a" ) as file :
1089- file .write ('\n \n ' )
1090- file .write (repr (conn ))
1091- # quit(1 )
1092- uuid_value = create_uuid ( request . param [ 1 ] )
1066+ # with open('rawconn .txt', 'a' ) as file:
1067+ # file.write('\n')
1068+ # file.write(repr(conn))
1069+ # file.write('\n' )
1070+ # file.write(str(type(conn)) )
10931071
10941072 import sqlalchemy
10951073 from sqlalchemy import Engine
1096- # conn.execution_options(isolation_level="AUTOCOMMIT")
1097- yield conn , uuid_value
1098- # if isinstance(conn, Engine):
1099- # conn = conn.connect()
1100- # if conn.in_transaction():
1101- # conn.commit()
1102- # else:
1103- # if conn.in_transaction():
1104- # conn.commit()
1105- with open ("a.txt" , "a" ) as file :
1106- file .write ('\n \n ' )
1107- file .write ("view_" + uuid_value )
1108- file .write ('\n \n ' )
1109- file .write ("table_" + uuid_value )
1110-
1111- for view in filter_get_all_views (conn , "view_" + uuid_value ):
1112- drop_view (view , conn )
1113-
1114- for tbl in filter_get_all_tables (conn , "table_" + uuid_value ):
1115- drop_table (tbl , conn )
1116-
1117-
1118- @pytest .mark .parametrize ("connect_and_uuid" , setup (all_connectable , "test_dataframe_to_sql" ), indirect = True )
1119- def test_all (connect_and_uuid ):
1120- with open ("all.txt" , "a" ) as file :
1121- file .write ('\n \n ' )
1122- file .write (repr (setup (all_connectable , "test_dataframe_to_sql" )))
1074+ if table_uuid is None and view_uuid is None :
1075+ yield conn
1076+ if table_uuid is not None and view_uuid is None :
1077+ yield conn , table_uuid
1078+ if table_uuid is None and view_uuid is not None :
1079+ yield conn , view_uuid
1080+ if table_uuid is not None and view_uuid is not None :
1081+ yield conn , table_uuid , view_uuid
1082+ if type (conn ) != type ("str" ):
1083+ if view_uuid is not None :
1084+ for view in filter_get_all_views (conn , view_uuid ):
1085+ drop_view (view , conn )
1086+
1087+ if table_uuid is not None :
1088+ for tbl in filter_get_all_tables (conn , table_uuid ):
1089+ drop_table (tbl , conn )
11231090
11241091
1125- @pytest .mark .parametrize ("connect_and_uuid" , setup (all_connectable , "test_dataframe_to_sql" ), indirect = True )
1092+ @pytest .mark .parametrize ("connect_and_uuid" , setup (all_connectable , uuid_tables = "test_dataframe_to_sql" ), indirect = True )
1093+ def test_all (connect_and_uuid ):
1094+ pass
1095+
1096+ @pytest .mark .parametrize ("connect_and_uuid" , setup (all_connectable , uuid_tables = "test_dataframe_to_sql" ), indirect = True )
11261097def test_dataframe_to_sql (connect_and_uuid , test_frame1 , request ):
1127- # GH 51086 if conn is sqlite_engine
1128- conn , uuid = connect_and_uuid
1129- table_uuid = "table_" + uuid
1098+ conn , table_uuid = connect_and_uuid
11301099 test_frame1 .to_sql (name = table_uuid , con = conn , if_exists = "append" , index = False )
11311100
11321101
1133- @pytest .mark .parametrize ("conn" , all_connectable )
1134- def test_dataframe_to_sql_empty (conn , test_frame1 , request ):
1135- if conn == "postgresql_adbc_conn" and not using_string_dtype ():
1102+ # @pytest.mark.parametrize("conn", all_connectable)
1103+ @pytest .mark .parametrize ("connect_and_uuid" , setup (all_connectable , uuid_tables = "test_dataframe_to_sql_empty" ), indirect = True )
1104+ def test_dataframe_to_sql_empty (connect_and_uuid , test_frame1 , request ):
1105+ conn , table_uuid = connect_and_uuid
1106+
1107+ if "adbc_driver_manager.dbapi.Connection" in str (type (conn )):
11361108 request .node .add_marker (
11371109 pytest .mark .xfail (
11381110 reason = "postgres ADBC driver < 1.2 cannot insert index with null type" ,
11391111 )
11401112 )
11411113
11421114 # GH 51086 if conn is sqlite_engine
1143- conn = request .getfixturevalue (conn )
1144- table_uuid = "test_" + create_uuid ("test" )
11451115 empty_df = test_frame1 .iloc [:0 ]
11461116 empty_df .to_sql (name = table_uuid , con = conn , if_exists = "append" , index = False )
11471117
@@ -1176,7 +1146,7 @@ def test_dataframe_to_sql_arrow_dtypes(conn, request):
11761146 msg = "the 'timedelta'"
11771147
11781148 conn = request .getfixturevalue (conn )
1179- table_uuid = create_unique_table_name ("test_arrow" )
1149+ table_uuid = "table_" + create_uuid ("test_arrow" )
11801150 with tm .assert_produces_warning (exp_warning , match = msg , check_stacklevel = False ):
11811151 df .to_sql (name = table_uuid , con = conn , if_exists = "replace" , index = False )
11821152
0 commit comments