Skip to content

Commit 094652a

Browse files
authored
tests: add more tests for validators (#2186)
1 parent 77ae5a3 commit 094652a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/config/tests.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
Config,
4444
ConfigurationError,
4545
EnumerationValidator,
46+
ExcludeRangeValidator,
4647
FileIsReadableValidator,
4748
PrecisionValidator,
4849
RegexValidator,
50+
UnitValidator,
4951
VersionedConfig,
5052
_BoolConfigValue,
5153
_ConfigBase,
@@ -450,3 +452,38 @@ def test_config_all_upper_case():
450452
if not isinstance(config_value, _ConfigValue):
451453
continue
452454
assert config_value.env_key == config_value.env_key.upper()
455+
456+
457+
def test_regex_validator_without_match():
458+
validator = RegexValidator("\d")
459+
with pytest.raises(ConfigurationError) as e:
460+
validator("foo", "field")
461+
assert "does not match pattern" in e.value.args[0]
462+
463+
464+
def test_unit_validator_without_match():
465+
validator = RegexValidator("ms")
466+
with pytest.raises(ConfigurationError) as e:
467+
validator("s", "field")
468+
assert "does not match pattern" in e.value.args[0]
469+
470+
471+
def test_unit_validator_with_unsupported_unit():
472+
validator = UnitValidator("(\d+)(s)", "secs", {})
473+
with pytest.raises(ConfigurationError) as e:
474+
validator("10s", "field")
475+
assert "is not a supported unit" in e.value.args[0]
476+
477+
478+
def test_precision_validator_not_a_float():
479+
validator = PrecisionValidator()
480+
with pytest.raises(ConfigurationError) as e:
481+
validator("notafloat", "field")
482+
assert "is not a float" in e.value.args[0]
483+
484+
485+
def test_exclude_range_validator_not_in_range():
486+
validator = ExcludeRangeValidator(1, 100, "desc")
487+
with pytest.raises(ConfigurationError) as e:
488+
validator(10, "field")
489+
assert "cannot be in range" in e.value.args[0]

0 commit comments

Comments
 (0)