66
66
# @pytest.fixture
67
67
def create_uuid (uuid_value ):
68
68
# def _return_uuid(content):
69
- return f'{ uuid_value } _{ uuid .uuid4 ().hex } '
69
+ return f'{ uuid_value } _{ uuid .uuid4 ().hex } ' [ 0 : 30 ]
70
70
# return _return_uuid
71
71
72
72
# return f'{getattr(request, "param", "None")}_{uuid.uuid4().hex}'
@@ -77,8 +77,15 @@ def repeat(constant):
77
77
yield constant
78
78
79
79
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 )))
82
89
83
90
84
91
@pytest .fixture
@@ -547,22 +554,9 @@ def get_all_views(conn):
547
554
results .append (view_name )
548
555
549
556
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
557
557
else :
558
- with open ("get_all_views_dump.txt" , "a" ) as file :
559
- file .write ('\n \n ' )
560
- file .write (str (type (conn )))
561
558
from sqlalchemy import inspect
562
559
563
- with open ("view_dump.txt" , "a" ) as file :
564
- file .write ('\n \n ' )
565
- file .write ((repr (conn )))
566
560
567
561
return inspect (conn ).get_view_names ()
568
562
@@ -589,37 +583,32 @@ def get_all_tables(conn):
589
583
590
584
return inspect (conn ).get_table_names ()
591
585
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.
597
586
598
587
#TODO See if I can inject something in the request object
599
588
def filter_get_all_tables (conn , extract_this_value ):
600
589
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))
603
592
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 )
610
599
return return_val
611
600
612
601
def filter_get_all_views (conn , extract_this_value ):
613
602
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))
616
605
return_val = []
617
606
618
607
with open ("collected.txt" , "a" ) as file :
619
- file .write ('\n ' )
608
+ # file.write('\n')
620
609
for v in views :
621
610
if v in extract_this_value :
622
- file .write (str (v ))
611
+ # file.write(str(v))
623
612
return_val .append (v )
624
613
return return_val
625
614
@@ -1071,77 +1060,58 @@ def sqlite_buildin_types(sqlite_buildin, types_data):
1071
1060
@pytest .fixture
1072
1061
def connect_and_uuid (request ):
1073
1062
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 ])
1087
1065
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)) )
1093
1071
1094
1072
import sqlalchemy
1095
1073
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 )
1123
1090
1124
1091
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 )
1126
1097
def 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
1130
1099
test_frame1 .to_sql (name = table_uuid , con = conn , if_exists = "append" , index = False )
1131
1100
1132
1101
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 )):
1136
1108
request .node .add_marker (
1137
1109
pytest .mark .xfail (
1138
1110
reason = "postgres ADBC driver < 1.2 cannot insert index with null type" ,
1139
1111
)
1140
1112
)
1141
1113
1142
1114
# GH 51086 if conn is sqlite_engine
1143
- conn = request .getfixturevalue (conn )
1144
- table_uuid = "test_" + create_uuid ("test" )
1145
1115
empty_df = test_frame1 .iloc [:0 ]
1146
1116
empty_df .to_sql (name = table_uuid , con = conn , if_exists = "append" , index = False )
1147
1117
@@ -1176,7 +1146,7 @@ def test_dataframe_to_sql_arrow_dtypes(conn, request):
1176
1146
msg = "the 'timedelta'"
1177
1147
1178
1148
conn = request .getfixturevalue (conn )
1179
- table_uuid = create_unique_table_name ("test_arrow" )
1149
+ table_uuid = "table_" + create_uuid ("test_arrow" )
1180
1150
with tm .assert_produces_warning (exp_warning , match = msg , check_stacklevel = False ):
1181
1151
df .to_sql (name = table_uuid , con = conn , if_exists = "replace" , index = False )
1182
1152
0 commit comments