e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""Tests for telemetry decorator behavior."""
|
|
|
|
from _pytest.monkeypatch import MonkeyPatch
|
|
import pytest
|
|
|
|
from deeptutor.services.llm import telemetry
|
|
|
|
|
|
class _FakeLogger:
|
|
def __init__(self) -> None:
|
|
self.messages: list[str] = []
|
|
|
|
def debug(self, message: str, *args: object, **_kwargs: object) -> None:
|
|
self.messages.append(message % args if args else message)
|
|
|
|
def warning(self, message: str, *args: object, **_kwargs: object) -> None:
|
|
self.messages.append(message % args if args else message)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_track_llm_call_success(monkeypatch: MonkeyPatch) -> None:
|
|
"""Successful calls should emit debug log entries."""
|
|
fake_logger = _FakeLogger()
|
|
monkeypatch.setattr(telemetry, "logger", fake_logger)
|
|
|
|
@telemetry.track_llm_call("test")
|
|
async def _func() -> str:
|
|
return "ok"
|
|
|
|
result = await _func()
|
|
|
|
assert result == "ok"
|
|
assert any("completed successfully" in msg for msg in fake_logger.messages)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_track_llm_call_failure(monkeypatch: MonkeyPatch) -> None:
|
|
"""Failures should emit warning log entries."""
|
|
fake_logger = _FakeLogger()
|
|
monkeypatch.setattr(telemetry, "logger", fake_logger)
|
|
|
|
@telemetry.track_llm_call("test")
|
|
async def _func() -> str:
|
|
raise RuntimeError("boom")
|
|
|
|
with pytest.raises(RuntimeError):
|
|
await _func()
|
|
|
|
assert any("failed" in msg for msg in fake_logger.messages)
|