@@ -279,7 +279,7 @@ def test_executemany_comment(self):
279
279
connect_module = mock .MagicMock ()
280
280
connect_module .__name__ = "test"
281
281
connect_module .__version__ = mock .MagicMock ()
282
- connect_module .__libpq_version__ = 123
282
+ connect_module .pq . version . return_value = 123
283
283
connect_module .apilevel = 123
284
284
connect_module .threadsafety = 123
285
285
connect_module .paramstyle = "test"
@@ -312,7 +312,7 @@ def test_executemany_comment_stmt_enabled(self):
312
312
connect_module = mock .MagicMock ()
313
313
connect_module .__name__ = "test"
314
314
connect_module .__version__ = mock .MagicMock ()
315
- connect_module .__libpq_version__ = 123
315
+ connect_module .pq . version . return_value = 123
316
316
connect_module .apilevel = 123
317
317
connect_module .threadsafety = 123
318
318
connect_module .paramstyle = "test"
@@ -420,7 +420,7 @@ def test_executemany_comment_stmt_enabled_matches_db_statement_attribute(
420
420
):
421
421
connect_module = mock .MagicMock ()
422
422
connect_module .__version__ = mock .MagicMock ()
423
- connect_module .__libpq_version__ = 123
423
+ connect_module .pq . version . return_value = 123
424
424
connect_module .apilevel = 123
425
425
connect_module .threadsafety = 123
426
426
connect_module .paramstyle = "test"
@@ -564,6 +564,7 @@ def test_executemany_psycopg2_integration_comment(self):
564
564
connect_module = mock .MagicMock ()
565
565
connect_module .__name__ = "psycopg2"
566
566
connect_module .__version__ = "1.2.3"
567
+ connect_module .pq .version .side_effect = AttributeError
567
568
connect_module .__libpq_version__ = 123
568
569
connect_module .apilevel = 123
569
570
connect_module .threadsafety = 123
@@ -597,6 +598,7 @@ def test_executemany_psycopg2_integration_comment_stmt_enabled(self):
597
598
connect_module = mock .MagicMock ()
598
599
connect_module .__name__ = "psycopg2"
599
600
connect_module .__version__ = "1.2.3"
601
+ connect_module .pq .version .side_effect = AttributeError
600
602
connect_module .__libpq_version__ = 123
601
603
connect_module .apilevel = 123
602
604
connect_module .threadsafety = 123
@@ -934,7 +936,7 @@ def test_executemany_flask_integration_comment(self):
934
936
sqlcommenter_context = context .set_value (
935
937
"SQLCOMMENTER_ORM_TAGS_AND_VALUES" , {"flask" : 1 }, current_context
936
938
)
937
- context .attach (sqlcommenter_context )
939
+ token = context .attach (sqlcommenter_context )
938
940
939
941
mock_connection = db_integration .wrapped_connection (
940
942
mock_connect , {}, {}
@@ -953,16 +955,13 @@ def test_executemany_flask_integration_comment(self):
953
955
"Select 1;" ,
954
956
)
955
957
956
- clear_context = context .set_value (
957
- "SQLCOMMENTER_ORM_TAGS_AND_VALUES" , {}, current_context
958
- )
959
- context .attach (clear_context )
958
+ context .detach (token )
960
959
961
960
def test_executemany_flask_integration_comment_stmt_enabled (self ):
962
961
connect_module = mock .MagicMock ()
963
962
connect_module .__name__ = "test"
964
963
connect_module .__version__ = mock .MagicMock ()
965
- connect_module .__libpq_version__ = 123
964
+ connect_module .pq . version . return_value = 123
966
965
connect_module .apilevel = 123
967
966
connect_module .threadsafety = 123
968
967
connect_module .paramstyle = "test"
@@ -979,7 +978,7 @@ def test_executemany_flask_integration_comment_stmt_enabled(self):
979
978
sqlcommenter_context = context .set_value (
980
979
"SQLCOMMENTER_ORM_TAGS_AND_VALUES" , {"flask" : 1 }, current_context
981
980
)
982
- context .attach (sqlcommenter_context )
981
+ token = context .attach (sqlcommenter_context )
983
982
984
983
mock_connection = db_integration .wrapped_connection (
985
984
mock_connect , {}, {}
@@ -998,10 +997,7 @@ def test_executemany_flask_integration_comment_stmt_enabled(self):
998
997
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',flask=1,libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
999
998
)
1000
999
1001
- clear_context = context .set_value (
1002
- "SQLCOMMENTER_ORM_TAGS_AND_VALUES" , {}, current_context
1003
- )
1004
- context .attach (clear_context )
1000
+ context .detach (token )
1005
1001
1006
1002
def test_callproc (self ):
1007
1003
db_integration = dbapi .DatabaseApiIntegration (
@@ -1126,7 +1122,7 @@ def test_non_string_sql_conversion(self):
1126
1122
connect_module = mock .MagicMock ()
1127
1123
connect_module .__name__ = "test"
1128
1124
connect_module .__version__ = "1.0"
1129
- connect_module .__libpq_version__ = 123
1125
+ connect_module .pq . version . return_value = 123
1130
1126
connect_module .apilevel = "2.0"
1131
1127
connect_module .threadsafety = 1
1132
1128
connect_module .paramstyle = "test"
0 commit comments