|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +try: |
| 6 | + from pydantic_evals.reporting import EvaluationReport |
| 7 | +except Exception: |
| 8 | + pytest.skip('pydantic_evals not importable (likely pydantic < 2.8)', allow_module_level=True) |
| 9 | + |
| 10 | +import logfire |
| 11 | +from logfire._internal.config import LogfireConfig |
| 12 | + |
| 13 | + |
| 14 | +def _make_report(trace_id: str | None = None, span_id: str | None = None) -> EvaluationReport: |
| 15 | + return EvaluationReport(name='test', cases=[], trace_id=trace_id, span_id=span_id) |
| 16 | + |
| 17 | + |
| 18 | +def test_url_from_eval_with_project_url() -> None: |
| 19 | + config = LogfireConfig(send_to_logfire=False, console=False) |
| 20 | + config.project_url = 'https://logfire.pydantic.dev/my-org/my-project' |
| 21 | + instance = logfire.Logfire(config=config) |
| 22 | + |
| 23 | + report = _make_report(trace_id='abc123', span_id='def456') |
| 24 | + result = instance.url_from_eval(report) |
| 25 | + assert result == 'https://logfire.pydantic.dev/my-org/my-project/evals/compare?experiment=abc123-def456' |
| 26 | + |
| 27 | + |
| 28 | +def test_url_from_eval_no_project_url() -> None: |
| 29 | + config = LogfireConfig(send_to_logfire=False, console=False) |
| 30 | + instance = logfire.Logfire(config=config) |
| 31 | + |
| 32 | + report = _make_report(trace_id='abc123', span_id='def456') |
| 33 | + result = instance.url_from_eval(report) |
| 34 | + assert result is None |
| 35 | + |
| 36 | + |
| 37 | +def test_url_from_eval_no_trace_id() -> None: |
| 38 | + config = LogfireConfig(send_to_logfire=False, console=False) |
| 39 | + config.project_url = 'https://logfire.pydantic.dev/my-org/my-project' |
| 40 | + instance = logfire.Logfire(config=config) |
| 41 | + |
| 42 | + report = _make_report(span_id='def456') |
| 43 | + result = instance.url_from_eval(report) |
| 44 | + assert result is None |
| 45 | + |
| 46 | + |
| 47 | +def test_url_from_eval_no_span_id() -> None: |
| 48 | + config = LogfireConfig(send_to_logfire=False, console=False) |
| 49 | + config.project_url = 'https://logfire.pydantic.dev/my-org/my-project' |
| 50 | + instance = logfire.Logfire(config=config) |
| 51 | + |
| 52 | + report = _make_report(trace_id='abc123') |
| 53 | + result = instance.url_from_eval(report) |
| 54 | + assert result is None |
| 55 | + |
| 56 | + |
| 57 | +def test_url_from_eval_no_ids() -> None: |
| 58 | + config = LogfireConfig(send_to_logfire=False, console=False) |
| 59 | + config.project_url = 'https://logfire.pydantic.dev/my-org/my-project' |
| 60 | + instance = logfire.Logfire(config=config) |
| 61 | + |
| 62 | + report = _make_report() |
| 63 | + result = instance.url_from_eval(report) |
| 64 | + assert result is None |
0 commit comments