Skip to content

Commit

Permalink
Add testing for StringDefinition validator
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Oct 28, 2024
1 parent cb78e07 commit 39c24d2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/ert/unit_tests/gui/ide/test_string_definition_argument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from ert.validation import StringDefinition


def test_validate_success_with_all_required_tokens():
string_def = StringDefinition(required=["token1", "token2"], invalid=["invalid1"])
validation_status = string_def.validate("This is a string with token1 and token2")
assert bool(validation_status) is True
assert validation_status.message() == ""


def test_validate_success_with_required_tokens():
string_def = StringDefinition(required=["token1", "token2"], invalid=["invalid1"])
validation_status = string_def.validate("This is a string with token1 and token2")
assert bool(validation_status) is True
assert validation_status.message() == ""


def test_validate_failure_with_empty_required_tokens():
string_def = StringDefinition(optional=False, required=[], invalid=["invalid1"])
validation_status = string_def.validate("This is a string with invalid1")
assert bool(validation_status) is False
assert validation_status.message() == "Contains invalid string invalid1!"


def test_validate_empty_string():
string_def = StringDefinition(required=["token1"], invalid=["invalid1"])
validation_status = string_def.validate("")
assert bool(validation_status) is False
assert "Missing required token1!" in validation_status.message()

0 comments on commit 39c24d2

Please sign in to comment.