Beispiel #1
0
    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)
Beispiel #2
0
    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))
Beispiel #3
0
    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
Beispiel #4
0
    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
Beispiel #5
0
    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())
Beispiel #6
0
    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())