Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sdks/python/tests/unit/evaluation/metrics/test_is_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from opik.evaluation.metrics.heuristics.is_json import IsJson

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test bypasses public IsJson API

IsJson is imported from the internal opik.evaluation.metrics.heuristics.is_json, so this test can pass while the documented opik.evaluation.metrics export is broken — should we import IsJson from opik.evaluation.metrics instead, as .agents/skills/python-sdk/testing.md requires?

Severity

Want Baz to fix this for you? Activate Fixer You can also update your AI coding guidelines based on this comment by apply pr to [branch name]

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
`sdks/python/tests/unit/evaluation/metrics/test_is_json.py` around line 3, update the
`IsJson` import used by these JSON metric tests to come from the public
`opik.evaluation.metrics` package rather than the internal `heuristics.is_json` module.
Keep the existing test cases unchanged so collection and execution verify that the
documented package-level export works correctly.

from opik.evaluation.metrics.score_result import ScoreResult


@pytest.mark.parametrize(
"output",
[
'{"key": "value"}',
"[1, 2, 3]",
"5",
'"a json string"',
"true",
"null",
],
)
def test_is_json__valid_json__returns_score_1(output):
metric = IsJson(track=False)

assert metric.score(output=output) == ScoreResult(
name=metric.name, value=1.0, reason=None, metadata=None
)


@pytest.mark.parametrize(
"output",
[
"Not a JSON string",
"",
'{"key": "value"',
None,
123,
],
)
def test_is_json__invalid_json__returns_score_0(output):
metric = IsJson(track=False)

assert metric.score(output=output) == ScoreResult(
name=metric.name, value=0.0, reason=None, metadata=None
)