Skip to content

Commit 8020903

Browse files
fix: restore all changes - comment_position, tests, pylint disable, CommentPositionT
1 parent f88ddcc commit 8020903

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,59 @@ def test_executemany_comment(self):
342342
cursor = mock_connection.cursor()
343343
cursor.executemany("Select 1;")
344344
self.assertRegex(
345+
346+
def test_executemany_comment_position_start(self):
347+
connect_module = mock.MagicMock()
348+
connect_module.__name__ = "test"
349+
connect_module.__version__ = mock.MagicMock()
350+
connect_module.pq.version.return_value = 123
351+
connect_module.apilevel = 123
352+
connect_module.threadsafety = 123
353+
connect_module.paramstyle = "test"
354+
355+
db_integration = dbapi.DatabaseApiIntegration(
356+
"instrumenting_module_test_name",
357+
"postgresql",
358+
enable_commenter=True,
359+
commenter_options={"db_driver": False, "dbapi_level": False},
360+
connect_module=connect_module,
361+
comment_position="start",
362+
)
363+
mock_connection = db_integration.wrapped_connection(
364+
mock_connect, {}, {}
365+
)
366+
cursor = mock_connection.cursor()
367+
cursor.executemany("Select 1;")
368+
self.assertRegex(
369+
cursor.query,
370+
r"/\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/ Select 1;",
371+
)
372+
373+
def test_executemany_comment_position_end_default(self):
374+
connect_module = mock.MagicMock()
375+
connect_module.__name__ = "test"
376+
connect_module.__version__ = mock.MagicMock()
377+
connect_module.pq.version.return_value = 123
378+
connect_module.apilevel = 123
379+
connect_module.threadsafety = 123
380+
connect_module.paramstyle = "test"
381+
382+
db_integration = dbapi.DatabaseApiIntegration(
383+
"instrumenting_module_test_name",
384+
"postgresql",
385+
enable_commenter=True,
386+
commenter_options={"db_driver": False, "dbapi_level": False},
387+
connect_module=connect_module,
388+
)
389+
mock_connection = db_integration.wrapped_connection(
390+
mock_connect, {}, {}
391+
)
392+
cursor = mock_connection.cursor()
393+
cursor.executemany("Select 1;")
394+
self.assertRegex(
395+
cursor.query,
396+
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
397+
)
345398
cursor.query,
346399
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
347400
)

0 commit comments

Comments
 (0)