"""Tests de PermissiveRule y Condition.""" from __future__ import annotations import pytest from pydantic import ValidationError from vmssailor.core import PermissiveRule from vmssailor.core.permissive import Condition def test_condition_basic() -> None: c = Condition( tag_ref="ME_PORT.OIL_PRESS", operator=">", threshold=0.3, severity="fail", ) assert c.severity == "fail" def test_condition_between_requires_both_thresholds() -> None: with pytest.raises(ValidationError): Condition( tag_ref="x", operator="between", threshold_low=1.0, # threshold_high faltante ) def test_permissive_rule_empty_conditions_rejected() -> None: with pytest.raises(ValidationError): PermissiveRule(id="r", action_id="START", conditions=[]) def test_permissive_rule_with_multiple_conditions() -> None: r = PermissiveRule( id="rule_start", action_id="START_ME_PORT", conditions=[ Condition(tag_ref="ME_PORT.OIL_PRESS", operator=">", threshold=0.3), Condition(tag_ref="ME_PORT.COOLANT_TEMP", operator=">", threshold=5.0), Condition(tag_ref="ME_PORT.ESTOP_ACTIVE", operator="is_false"), ], on_fail_message="No es seguro arrancar.", ) assert len(r.conditions) == 3 assert r.conditions[2].operator == "is_false"