Skip to content

Commit 3cc19d6

Browse files
committed
test: add test to cover new changes from jxmorris12#210 jxmorris12#211 jxmorris12#212 jxmorris12#213
1 parent 2c5fe23 commit 3cc19d6

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎tests/unit/test_match.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ def test_four_byte_char_adjustment(self) -> None:
106106
adjusted_offset = 2
107107
assert m.offset == adjusted_offset
108108

109+
def test_four_byte_char_after_match_is_not_counted(self) -> None:
110+
"""A 4-byte emoji after the match does not shift the offset."""
111+
# "🌅" at position 6 is after the match at offset 0, so the adjustment
112+
# loop must break on its first iteration instead of counting it.
113+
text = "hello 🌅"
114+
attrib = _make_attrib(
115+
offset=0,
116+
length=5,
117+
context_text=text,
118+
context_offset=0,
119+
sentence=text,
120+
)
121+
m = Match(attrib, four_byte_char_positions(text))
122+
assert m.offset == 0
123+
109124
def test_no_adjustment_without_four_byte_chars(self) -> None:
110125
"""Offsets are unchanged when no 4-byte characters precede the match."""
111126
text = "Hello world today"

‎tests/unit/test_server_unit.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

943965
class TestStartLocalServer:
944966
"""Tests for _start_local_server() PathError branch."""

0 commit comments

Comments
 (0)