Enabled all Ruff lint rules and resolved findings with justified inline suppressions.
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 14s
CI / Tests (Python 3.13) (push) Successful in 14s
CI / Tests (Python 3.14) (push) Successful in 11s
CI / Type Checking (push) Successful in 10s
CI / Spelling (push) Successful in 5s
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 14s
CI / Tests (Python 3.13) (push) Successful in 14s
CI / Tests (Python 3.14) (push) Successful in 11s
CI / Type Checking (push) Successful in 10s
CI / Spelling (push) Successful in 5s
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Owlbot test suite."""
|
||||
@@ -116,6 +116,7 @@ class TestOnCommandDecorator:
|
||||
self,
|
||||
name: str,
|
||||
aliases: list[str] | None,
|
||||
*,
|
||||
auth: bool,
|
||||
mod: bool,
|
||||
cooldown: int,
|
||||
@@ -503,7 +504,7 @@ class TestCommandDispatcherDispatch:
|
||||
module_ctx = make_module_context(storage, module_name)
|
||||
|
||||
dispatcher = CommandDispatcher(
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
owncast_client=stub, # type: ignore[arg-type]
|
||||
handler_timeout=handler_timeout,
|
||||
loaded_modules=set(),
|
||||
@@ -761,7 +762,7 @@ class TestCommandDispatcherDispatch:
|
||||
row = await storage.fetch_one("SELECT * FROM items WHERE id = ?", (1,))
|
||||
assert row is not None
|
||||
assert row["name"] == "apple"
|
||||
assert "raised exception: boom" in caplog.text
|
||||
assert "raised exception." in caplog.text
|
||||
|
||||
async def test_timeout_is_logged(
|
||||
self, storage: ModuleStorage, caplog: pytest.LogCaptureFixture
|
||||
@@ -854,7 +855,7 @@ class TestCommandDispatcherDispatch:
|
||||
with caplog.at_level(logging.ERROR, logger="owlbot.commands"):
|
||||
await dispatcher.dispatch(_make_chat_event(body="!test"))
|
||||
|
||||
assert "raised exception: builtin-fail" in caplog.text
|
||||
assert "raised exception." in caplog.text
|
||||
|
||||
async def test_builtin_command_timeout(
|
||||
self, storage: ModuleStorage, caplog: pytest.LogCaptureFixture
|
||||
@@ -963,6 +964,7 @@ class TestModuleCommands:
|
||||
other_setup: str | None,
|
||||
call_module: str,
|
||||
trigger: str,
|
||||
*,
|
||||
expected: bool,
|
||||
) -> None:
|
||||
"""ModuleCommands.unregister respects ownership."""
|
||||
@@ -1059,7 +1061,7 @@ class TestCommandContext:
|
||||
],
|
||||
)
|
||||
def test_property_proxying(
|
||||
self, storage: ModuleStorage, prop: str, use_is: bool
|
||||
self, storage: ModuleStorage, prop: str, *, use_is: bool
|
||||
) -> None:
|
||||
"""CommandContext properties proxy to the underlying ModuleContext."""
|
||||
cmd_ctx, module_ctx, _, _ = self._make_command_context(storage)
|
||||
|
||||
@@ -540,7 +540,7 @@ class _StubModuleCommands:
|
||||
aliases: list[str] | tuple[str, ...] | None = None,
|
||||
requires_authenticated: bool = False,
|
||||
requires_moderator: bool = False,
|
||||
cooldown: int | float = 0,
|
||||
cooldown: int = 0,
|
||||
) -> None:
|
||||
all_new = {name} | set(aliases or [])
|
||||
for trigger in all_new:
|
||||
@@ -551,6 +551,7 @@ class _StubModuleCommands:
|
||||
self._registered[name] = {
|
||||
"handler": handler,
|
||||
"aliases": set(aliases or []),
|
||||
"requires_authenticated": requires_authenticated,
|
||||
"requires_moderator": requires_moderator,
|
||||
"cooldown": cooldown,
|
||||
}
|
||||
@@ -702,7 +703,7 @@ class TestManagerCreateCommand:
|
||||
cmd_ctx: ModuleContext,
|
||||
stub_commands: _StubModuleCommands,
|
||||
) -> None:
|
||||
"""If DB insert fails, the registry registration is rolled back."""
|
||||
"""If DB insert fails, the command is not registered."""
|
||||
# Create a manager with a repo whose storage is closed.
|
||||
closed_storage = ModuleStorage(None, "closed")
|
||||
bad_repo = CommandRepository(closed_storage)
|
||||
|
||||
@@ -229,7 +229,7 @@ class TestUser:
|
||||
pytest.param(["MOD", "MODERATOR"], True, id="moderator-among-others"),
|
||||
],
|
||||
)
|
||||
def test_is_moderator(self, scopes: list[str], expected: bool) -> None:
|
||||
def test_is_moderator(self, scopes: list[str], *, expected: bool) -> None:
|
||||
"""is_moderator reflects whether MODERATOR is in scopes."""
|
||||
user = User.from_dict({"scopes": scopes})
|
||||
assert user.is_moderator is expected
|
||||
|
||||
+23
-22
@@ -305,6 +305,7 @@ class TestEventRegistry:
|
||||
def test_unregister(
|
||||
self,
|
||||
setup_types: tuple[EventType, ...] | None,
|
||||
*,
|
||||
expected_return: bool,
|
||||
expected_remaining: int,
|
||||
) -> None:
|
||||
@@ -437,7 +438,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -466,7 +467,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(high_handler, (EventType.CHAT,), "mod_a", Priority.HIGH)
|
||||
@@ -492,7 +493,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(first, (EventType.CHAT,), "mod_a", Priority.NORMAL)
|
||||
@@ -511,7 +512,7 @@ class TestEventDispatcherDispatch:
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
with caplog.at_level(logging.DEBUG, logger="owlbot.events"):
|
||||
@@ -539,7 +540,7 @@ class TestEventDispatcherDispatch:
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
chat_event = _make_chat_event(body="hello")
|
||||
@@ -567,7 +568,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(handler_a, (EventType.CHAT,), "mod_a", Priority.HIGH)
|
||||
@@ -593,7 +594,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(handler_a, (EventType.CHAT,), "mod_a", Priority.HIGH)
|
||||
@@ -624,7 +625,7 @@ class TestEventDispatcherDispatch:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(stopper, (EventType.CHAT,), "mod_a", Priority.HIGH)
|
||||
@@ -657,7 +658,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -687,7 +688,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -697,7 +698,7 @@ class TestEventDispatcherStorage:
|
||||
row = await storage.fetch_one("SELECT val FROM test_tbl")
|
||||
assert row is not None
|
||||
assert row[0] == "persisted"
|
||||
assert any("raised exception: boom" in r.message for r in caplog.records)
|
||||
assert any("raised exception." in r.message for r in caplog.records)
|
||||
|
||||
async def test_exception_does_not_stop_next_handler(
|
||||
self, storage: ModuleStorage
|
||||
@@ -719,7 +720,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(failing_handler, (EventType.CHAT,), "mod_a", Priority.HIGH)
|
||||
@@ -742,7 +743,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=0.05,
|
||||
)
|
||||
dispatcher.register(slow_handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -772,7 +773,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=0.05,
|
||||
)
|
||||
dispatcher.register(slow_handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -802,7 +803,7 @@ class TestEventDispatcherStorage:
|
||||
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=0.05,
|
||||
)
|
||||
dispatcher.register(slow_handler, (EventType.CHAT,), "mod_a")
|
||||
@@ -820,7 +821,7 @@ class TestCommandDispatchPhase:
|
||||
[
|
||||
pytest.param(
|
||||
EventType.CHAT,
|
||||
lambda: _make_chat_event(),
|
||||
_make_chat_event,
|
||||
1,
|
||||
id="chat-triggers",
|
||||
),
|
||||
@@ -853,7 +854,7 @@ class TestCommandDispatchPhase:
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
event = event_factory()
|
||||
@@ -877,7 +878,7 @@ class TestCommandDispatchPhase:
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
dispatcher.register(stopper, (EventType.CHAT,), "mod_a")
|
||||
@@ -899,12 +900,12 @@ class TestCommandDispatchPhase:
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
dispatcher = EventDispatcher(
|
||||
command_dispatch=command_dispatch,
|
||||
get_module_context=lambda name: module_ctx,
|
||||
get_module_context=lambda _name: module_ctx,
|
||||
handler_timeout=5.0,
|
||||
)
|
||||
with caplog.at_level(logging.ERROR, logger="owlbot.events"):
|
||||
await dispatcher.dispatch(EventType.CHAT, _make_chat_event())
|
||||
assert any("Command dispatch failed: fail" in r.message for r in caplog.records)
|
||||
assert any("Command dispatch failed." in r.message for r in caplog.records)
|
||||
|
||||
|
||||
class TestModuleEvents:
|
||||
@@ -974,7 +975,7 @@ class TestModuleEvents:
|
||||
],
|
||||
)
|
||||
def test_unregister(
|
||||
self, register_on: str | None, unregister_from: str, expected: bool
|
||||
self, register_on: str | None, unregister_from: str, *, expected: bool
|
||||
) -> None:
|
||||
"""ModuleEvents.unregister() respects ownership checks."""
|
||||
|
||||
@@ -1061,7 +1062,7 @@ class TestEventContext:
|
||||
],
|
||||
)
|
||||
def test_property_proxying(
|
||||
self, storage: ModuleStorage, prop: str, use_is: bool
|
||||
self, storage: ModuleStorage, prop: str, *, use_is: bool
|
||||
) -> None:
|
||||
"""EventContext properties proxy to the underlying ModuleContext."""
|
||||
module_ctx = make_module_context(storage, "mod_a")
|
||||
|
||||
+17
-14
@@ -24,6 +24,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import types
|
||||
from http import HTTPStatus
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import pytest
|
||||
@@ -86,6 +87,7 @@ class TestOnRouteDecorator:
|
||||
self,
|
||||
path: str,
|
||||
methods: list[str] | None,
|
||||
*,
|
||||
streaming: bool,
|
||||
expected_path: str,
|
||||
expected_methods: list[str] | None,
|
||||
@@ -123,7 +125,7 @@ class TestRouteInfo:
|
||||
pytest.param(False, id="streaming-false"),
|
||||
],
|
||||
)
|
||||
def test_stores_streaming(self, streaming: bool) -> None:
|
||||
def test_stores_streaming(self, *, streaming: bool) -> None:
|
||||
"""RouteInfo stores the streaming flag."""
|
||||
info = RouteInfo(
|
||||
path="/x",
|
||||
@@ -506,7 +508,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "api"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 200
|
||||
assert response.status == HTTPStatus.OK
|
||||
assert response.content_type == "application/json"
|
||||
|
||||
async def test_dispatch_web_response(self) -> None:
|
||||
@@ -523,7 +525,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "page"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 201
|
||||
assert response.status == HTTPStatus.CREATED
|
||||
|
||||
async def test_dispatch_none_response(self) -> None:
|
||||
"""Handler returning None produces 204 No Content."""
|
||||
@@ -539,7 +541,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "hook"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 204
|
||||
assert response.status == HTTPStatus.NO_CONTENT
|
||||
|
||||
async def test_dispatch_404(self) -> None:
|
||||
"""Dispatch to unregistered path returns 404."""
|
||||
@@ -550,7 +552,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "nope"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 404
|
||||
assert response.status == HTTPStatus.NOT_FOUND
|
||||
|
||||
async def test_dispatch_405(self) -> None:
|
||||
"""Dispatch with wrong method returns 405 with Allow header."""
|
||||
@@ -562,7 +564,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "data"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 405
|
||||
assert response.status == HTTPStatus.METHOD_NOT_ALLOWED
|
||||
assert "GET" in response.headers["Allow"]
|
||||
|
||||
async def test_dispatch_handler_exception(self) -> None:
|
||||
@@ -579,7 +581,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "bad"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 500
|
||||
assert response.status == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
async def test_dispatch_unsupported_return_type(self) -> None:
|
||||
"""Handler returning unsupported type produces 500."""
|
||||
@@ -595,7 +597,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "bad"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 500
|
||||
assert response.status == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
async def test_dispatch_timeout(self) -> None:
|
||||
"""Non-streaming handler exceeding timeout returns 500."""
|
||||
@@ -612,7 +614,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "slow"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 500
|
||||
assert response.status == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
async def test_dispatch_streaming_bypasses_timeout(self) -> None:
|
||||
"""Streaming handler exceeding timeout is not cancelled."""
|
||||
@@ -629,7 +631,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "stream"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 200
|
||||
assert response.status == HTTPStatus.OK
|
||||
|
||||
async def test_dispatch_streaming_exception(self) -> None:
|
||||
"""Streaming handler that raises returns 500."""
|
||||
@@ -645,7 +647,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "bad"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 500
|
||||
assert response.status == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
async def test_dispatch_streaming_normal_return(self) -> None:
|
||||
"""Streaming handler returning dict produces JSON response."""
|
||||
@@ -661,7 +663,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = "fast"
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 200
|
||||
assert response.status == HTTPStatus.OK
|
||||
|
||||
async def test_dispatch_path_params(self) -> None:
|
||||
"""Path parameters are populated in RouteContext.match_info."""
|
||||
@@ -695,7 +697,7 @@ class TestRouteDispatcherDispatch:
|
||||
request.match_info["path"] = ""
|
||||
|
||||
response = await dispatcher.dispatch(request)
|
||||
assert response.status == 200
|
||||
assert response.status == HTTPStatus.OK
|
||||
|
||||
|
||||
class TestRouteDispatcherDrainHandlers:
|
||||
@@ -1012,6 +1014,7 @@ class TestModuleRoutes:
|
||||
)
|
||||
def test_exists(
|
||||
self,
|
||||
*,
|
||||
register: bool,
|
||||
check_method: str | None,
|
||||
expected: bool,
|
||||
@@ -1084,7 +1087,7 @@ class TestRouteContext:
|
||||
pytest.param("templates", True, id="templates"),
|
||||
],
|
||||
)
|
||||
def test_property_proxying(self, prop: str, use_is: bool) -> None:
|
||||
def test_property_proxying(self, prop: str, *, use_is: bool) -> None:
|
||||
"""RouteContext properties proxy to the underlying ModuleContext."""
|
||||
ctx, module_ctx = self._make_route_context()
|
||||
ctx_val = getattr(ctx, prop)
|
||||
|
||||
@@ -52,7 +52,7 @@ class _StubOwncastClient:
|
||||
self.sent: list[str] = []
|
||||
self._fail = fail
|
||||
|
||||
async def send_message(self, body: str, *, unsanitized: bool = False) -> str:
|
||||
async def send_message(self, body: str, **_kwargs: bool) -> str:
|
||||
"""Record *body* or raise if configured to fail."""
|
||||
if self._fail:
|
||||
raise RuntimeError("network error")
|
||||
|
||||
Reference in New Issue
Block a user