@@ -882,6 +882,16 @@ def test_raises_rate_limit_error_on_http_426(self) -> None:
882882 with pytest .raises (RateLimitError ):
883883 lt ._query_server ("http://fake/" , num_tries = 1 )
884884
885+ def test_raises_rate_limit_error_on_http_426_with_valid_json (self ) -> None :
886+ """RateLimitError is raised on HTTP 426 even when the body is valid JSON."""
887+ r = _make_json_response (
888+ b'{"error": "rate limited"}' , status_code = _HTTP_RATE_LIMIT_STATUS
889+ )
890+ lt = _bare_lt (_remote = True )
891+ lt ._session = _MockSession (get_response = r )
892+ with pytest .raises (RateLimitError ):
893+ lt ._query_server ("http://fake/" , num_tries = 1 )
894+
885895 def test_returns_none_with_zero_tries (self ) -> None :
886896 """Returns None immediately when num_tries=0 (loop never executes)."""
887897 lt = _bare_lt ()
@@ -939,6 +949,18 @@ def close(self) -> None:
939949 lt ._terminate_server ()
940950 assert mock_stdin .closed
941951
952+ def test_does_not_raise_when_process_not_in_running_list (self ) -> None :
953+ """_terminate_server() does not raise if the process is absent from the list."""
954+ mock_proc = _MockProcess (poll_return = None )
955+ lt = _bare_lt ()
956+ lt ._server = mock_proc # type: ignore[assignment]
957+ with (
958+ patch ("language_tool_python.server._RUNNING_SERVER_PROCESSES" , []),
959+ patch ("language_tool_python.server._kill_processes" ),
960+ ):
961+ lt ._terminate_server ()
962+ assert lt ._server is None
963+
942964
943965class TestStartLocalServer :
944966 """Tests for _start_local_server() PathError branch."""
0 commit comments