Пример #1
0
 def test_and_validator(self):
     val = t.ItemAndValidator(t.ItemRegexValidator(r'.*a.*'),
                              t.ItemRegexValidator(r'.*b.*'))
     self.assertIsInstance(val, t.ItemBaseValidator)
     self.assertTrue(val("xxabyy"))
     self.assertTrue(val("bxxayy"))
     self.assertFalse(val("xxayy"))
     self.assertFalse(val("xxbyy"))
Пример #2
0
 def test_regex_validator(self):
     val = t.ItemRegexValidator(r'[a-zA-Z]+')
     self.assertIsInstance(val, t.ItemBaseValidator)
     self.assertTrue(val("string"))
     self.assertTrue(val("SomeString"))
     self.assertFalse(val("some string"))
     self.assertFalse(val("str123"))
     self.assertFalse(val("123str"))
Пример #3
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)
Пример #4
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))
Пример #5
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
Пример #6
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
Пример #7
0
    def test_sections_multi_ok(self):
        self.cfg.read_string("""
        [SECT_1]
        key = value

        [SECT_2]
        key = value
        """)

        with self.schema.section(t.ItemRegexValidator(r'SECT_\d+')):
            pass
        self.schema.no_other()
Пример #8
0
    def test_values_ok(self):
        self.cfg.read_string("""
        [GLOBAL]
        key = value

        [OPTIONAL]
        key_1 = 10
        key_2 = 12
        key = value
        """)

        with self.schema.section("GLOBAL") as s:
            s.value("key", value_val="value").no_other()

        with self.schema.section("OPTIONAL", required=False) as s:
            s.value(t.ItemRegexValidator(r'key_\d+'),
                    value_val=t.ItemNumberValidator())

        self.schema.no_other()