@@ -459,35 +459,44 @@ def test_detach_archive(pgmq_fixture, db_session):
459459 msg = MSG
460460 msg_id = pgmq .send (queue_name , msg )
461461 pgmq .archive (queue_name , msg_id )
462-
462+
463463 # Detach archive should not raise an error
464464 pgmq .detach_archive (queue_name )
465-
465+
466466 # Read the archive to ensure it still exists after detaching
467467 archived_msg = pgmq .read_archive (queue_name )
468468 assert archived_msg is not None
469469 assert archived_msg .msg_id == msg_id
470-
470+
471471 # Cleanup: Drop the archive and queue tables
472472 # After detaching, the archive is no longer part of the extension
473473 # We need to drop both tables manually by first removing them from the extension
474474 if pgmq .is_async :
475- import asyncio
475+
476476 async def cleanup ():
477477 async with pgmq .session_maker () as session :
478478 # Drop archive table (already detached)
479- await session .execute (text (f"DROP TABLE IF EXISTS pgmq.a_{ queue_name } CASCADE;" ))
479+ await session .execute (
480+ text (f"DROP TABLE IF EXISTS pgmq.a_{ queue_name } CASCADE;" )
481+ )
480482 # Detach and drop queue table
481- await session .execute (text (f"ALTER EXTENSION pgmq DROP TABLE pgmq.q_{ queue_name } ;" ))
482- await session .execute (text (f"DROP TABLE IF EXISTS pgmq.q_{ queue_name } CASCADE;" ))
483+ await session .execute (
484+ text (f"ALTER EXTENSION pgmq DROP TABLE pgmq.q_{ queue_name } ;" )
485+ )
486+ await session .execute (
487+ text (f"DROP TABLE IF EXISTS pgmq.q_{ queue_name } CASCADE;" )
488+ )
483489 await session .commit ()
490+
484491 pgmq .loop .run_until_complete (cleanup ())
485492 else :
486493 with pgmq .session_maker () as session :
487494 # Drop archive table (already detached)
488495 session .execute (text (f"DROP TABLE IF EXISTS pgmq.a_{ queue_name } CASCADE;" ))
489496 # Detach and drop queue table
490- session .execute (text (f"ALTER EXTENSION pgmq DROP TABLE pgmq.q_{ queue_name } ;" ))
497+ session .execute (
498+ text (f"ALTER EXTENSION pgmq DROP TABLE pgmq.q_{ queue_name } ;" )
499+ )
491500 session .execute (text (f"DROP TABLE IF EXISTS pgmq.q_{ queue_name } CASCADE;" ))
492501 session .commit ()
493502
@@ -544,22 +553,30 @@ def test_read_archive_batch_limit(pgmq_setup_teardown: PGMQ_WITH_QUEUE):
544553def test_create_time_based_partitioned_queue (pgmq_fixture , db_session ):
545554 pgmq : PGMQueue = pgmq_fixture
546555 queue_name = f"test_queue_{ uuid .uuid4 ().hex } "
547- pgmq .create_partitioned_queue (queue_name , partition_interval = '1 day' , retention_interval = '7 days' )
556+ pgmq .create_partitioned_queue (
557+ queue_name , partition_interval = "1 day" , retention_interval = "7 days"
558+ )
548559 assert check_queue_exists (db_session , queue_name ) is True
549560
550561
551562@pgmq_deps
552- def test_create_time_based_partitioned_queue_various_intervals (pgmq_fixture , db_session ):
563+ def test_create_time_based_partitioned_queue_various_intervals (
564+ pgmq_fixture , db_session
565+ ):
553566 pgmq : PGMQueue = pgmq_fixture
554-
567+
555568 # Test with hour
556569 queue_name_hour = f"test_queue_{ uuid .uuid4 ().hex } "
557- pgmq .create_partitioned_queue (queue_name_hour , partition_interval = '1 hour' , retention_interval = '24 hours' )
570+ pgmq .create_partitioned_queue (
571+ queue_name_hour , partition_interval = "1 hour" , retention_interval = "24 hours"
572+ )
558573 assert check_queue_exists (db_session , queue_name_hour ) is True
559-
574+
560575 # Test with week
561576 queue_name_week = f"test_queue_{ uuid .uuid4 ().hex } "
562- pgmq .create_partitioned_queue (queue_name_week , partition_interval = '1 week' , retention_interval = '4 weeks' )
577+ pgmq .create_partitioned_queue (
578+ queue_name_week , partition_interval = "1 week" , retention_interval = "4 weeks"
579+ )
563580 assert check_queue_exists (db_session , queue_name_week ) is True
564581
565582
@@ -568,7 +585,11 @@ def test_create_partitioned_queue_invalid_time_interval(pgmq_fixture):
568585 pgmq : PGMQueue = pgmq_fixture
569586 queue_name = f"test_queue_{ uuid .uuid4 ().hex } "
570587 with pytest .raises (ValueError ) as e :
571- pgmq .create_partitioned_queue (queue_name , partition_interval = 'invalid interval' , retention_interval = '7 days' )
588+ pgmq .create_partitioned_queue (
589+ queue_name ,
590+ partition_interval = "invalid interval" ,
591+ retention_interval = "7 days" ,
592+ )
572593 assert "Invalid time-based partition interval" in str (e .value )
573594
574595
@@ -577,5 +598,7 @@ def test_create_partitioned_queue_invalid_numeric_interval(pgmq_fixture):
577598 pgmq : PGMQueue = pgmq_fixture
578599 queue_name = f"test_queue_{ uuid .uuid4 ().hex } "
579600 with pytest .raises (ValueError ) as e :
580- pgmq .create_partitioned_queue (queue_name , partition_interval = - 100 , retention_interval = 100000 )
601+ pgmq .create_partitioned_queue (
602+ queue_name , partition_interval = - 100 , retention_interval = 100000
603+ )
581604 assert "Numeric partition interval must be positive" in str (e .value )
0 commit comments