1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
from __future__ import annotations
import pytest
from dynaconf import validator_conditions
positive_conditions = [
("eq", 1, 1),
("ne", 1, 2),
("gt", 4, 3),
("lt", 3, 4),
("gte", 5, 5),
("lte", 5, 5),
("identity", None, None),
("is_type_of", 42, int),
("is_in", 42, [42, 34]),
("is_not_in", 42, [55, 34]),
("cont", "This word(s) contains in text", "in"),
("len_eq", "Length Equal", 12),
("len_eq", [1, 2, 3], 3),
("len_ne", "Length Not equal", 0),
("len_ne", [], 1),
("len_min", "Minimum length", 3),
("len_min", [1, 2, 3, 4, 5], 3),
("len_max", "Maximum length", 15),
("len_max", [1, 2, 3, 4, 5], 5),
("startswith", "codeshow", "code"),
("endswith", "codeshow", "show"),
]
@pytest.mark.parametrize("data", positive_conditions)
def test_conditions(data):
assert getattr(validator_conditions, data[0])(data[1], data[2])
negative_conditions = [
("eq", 1, 2),
("ne", 1, 1),
("gt", 4, 4),
("lt", 3, 3),
("gte", 5, 6),
("lte", 5, 4),
("identity", None, 1),
("is_type_of", 42, str),
("is_in", 42, [55, 34]),
("is_not_in", 42, [42, 34]),
("cont", "This word(s) contains in text", "out"),
("len_eq", "Length Equal", 0),
("len_eq", [1, 2, 3], 4),
("len_ne", "Length Not equal", 16),
("len_ne", [], 0),
("len_min", "Minimum length", 15),
("len_min", [1, 2, 3, 4, 5], 6),
("len_max", "Maximum length", 3),
("len_max", [1, 2, 3, 4, 5], 4),
("startswith", "codeshow", "show"),
("endswith", "codeshow", "code"),
]
@pytest.mark.parametrize("data", negative_conditions)
def test_negative_conditions(data):
assert not getattr(validator_conditions, data[0])(data[1], data[2])
|