Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi committed Oct 17, 2024
1 parent ea17a2a commit 408dc1b
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ def test_instrument_connection(self, mock_connect):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)

@mock.patch("opentelemetry.instrumentation.dbapi.instrument_connection")
@mock.patch("pymysql.connect")
# pylint: disable=unused-argument
def test_instrument_connection_enable_commenter(
self,
mock_connect,
mock_instrument_connection,
):
cnx = pymysql.connect(database="test")
cnx = PyMySQLInstrumentor().instrument_connection(
cnx,
enable_commenter=True,
commenter_options={"foo": True},
)
cursor = cnx.cursor()
cursor.execute("SELECT * FROM test")
kwargs = mock_instrument_connection.call_args[1]
self.assertEqual(kwargs["enable_commenter"], True)
self.assertEqual(kwargs["commenter_options"], {"foo": True})

@mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect")
@mock.patch("pymysql.connect")
# pylint: disable=unused-argument
def test__instrument_enable_commenter(
self,
mock_connect,
mock_wrap_connect,
):
PyMySQLInstrumentor()._instrument(
enable_commenter=True,
commenter_options={"foo": True},
)
kwargs = mock_wrap_connect.call_args[1]
self.assertEqual(kwargs["enable_commenter"], True)
self.assertEqual(kwargs["commenter_options"], {"foo": True})

@mock.patch("pymysql.connect")
# pylint: disable=unused-argument
def test_uninstrument_connection(self, mock_connect):
Expand Down

0 comments on commit 408dc1b

Please sign in to comment.