-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing for StringDefinition validator
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
tests/ert/unit_tests/gui/ide/test_string_definition_argument.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |