63
63
]
64
64
65
65
66
- def create_unique_table_name (prefix : str ) -> str :
67
- return f"{ prefix } _{ uuid .uuid4 ().hex } "
66
+ @pytest .fixture
67
+ def create_uuid (request ) -> str :
68
+ return f'{ getattr (request , "param" , "None" )} _{ uuid .uuid4 ().hex } '
69
+
70
+
71
+ def repeat (constant ):
72
+ while True :
73
+ yield constant
74
+
75
+
76
+ def setup (connection_variables , uuid_constant ):
77
+ return list (map (lambda * args : connection_variables , connection_variables , repeat (uuid_constant )))
68
78
69
79
70
80
@pytest .fixture
@@ -538,7 +548,6 @@ def get_all_views(conn):
538
548
539
549
return inspect (conn ).get_view_names ()
540
550
541
-
542
551
def get_all_tables (conn ):
543
552
if isinstance (conn , sqlite3 .Connection ):
544
553
c = conn .execute ("SELECT name FROM sqlite_master WHERE type='table'" )
@@ -562,6 +571,43 @@ def get_all_tables(conn):
562
571
563
572
return inspect (conn ).get_table_names ()
564
573
574
+ #TODO
575
+ # test1.py has a parameter that runs in a subrequest as a fixture.
576
+ # I need to modify this behaviour to create a subrequest in a fixture
577
+ # so I need to see if I can modify the request inside the test, and then
578
+ # run it with the fixture.
579
+
580
+ #TODO See if I can inject something in the request object
581
+ def filter_get_all_tables (conn , extract_this_value ):
582
+ tables = get_all_tables (conn )
583
+ with open ("tables.txt" , "w" ) as file :
584
+ file .write (str (tables ))
585
+ return_val = []
586
+ with open ("collected.txt" , "w" ) as file :
587
+ file .write ('\n ' )
588
+ for t in tables :
589
+ if t in extract_this_value :
590
+ file .write (str (t ))
591
+ return_val .append (t )
592
+ return return_val
593
+
594
+ def filter_get_all_views (conn , extract_this_value ):
595
+ tables = get_all_views (conn )
596
+ with open ("views.txt" , "w" ) as file :
597
+ file .write (str (tables ))
598
+ return_val = []
599
+
600
+ with open ("collected.txt" , "a" ) as file :
601
+ file .write ('\n ' )
602
+ for t in tables :
603
+ if t in extract_this_value :
604
+ file .write (str (t ))
605
+ return_val .append (t )
606
+ return return_val
607
+
608
+
609
+ # filter_get_all_tables(pytest.param("postgresql_psycopg2_engine", marks=pytest.mark.db),'')
610
+
565
611
566
612
def drop_table (
567
613
table_name : str ,
@@ -654,18 +700,19 @@ def mysql_pymysql_conn_types(mysql_pymysql_engine_types):
654
700
655
701
656
702
@pytest .fixture
657
- def postgresql_psycopg2_engine ():
703
+ def postgresql_psycopg2_engine (request ):
658
704
sqlalchemy = pytest .importorskip ("sqlalchemy" )
659
705
pytest .importorskip ("psycopg2" )
660
706
engine = sqlalchemy .create_engine (
661
707
"postgresql+psycopg2://postgres:postgres@localhost:5432/pandas" ,
662
708
poolclass = sqlalchemy .pool .NullPool ,
663
709
)
664
710
yield engine
665
- for view in get_all_views (engine ):
666
- drop_view (view , engine )
667
- for tbl in get_all_tables (engine ):
668
- drop_table (tbl , engine )
711
+
712
+ # for view in filter_get_all_tables(engine, getattr(request, "create_uuid")):
713
+ # drop_view(view, engine)
714
+ # for tbl in filter_get_all_tables(engine, getattr(request, "create_uuid")):
715
+ # drop_table(tbl, engine)
669
716
engine .dispose ()
670
717
671
718
@@ -1469,16 +1516,56 @@ def insert_on_conflict(table, conn, keys, data_iter):
1469
1516
pandasSQL .drop_table (table_uuid )
1470
1517
1471
1518
1472
- @pytest .mark .parametrize ("conn" , postgresql_connectable )
1473
- def test_read_view_postgres (conn , request ):
1519
+ @pytest .fixture
1520
+ def conn (request ):
1521
+ with open ("aaaa.txt" , "w" ) as file :
1522
+ file .write ('\n \n ' )
1523
+ file .write (repr (request .__dict__ ))
1524
+ file .write ('\n \n ' )
1525
+ file .write (repr (getattr (request , "param" , None )))
1526
+ file .write ('\n \n ' )
1527
+ #Parameterset
1528
+ file .write ('\n \n ' )
1529
+ file .write (str (getattr (request , "param" , None )[0 ][0 ][0 ]))
1530
+ file .write ('\n \n ' )
1531
+ file .write ('\n \n ' )
1532
+ #String
1533
+ file .write (repr (getattr (request , "param" , None )[1 ]))
1534
+ conn_type = getattr (request , "param" , None )[0 ]
1535
+ conn = request .getfixturevalue (str (getattr (request , "param" , None )[0 ][0 ][0 ]))
1536
+ uuid_value = getattr (request , "param" , None )[1 ]
1537
+ yield conn
1538
+ # clean_tables()
1539
+ with open ("a.txt" , "w" ) as file :
1540
+ file .write ('\n \n ' )
1541
+ file .write (repr (conn ))
1542
+
1543
+ for view in filter_get_all_tables (conn , uuid_value ):
1544
+ drop_view (view , conn )
1545
+ for tbl in filter_get_all_tables (conn , uuid_value ):
1546
+ drop_table (tbl , conn )
1547
+
1548
+
1549
+ @pytest .mark .parametrize ("conn" , setup (postgresql_connectable , "test_read_view_postgres" ), indirect = True )
1550
+ @pytest .mark .parametrize ("create_uuid" , ["test_read_view_postgres" ], indirect = True )
1551
+ def test_read_view_postgres (conn , create_uuid , request ):
1474
1552
# GH 52969
1475
- conn = request .getfixturevalue (conn )
1553
+ # conn = request.getfixturevalue(conn)
1554
+
1555
+ # def run_test():
1476
1556
1477
1557
from sqlalchemy .engine import Engine
1478
1558
from sqlalchemy .sql import text
1479
1559
1480
- table_name = create_unique_table_name ("group" )
1481
- view_name = create_unique_table_name ("group_view" )
1560
+ view_name = table_name = create_uuid
1561
+ # view_name = "view_"+create_uuid
1562
+
1563
+ with open ("blah.txt" , "w" ) as file :
1564
+ file .write ('\n ' )
1565
+ file .write (repr (table_name ))
1566
+ table_name = "table_" + create_uuid
1567
+ file .write ('\n ' )
1568
+ file .write (repr (table_name ))
1482
1569
1483
1570
sql_stmt = text (
1484
1571
f"""
@@ -1493,6 +1580,7 @@ def test_read_view_postgres(conn, request):
1493
1580
SELECT * FROM { table_name } ;
1494
1581
"""
1495
1582
)
1583
+ request
1496
1584
if isinstance (conn , Engine ):
1497
1585
with conn .connect () as con :
1498
1586
with con .begin ():
0 commit comments