77async def test_502_html_handling ():
88 """Test that 502 errors with HTML bodies are sanitized"""
99 config = {"api_key" : "test_key" , "api_url" : "https://api.test.com" }
10- engine = LingoDotDevEngine (config )
1110
1211 html_body = """<html><body><h1>502 Bad Gateway</h1></body></html>"""
1312
@@ -22,8 +21,9 @@ async def test_502_html_handling():
2221 ) # simulating non-JSON response
2322 mock_post .return_value = mock_response
2423
25- with pytest .raises (RuntimeError ) as exc_info :
26- await engine .localize_text ("hello" , {"target_locale" : "es" })
24+ async with LingoDotDevEngine (config ) as engine :
25+ with pytest .raises (RuntimeError ) as exc_info :
26+ await engine .localize_text ("hello" , {"target_locale" : "es" })
2727
2828 error_msg = str (exc_info .value )
2929
@@ -38,8 +38,6 @@ async def test_502_html_handling():
3838async def test_500_json_handling ():
3939 """Test that 500 errors with JSON bodies are preserved"""
4040 config = {"api_key" : "test_key" , "api_url" : "https://api.test.com" }
41- engine = LingoDotDevEngine (config )
42-
4341 error_json = {"error" : "Specific internal error message" }
4442
4543 with patch ("lingodotdev.engine.httpx.AsyncClient.post" ) as mock_post :
@@ -50,8 +48,9 @@ async def test_500_json_handling():
5048 mock_response .json .return_value = error_json
5149 mock_post .return_value = mock_response
5250
53- with pytest .raises (RuntimeError ) as exc_info :
54- await engine .localize_text ("hello" , {"target_locale" : "es" })
51+ async with LingoDotDevEngine (config ) as engine :
52+ with pytest .raises (RuntimeError ) as exc_info :
53+ await engine .localize_text ("hello" , {"target_locale" : "es" })
5554
5655 error_msg = str (exc_info .value )
5756
0 commit comments