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
377 lines
11 KiB
Python
377 lines
11 KiB
Python
from typing import Any, List, Optional
|
|
|
|
from opik.validation import validator_helpers
|
|
from opik.validation import parameter
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
("String", False, True),
|
|
("", False, False),
|
|
(1, False, False),
|
|
((1, 2, 3), False, False),
|
|
([2], False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_str(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_str(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
(1, False, True),
|
|
("String", False, False),
|
|
((1, 2, 3), False, False),
|
|
([2], False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_int(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_int(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
(1.0, False, True),
|
|
(2, False, False),
|
|
("String", False, False),
|
|
((1, 2, 3), False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_float(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_float(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
(1.0, False, True),
|
|
(2, False, True),
|
|
("String", False, False),
|
|
((1, 2, 3), False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_numeric(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_numeric(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
(True, False, True),
|
|
(False, False, True),
|
|
("String", False, False),
|
|
((1, 2, 3), False, False),
|
|
([2], False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_bool(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_bool(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
([1.0], False, True),
|
|
([2], False, True),
|
|
(["String"], False, True),
|
|
("not_a_list", False, False),
|
|
(10, False, False),
|
|
((1, 2, 3), False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_type_list(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_list(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
({"key": 1.0}, False, True),
|
|
([2], False, False),
|
|
("not_a_dict", False, False),
|
|
(10, False, False),
|
|
((1, 2, 3), False, False),
|
|
],
|
|
)
|
|
def test_validate_type_dict(value: Any, allow_empty: bool, expected: bool):
|
|
assert (
|
|
validator_helpers.validate_type_dict(value=value, allow_empty=allow_empty)
|
|
== expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,possible_values,allow_empty,expected",
|
|
[
|
|
(None, None, False, False),
|
|
(None, None, True, True),
|
|
("String", None, False, True),
|
|
(1, None, False, False),
|
|
((1, 2, 3), None, False, False),
|
|
([2], None, False, False),
|
|
({"key": 1.0}, None, False, False),
|
|
("1", ["1", "2"], False, True),
|
|
("3", ["1", "2"], False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_type_str(
|
|
value: Any, possible_values: Optional[List], allow_empty: bool, expected: bool
|
|
):
|
|
param = parameter.create_str_parameter(
|
|
name="parameter_type_str",
|
|
value=value,
|
|
possible_values=possible_values,
|
|
allow_empty=allow_empty,
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,possible_values,allow_empty,expected",
|
|
[
|
|
(None, None, False, False),
|
|
(None, None, True, True),
|
|
(1, None, False, True),
|
|
("String", None, False, False),
|
|
((1, 2, 3), None, False, False),
|
|
([2], None, False, False),
|
|
(1, [1, 2, 3], False, True),
|
|
(4, [1, 2, 3], False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_type_int(
|
|
value: Any, possible_values: Optional[List], allow_empty: bool, expected: bool
|
|
):
|
|
param = parameter.create_int_parameter(
|
|
name="parameter_type_int",
|
|
value=value,
|
|
possible_values=possible_values,
|
|
allow_empty=allow_empty,
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,possible_values,allow_empty,expected",
|
|
[
|
|
(None, None, False, False),
|
|
(None, None, True, True),
|
|
(1.0, None, False, True),
|
|
(2, None, False, False),
|
|
("String", None, False, False),
|
|
((1, 2, 3), None, False, False),
|
|
({"key": 1.0}, None, False, False),
|
|
(1.1, [1.1, 2.1, 3.1], False, True),
|
|
(4.1, [1.1, 2.1, 3.1], False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_type_float(
|
|
value: Any, possible_values: Optional[List], allow_empty: bool, expected: bool
|
|
):
|
|
param = parameter.create_float_parameter(
|
|
name="parameter_type_float",
|
|
value=value,
|
|
possible_values=possible_values,
|
|
allow_empty=allow_empty,
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,possible_values,allow_empty,expected",
|
|
[
|
|
(None, None, False, False),
|
|
(None, None, True, True),
|
|
(1.0, None, False, True),
|
|
(2, None, False, True),
|
|
("String", None, False, False),
|
|
((1, 2, 3), None, False, False),
|
|
({"key": 1.0}, None, False, False),
|
|
(1, [1, 2.2, 3], False, True),
|
|
(2.2, [1.1, 2.2, 3], False, True),
|
|
(4, [1, 2.2, 3], False, False),
|
|
(4.2, [1.1, 2.2, 3], False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_type_numeric(
|
|
value: Any, possible_values: Optional[List], allow_empty: bool, expected: bool
|
|
):
|
|
param = parameter.create_numeric_parameter(
|
|
name="parameter_type_numeric",
|
|
value=value,
|
|
possible_values=possible_values,
|
|
allow_empty=allow_empty,
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
(True, False, True),
|
|
(False, False, True),
|
|
("String", False, False),
|
|
((1, 2, 3), False, False),
|
|
([2], False, False),
|
|
({"key": 1.0}, False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_type_bool(value: Any, allow_empty: bool, expected: bool):
|
|
param = parameter.create_bool_parameter(
|
|
name="parameter_type_bool", value=value, allow_empty=allow_empty
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
([1.0], False, True),
|
|
([2], False, True),
|
|
(["String"], False, True),
|
|
("not_a_list", False, False),
|
|
(10, False, False),
|
|
((1, 2, 3), False, False),
|
|
({"key": 1.0}, False, False),
|
|
([], False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_value_list(value: Any, allow_empty: bool, expected: bool):
|
|
param = parameter.create_list_parameter(
|
|
name="parameter_value_list", value=value, allow_empty=allow_empty
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value,allow_empty,expected",
|
|
[
|
|
(None, False, False),
|
|
(None, True, True),
|
|
({"key": 1.0}, False, True),
|
|
([2], False, False),
|
|
("not_a_list", False, False),
|
|
(10, False, False),
|
|
((1, 2, 3), False, False),
|
|
([], False, False),
|
|
({}, False, False),
|
|
],
|
|
)
|
|
def test_validate_parameter_value_dict(value: Any, allow_empty: bool, expected: bool):
|
|
param = parameter.create_dict_parameter(
|
|
name="parameter_value_dict", value=value, allow_empty=allow_empty
|
|
)
|
|
_check_validate_parameter(test_parameter=param, expected=expected)
|
|
|
|
|
|
def _check_validate_parameter(test_parameter: parameter.Parameter, expected: bool):
|
|
valid, msg = validator_helpers.validate_parameter(parameter=test_parameter)
|
|
assert valid == expected
|
|
|
|
if expected:
|
|
return
|
|
|
|
if test_parameter.value is None:
|
|
value_not_empty = False
|
|
elif not isinstance(test_parameter.value, (bool, int, float)):
|
|
value_not_empty = (
|
|
hasattr(test_parameter.value, "__len__") and len(test_parameter.value) > 0
|
|
)
|
|
else:
|
|
value_not_empty = True
|
|
|
|
if test_parameter.possible_values is not None:
|
|
possible_values_str = [str(v) for v in test_parameter.possible_values]
|
|
|
|
if test_parameter.allow_empty:
|
|
expected_msg = (
|
|
"parameter %r must be one of [%s] or None but %r was given"
|
|
% (
|
|
test_parameter.name,
|
|
", ".join(possible_values_str),
|
|
test_parameter.value,
|
|
)
|
|
)
|
|
else:
|
|
expected_msg = "parameter %r must be one of [%s] but %r was given" % (
|
|
test_parameter.name,
|
|
", ".join(possible_values_str),
|
|
test_parameter.value,
|
|
)
|
|
elif value_not_empty:
|
|
param_type = (
|
|
None
|
|
if test_parameter.value is None
|
|
else type(test_parameter.value).__name__
|
|
)
|
|
|
|
if test_parameter.allow_empty:
|
|
expected_msg = (
|
|
"parameter %r must be of type(s) %r or None but %r was given"
|
|
% (
|
|
test_parameter.name,
|
|
validator_helpers.types_list(test_parameter.types),
|
|
param_type,
|
|
)
|
|
)
|
|
else:
|
|
expected_msg = "parameter %r must be of type(s) %r but %r was given" % (
|
|
test_parameter.name,
|
|
validator_helpers.types_list(test_parameter.types),
|
|
param_type,
|
|
)
|
|
else:
|
|
expected_msg = "parameter %r must have non empty value but %r was given" % (
|
|
test_parameter.name,
|
|
test_parameter.value,
|
|
)
|
|
|
|
assert expected_msg == msg
|