|
43 | 43 | Config, |
44 | 44 | ConfigurationError, |
45 | 45 | EnumerationValidator, |
| 46 | + ExcludeRangeValidator, |
46 | 47 | FileIsReadableValidator, |
47 | 48 | PrecisionValidator, |
48 | 49 | RegexValidator, |
| 50 | + UnitValidator, |
49 | 51 | VersionedConfig, |
50 | 52 | _BoolConfigValue, |
51 | 53 | _ConfigBase, |
@@ -450,3 +452,38 @@ def test_config_all_upper_case(): |
450 | 452 | if not isinstance(config_value, _ConfigValue): |
451 | 453 | continue |
452 | 454 | 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