Files
wehub-resource-sync 5a558eb09e
Backend Tests / discover-tests (push) Waiting to run
Backend Tests / ${{ matrix.name }} (push) Blocked by required conditions
Build and Publish SDK / build-and-publish (push) Waiting to run
Build Opik Docker Images / set-version (push) Waiting to run
Build Opik Docker Images / build-backend (push) Blocked by required conditions
Build Opik Docker Images / build-sandbox-executor-python (push) Blocked by required conditions
Build Opik Docker Images / build-python-backend (push) Blocked by required conditions
Build Opik Docker Images / build-frontend (push) Blocked by required conditions
Build Opik Docker Images / create-git-tag (push) Blocked by required conditions
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Waiting to run
Docs - Publish / run (push) Waiting to run
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Waiting to run
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Blocked by required conditions
Frontend Unit Tests / Test on Node 20 (push) Waiting to run
Guardrails E2E Tests / Select Python version matrix (push) Waiting to run
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Blocked by required conditions
Guardrails E2E Tests / 📢 Slack Notification (push) Blocked by required conditions
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Waiting to run
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Blocked by required conditions
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Waiting to run
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Waiting to run
Lint Opik Helm Chart / unittest-helm-chart (push) Waiting to run
Lint Opik Helm Chart / render-equality (push) Waiting to run
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Waiting to run
Python BE E2E Tests / Python BE E2E (push) Waiting to run
Python Backend Tests / run-python-backend-tests (push) Waiting to run
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Waiting to run
Release Drafter / update_release_draft (push) Waiting to run
SDK E2E Libraries Integration Tests / Check Secrets (push) Waiting to run
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / build-opik (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Blocked by required conditions
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Waiting to run
TypeScript SDK Build & Publish / build-and-publish (push) Waiting to run
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Waiting to run
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:25:44 +08:00

173 lines
6.1 KiB
Python

from typing import Any, Dict
from unittest import mock
import pytest
from opik import evaluation, exceptions, url_helpers
from opik.api_objects import opik_client
from opik.evaluation import metrics, rest_operations, test_case
from opik.evaluation.engine import engine
from opik.evaluation.metrics import score_result
def _make_mock_experiment(
id: str = "exp-id",
name: str = "exp-name",
dataset_name: str = "dataset-name",
) -> mock.Mock:
exp = mock.Mock()
exp.id = id
exp.name = name
exp.dataset_name = dataset_name
return exp
def _make_mock_dataset(id: str = "dataset-id") -> mock.Mock:
ds = mock.Mock()
ds.id = id
return ds
def _make_test_case(
trace_id: str = "trace-id-1",
dataset_item_id: str = "item-id-1",
task_output: Dict[str, Any] = None,
dataset_item_content: Dict[str, Any] = None,
) -> test_case.TestCase:
return test_case.TestCase(
trace_id=trace_id,
dataset_item_id=dataset_item_id,
task_output=task_output or {"output": "hello"},
dataset_item_content=dataset_item_content
or {"input": "hi", "reference": "hello"},
)
def test_evaluate_experiment__no_test_cases__raises_empty_experiment(fake_backend):
mock_experiment = _make_mock_experiment()
mock_dataset = _make_mock_dataset()
with mock.patch.object(
rest_operations,
"get_experiment_with_unique_name",
return_value=mock_experiment,
):
with mock.patch.object(
opik_client.Opik, "get_dataset", return_value=mock_dataset
):
with mock.patch.object(
rest_operations, "get_experiment_test_cases", return_value=[]
):
with pytest.raises(exceptions.EmptyExperiment):
evaluation.evaluate_experiment(
experiment_name="exp-name",
scoring_metrics=[metrics.Equals()],
)
def test_evaluate_experiment__happyflow(fake_backend):
mock_experiment = _make_mock_experiment()
mock_dataset = _make_mock_dataset()
test_cases = [
_make_test_case(
trace_id="trace-1",
task_output={"output": "hello"},
dataset_item_content={"input": "hi", "reference": "hello"},
),
_make_test_case(
trace_id="trace-2",
task_output={"output": "bye"},
dataset_item_content={"input": "ciao", "reference": "bye"},
),
]
mock_score_results = [
score_result.ScoreResult(name="equals_metric", value=1.0),
score_result.ScoreResult(name="equals_metric", value=1.0),
]
mock_test_results = [
mock.Mock(score_results=mock_score_results) for _ in test_cases
]
with mock.patch.object(
rest_operations,
"get_experiment_with_unique_name",
return_value=mock_experiment,
):
with mock.patch.object(
opik_client.Opik, "get_dataset", return_value=mock_dataset
):
with mock.patch.object(
rest_operations, "get_experiment_test_cases", return_value=test_cases
):
with mock.patch.object(
rest_operations,
"get_trace_project_name",
return_value="test-project",
):
with mock.patch.object(
url_helpers,
"get_experiment_url_by_id",
return_value="http://example.com/exp",
):
with mock.patch.object(
engine.EvaluationEngine,
"score_test_cases",
return_value=mock_test_results,
):
result = evaluation.evaluate_experiment(
experiment_name="exp-name",
scoring_metrics=[metrics.Equals()],
verbose=0,
)
assert result.experiment_id == "exp-id"
assert result.experiment_name == "exp-name"
assert result.dataset_id == "dataset-id"
assert result.test_results == mock_test_results
def test_evaluate_experiment__with_experiment_id__uses_get_by_id(fake_backend):
mock_experiment = _make_mock_experiment(id="explicit-exp-id")
mock_dataset = _make_mock_dataset()
test_cases = [_make_test_case()]
mock_get_by_id = mock.Mock(return_value=mock_experiment)
mock_get_by_name = mock.Mock()
with mock.patch.object(opik_client.Opik, "get_experiment_by_id", mock_get_by_id):
with mock.patch.object(
rest_operations, "get_experiment_with_unique_name", mock_get_by_name
):
with mock.patch.object(
opik_client.Opik, "get_dataset", return_value=mock_dataset
):
with mock.patch.object(
rest_operations,
"get_experiment_test_cases",
return_value=test_cases,
):
with mock.patch.object(
rest_operations,
"get_trace_project_name",
return_value="test-project",
):
with mock.patch.object(
url_helpers,
"get_experiment_url_by_id",
return_value="http://example.com/exp",
):
with mock.patch.object(
engine.EvaluationEngine,
"score_test_cases",
return_value=[],
):
evaluation.evaluate_experiment(
experiment_name="ignored-name",
experiment_id="explicit-exp-id",
scoring_metrics=[],
verbose=0,
)
mock_get_by_id.assert_called_once_with(id="explicit-exp-id")
mock_get_by_name.assert_not_called()