@@ -42,12 +42,15 @@ def _mock_x402_client():
4242def _make_registry_connection (* , registry = None , http_factory = None ):
4343 """Build a RegistryTEEConnection with patched externals."""
4444 factory = http_factory or FakeHTTPClient
45- with patch (
46- "src.opengradient.client.tee_connection.x402HttpxClient" ,
47- side_effect = factory ,
48- ), patch (
49- "src.opengradient.client.tee_connection.build_ssl_context_from_der" ,
50- return_value = MagicMock (spec = ssl .SSLContext ),
45+ with (
46+ patch (
47+ "src.opengradient.client.tee_connection.x402HttpxClient" ,
48+ side_effect = factory ,
49+ ),
50+ patch (
51+ "src.opengradient.client.tee_connection.build_ssl_context_from_der" ,
52+ return_value = MagicMock (spec = ssl .SSLContext ),
53+ ),
5154 ):
5255 return RegistryTEEConnection (
5356 x402_client = _mock_x402_client (),
@@ -182,12 +185,15 @@ def make_client(*args, **kwargs):
182185
183186 mock_reg = _mock_registry_with_tee ()
184187
185- with patch (
186- "src.opengradient.client.tee_connection.x402HttpxClient" ,
187- side_effect = make_client ,
188- ), patch (
189- "src.opengradient.client.tee_connection.build_ssl_context_from_der" ,
190- return_value = MagicMock (spec = ssl .SSLContext ),
188+ with (
189+ patch (
190+ "src.opengradient.client.tee_connection.x402HttpxClient" ,
191+ side_effect = make_client ,
192+ ),
193+ patch (
194+ "src.opengradient.client.tee_connection.build_ssl_context_from_der" ,
195+ return_value = MagicMock (spec = ssl .SSLContext ),
196+ ),
191197 ):
192198 conn = RegistryTEEConnection (
193199 x402_client = _mock_x402_client (),
@@ -199,7 +205,6 @@ def make_client(*args, **kwargs):
199205 assert conn .get ().http_client is not old_client
200206 assert len (clients_created ) == 2
201207
202-
203208 async def test_reconnect_swallows_close_failure (self ):
204209 mock_reg = _mock_registry_with_tee ()
205210 conn = _make_registry_connection (registry = mock_reg )
@@ -224,7 +229,13 @@ def slow_connect(self):
224229 mock_reg = _mock_registry_with_tee ()
225230 conn = _make_registry_connection (registry = mock_reg )
226231
227- with patch .object (RegistryTEEConnection , "_connect" , slow_connect ):
232+ with patch .object (RegistryTEEConnection , "_connect" , slow_connect ), patch (
233+ "src.opengradient.client.tee_connection.build_ssl_context_from_der" ,
234+ return_value = MagicMock (spec = ssl .SSLContext ),
235+ ), patch (
236+ "src.opengradient.client.tee_connection.x402HttpxClient" ,
237+ side_effect = FakeHTTPClient ,
238+ ):
228239 await asyncio .gather (conn .reconnect (), conn .reconnect ())
229240
230241 assert call_order == ["start" , "end" , "start" , "end" ]
0 commit comments