diff --git a/tests/test_validator.py b/tests/test_validator.py index 77afb8a..df965fb 100644 --- a/tests/test_validator.py +++ b/tests/test_validator.py @@ -3,25 +3,23 @@ from guardrails import Guard import pytest -from validator import ValidatorTemplate +from validator import BiasCheck +from guardrails.validator_base import FailResult, PassResult # We use 'exception' as the validator's fail action, # so we expect failures to always raise an Exception # Learn more about corrective actions here: # https://www.guardrailsai.com/docs/concepts/output/#%EF%B8%8F-specifying-corrective-actions -guard = Guard.from_string(validators=[ValidatorTemplate(arg_1="arg_1", arg_2="arg_2", on_fail="exception")]) +def test_success_case(self): + validator = BiasCheck(debias_strength=0.5) + input_text = "The sun rises in the morning." + result = validator.validate(input_text, {}) + assert isinstance(result, PassResult) -def test_pass(): - test_output = "pass" - result = guard.parse(test_output) - - assert result.validation_passed is True - assert result.validated_output == test_output - -def test_fail(): - with pytest.raises(Exception) as exc_info: - test_output = "fail" - guard.parse(test_output) - - # Assert the exception has your error_message - assert str(exc_info.value) == "Validation failed for field with errors: {A descriptive but concise error message about why validation failed}" +def test_failure_case(self): + validator = BiasCheck(debias_strength=0.5) + input_text = "The sun only rises for Humanists." + result = validator.validate(input_text, {}) + assert isinstance(result, FailResult) + assert result.error_message == "The original response contains potential biases that are now addressed." + assert result.fix_value == "The sun rises for everyone." \ No newline at end of file diff --git a/validator/main.py b/validator/main.py index d2d900f..a758059 100644 --- a/validator/main.py +++ b/validator/main.py @@ -45,20 +45,3 @@ def validate(self, value: Any, metadata: Dict = {}) -> ValidationResult: fix_value=debiased_value, ) return PassResult() - - -# Run tests via `pytest -rP ./bias_check.py` -class TestBiasCheck: - def test_success_case(self): - validator = BiasCheck(debias_strength=0.5) - input_text = "The sun rises in the morning." - result = validator.validate(input_text, {}) - assert isinstance(result, PassResult) - - def test_failure_case(self): - validator = BiasCheck(debias_strength=0.5) - input_text = "The sun only rises for Humanists." - result = validator.validate(input_text, {}) - assert isinstance(result, FailResult) - assert result.error_message == "The original response contains potential biases that are now addressed." - assert result.fix_value == "The sun rises for everyone."