2424class TestMcpInstrumentorInit (unittest .TestCase ):
2525 """Test McpInstrumentor initialization."""
2626
27- def test_init_default (self ):
27+ def test_init_default (self ) -> None :
2828 """Test default initialization."""
2929 instrumentor = McpInstrumentor ()
3030 self .assertIsNotNone (instrumentor )
3131 self .assertIsNotNone (instrumentor .tracer )
3232 self .assertIsNotNone (instrumentor .propagators )
3333
34- def test_init_with_tracer_provider (self ):
34+ def test_init_with_tracer_provider (self ) -> None :
3535 """Test initialization with custom tracer provider."""
3636 mock_provider = MagicMock (spec = TracerProvider )
3737 mock_tracer = MagicMock ()
@@ -42,7 +42,7 @@ def test_init_with_tracer_provider(self):
4242 instrumentor = McpInstrumentor (tracer_provider = mock_provider )
4343 self .assertIsNotNone (instrumentor .tracer )
4444
45- def test_init_with_propagators (self ):
45+ def test_init_with_propagators (self ) -> None :
4646 """Test initialization with custom propagators."""
4747 mock_propagators = MagicMock ()
4848 instrumentor = McpInstrumentor (propagators = mock_propagators )
@@ -52,7 +52,7 @@ def test_init_with_propagators(self):
5252class TestMcpInstrumentorDependencies (unittest .TestCase ):
5353 """Test instrumentation dependencies."""
5454
55- def test_instrumentation_dependencies (self ):
55+ def test_instrumentation_dependencies (self ) -> None :
5656 """Test that instrumentation_dependencies returns correct packages."""
5757 instrumentor = McpInstrumentor ()
5858 deps = instrumentor .instrumentation_dependencies ()
@@ -70,15 +70,17 @@ def setUp(self):
7070 @patch (
7171 "opentelemetry.instrumentation.mcp.instrumentation.register_post_import_hook"
7272 )
73- def test_instrument_registers_hooks (self , mock_register ):
73+ def test_instrument_registers_hooks (self , mock_register : MagicMock ):
7474 """Test that _instrument registers all required hooks."""
7575 self .instrumentor ._instrument ()
7676 self .assertEqual (mock_register .call_count , 4 )
7777
7878 @patch (
7979 "opentelemetry.instrumentation.mcp.instrumentation.register_post_import_hook"
8080 )
81- def test_instrument_registers_session_hooks (self , mock_register ):
81+ def test_instrument_registers_session_hooks (
82+ self , mock_register : MagicMock
83+ ):
8284 """Test that _instrument registers session hooks."""
8385 self .instrumentor ._instrument ()
8486 # Verify mcp.shared.session is registered (appears twice for send_request and send_notification)
@@ -92,7 +94,7 @@ def test_instrument_registers_session_hooks(self, mock_register):
9294 @patch (
9395 "opentelemetry.instrumentation.mcp.instrumentation.register_post_import_hook"
9496 )
95- def test_instrument_registers_server_hooks (self , mock_register ):
97+ def test_instrument_registers_server_hooks (self , mock_register : MagicMock ):
9698 """Test that _instrument registers server hooks."""
9799 self .instrumentor ._instrument ()
98100 # Verify mcp.server.lowlevel.server is registered (appears twice for _handle_request and _handle_notification)
@@ -111,37 +113,41 @@ def setUp(self):
111113 self .instrumentor = McpInstrumentor ()
112114
113115 @patch ("opentelemetry.instrumentation.mcp.instrumentation.unwrap" )
114- def test_uninstrument_unwraps_all (self , mock_unwrap ):
116+ def test_uninstrument_unwraps_all (self , mock_unwrap : MagicMock ):
115117 """Test that _uninstrument unwraps all hooks."""
116118 self .instrumentor ._uninstrument ()
117119 self .assertEqual (mock_unwrap .call_count , 4 )
118120
119121 @patch ("opentelemetry.instrumentation.mcp.instrumentation.unwrap" )
120- def test_uninstrument_unwraps_send_request (self , mock_unwrap ):
122+ def test_uninstrument_unwraps_send_request (self , mock_unwrap : MagicMock ):
121123 """Test that _uninstrument unwraps send_request."""
122124 self .instrumentor ._uninstrument ()
123125 mock_unwrap .assert_any_call (
124126 "mcp.shared.session" , "BaseSession.send_request"
125127 )
126128
127129 @patch ("opentelemetry.instrumentation.mcp.instrumentation.unwrap" )
128- def test_uninstrument_unwraps_send_notification (self , mock_unwrap ):
130+ def test_uninstrument_unwraps_send_notification (
131+ self , mock_unwrap : MagicMock
132+ ):
129133 """Test that _uninstrument unwraps send_notification."""
130134 self .instrumentor ._uninstrument ()
131135 mock_unwrap .assert_any_call (
132136 "mcp.shared.session" , "BaseSession.send_notification"
133137 )
134138
135139 @patch ("opentelemetry.instrumentation.mcp.instrumentation.unwrap" )
136- def test_uninstrument_unwraps_handle_request (self , mock_unwrap ):
140+ def test_uninstrument_unwraps_handle_request (self , mock_unwrap : MagicMock ):
137141 """Test that _uninstrument unwraps handle_request."""
138142 self .instrumentor ._uninstrument ()
139143 mock_unwrap .assert_any_call (
140144 "mcp.server.lowlevel.server" , "Server._handle_request"
141145 )
142146
143147 @patch ("opentelemetry.instrumentation.mcp.instrumentation.unwrap" )
144- def test_uninstrument_unwraps_handle_notification (self , mock_unwrap ):
148+ def test_uninstrument_unwraps_handle_notification (
149+ self , mock_unwrap : MagicMock
150+ ):
145151 """Test that _uninstrument unwraps handle_notification."""
146152 self .instrumentor ._uninstrument ()
147153 mock_unwrap .assert_any_call (
@@ -152,33 +158,33 @@ def test_uninstrument_unwraps_handle_notification(self, mock_unwrap):
152158class TestMcpInstrumentorSerialize (unittest .TestCase ):
153159 """Test serialize static method."""
154160
155- def test_serialize_simple_dict (self ):
161+ def test_serialize_simple_dict (self ) -> None :
156162 """Test serializing a simple dictionary."""
157163 result = McpInstrumentor .serialize ({"key" : "value" })
158164 self .assertEqual (result , '{"key": "value"}' )
159165
160- def test_serialize_nested_dict (self ):
166+ def test_serialize_nested_dict (self ) -> None :
161167 """Test serializing a nested dictionary."""
162168 result = McpInstrumentor .serialize ({"outer" : {"inner" : "value" }})
163169 self .assertEqual (result , '{"outer": {"inner": "value"}}' )
164170
165- def test_serialize_with_numbers (self ):
171+ def test_serialize_with_numbers (self ) -> None :
166172 """Test serializing dictionary with numbers."""
167173 result = McpInstrumentor .serialize ({"int" : 42 , "float" : 3.14 })
168174 self .assertIn ('"int": 42' , result )
169175 self .assertIn ('"float": 3.14' , result )
170176
171- def test_serialize_with_list (self ):
177+ def test_serialize_with_list (self ) -> None :
172178 """Test serializing dictionary with list."""
173179 result = McpInstrumentor .serialize ({"list" : [1 , 2 , 3 ]})
174180 self .assertEqual (result , '{"list": [1, 2, 3]}' )
175181
176- def test_serialize_empty_dict (self ):
182+ def test_serialize_empty_dict (self ) -> None :
177183 """Test serializing empty dictionary."""
178184 result = McpInstrumentor .serialize ({})
179185 self .assertEqual (result , "{}" )
180186
181- def test_serialize_non_serializable (self ):
187+ def test_serialize_non_serializable (self ) -> None :
182188 """Test serializing non-serializable object returns empty string."""
183189
184190 class NonSerializable :
@@ -187,12 +193,12 @@ class NonSerializable:
187193 result = McpInstrumentor .serialize ({"obj" : NonSerializable ()})
188194 self .assertEqual (result , "" )
189195
190- def test_serialize_with_none (self ):
196+ def test_serialize_with_none (self ) -> None :
191197 """Test serializing dictionary with None value."""
192198 result = McpInstrumentor .serialize ({"key" : None })
193199 self .assertEqual (result , '{"key": null}' )
194200
195- def test_serialize_with_boolean (self ):
201+ def test_serialize_with_boolean (self ) -> None :
196202 """Test serializing dictionary with boolean values."""
197203 result = McpInstrumentor .serialize ({"true" : True , "false" : False })
198204 self .assertIn ('"true": true' , result )
0 commit comments