def test_values_counter_fail_opt(self): self.cfg.read_string(""" [GLOBAL] key = value opt_1 = value1 """) with self.schema.section("GLOBAL") as s: s.value(t.ItemCountValidator(t.ItemRegexValidator(r'opt_\d+'), lambda x: x > 1), required=False)
def test_values_counter_fail_req(self): self.cfg.read_string(""" [GLOBAL] key_1 = value1 opt = optional """) with self.schema.section("GLOBAL") as s: s.value( t.ItemCountValidator(t.ItemRegexValidator(r'key_\d+'), lambda x: x > 1))
def test_sections_counter_fail_opt(self): self.cfg.read_string(""" [GLOBAL] [OPT_1] key = value """) with self.schema.section(t.ItemCountValidator( t.ItemRegexValidator(r'OPT_\d+'), lambda x: x > 1), required=False): pass
def test_sections_counter_fail_req(self): self.cfg.read_string(""" [SECT_1] key = value [OPTIONAL] """) with self.schema.section( t.ItemCountValidator(t.ItemRegexValidator(r'SECT_\d+'), lambda x: x > 1)): pass
def test_complex_count_validator(self): val = t.ItemAndValidator( t.ItemCountValidator(t.ItemStringValidator("ok"), lambda x: x > 1), t.ItemCountValidator(t.ItemStringValidator("ok"), lambda x: x < 3)) with self.subTest("one"): val.setup() val("ok") self.assertFalse(val.teardown()) with self.subTest("two"): val.setup() val("ok") val("ok") self.assertTrue(val.teardown()) with self.subTest("three"): val.setup() val("ok") val("ok") val("ok") self.assertFalse(val.teardown())
def test_count_validator(self): val = t.ItemCountValidator(t.ItemStringValidator("ok"), lambda x: x > 1) self.assertIsInstance(val, t.ItemBaseValidator) with self.subTest("one"): val.setup() val("ok") val("fail") self.assertFalse(val.teardown()) with self.subTest("two"): val.setup() val("ok") val("fail") val("ok") self.assertTrue(val.teardown())