예제 #1
0
    def test_repr(self):
        validator = validate_text(pattern='hello world', required=False)
        self.assertEqual(
            repr(validator),
            'validate_text(pattern=\'hello world\', required=False)',
        )

        validator = validate_text(min_length=4, max_length=10)
        self.assertEqual(
            repr(validator),
            'validate_text(min_length=4, max_length=10)',
        )
예제 #2
0
    def test_check_requested_bounds(self):
        with self.assertRaises(TypeError):
            validate_text(min_length='1')

        with self.assertRaises(ValueError):
            validate_text(min_length=-1)

        with self.assertRaises(TypeError):
            validate_text(max_length='1')

        with self.assertRaises(ValueError):
            validate_text(max_length=-1)

        with self.assertRaises(ValueError):
            validate_text(min_length=10, max_length=9)
예제 #3
0
    def test_schema_valid(self):  # type: () -> None
        validator = validate_tuple(schema=(
            validate_text(),
            validate_int(),
        ))

        validator((u"hello world", 9001))
예제 #4
0
 def test_invalid_key(self):
     with self.assertRaises(ValueError):
         validate_mapping({
             u"key1": 1,
             u"key2": 2,
         },
                          key_validator=validate_text(min_length=20))
    def test_schema_valid(self):  # type: () -> None
        validator = validate_structure(schema={
            'hello': validate_text(),
            'count': validate_int(),
        })

        validator({'hello': u"world", 'count': 2})
예제 #6
0
    def test_schema_invalid_value(self):  # type: () -> None
        validator = validate_tuple(schema=(
            validate_text(),
            validate_int(min_value=0),
        ))

        with self.assertRaises(ValueError):
            validator((u"string", -1))
예제 #7
0
    def test_schema_invalid_value_type(self):
        validator = validate_tuple(schema=(
            validate_text(),
            validate_int(),
        ))

        with self.assertRaises(TypeError):
            validator((u"string", '1000'))
    def test_schema_invalid_value_type(self):
        validator = validate_structure(schema={
            'hello': validate_text(),
            'count': validate_int(),
        })

        with self.assertRaises(TypeError):
            validator({
                'hello': u"world",
                'count': "one hundred",
            })
예제 #9
0
 def test_repr(self):
     validator = validate_mapping(
         key_validator=validate_text(),
         value_validator=validate_int(),
     )
     self.assertEqual(
         repr(validator),
         'validate_mapping('
         'key_validator=validate_text(), value_validator=validate_int()'
         ')',
     )
예제 #10
0
    def test_schema_invalid_value(self):  # type: () -> None
        validator = validate_structure(schema={
            'hello': validate_text(),
            'count': validate_int(min_value=0),
        })

        with self.assertRaises(ValueError):
            validator({
                'hello': u"world",
                'count': -1,
            })
예제 #11
0
    def test_pattern(self):
        validate_text(u"a----b", pattern=r"a-*b")

        with self.assertRaises(ValueError):
            validate_text(u"begin end", pattern=r"end")

        with self.assertRaises(ValueError):
            validate_text(u"begin end", pattern=r"begin")
예제 #12
0
    def test_precompiled_pattern(self):  # type: () -> None
        validate_text(u"a----b", pattern=re.compile(r"a-*b"))

        with self.assertRaises(ValueError):
            validate_text(u"begin end", pattern=re.compile(r"end"))

        with self.assertRaises(ValueError):
            validate_text(u"begin end", pattern=re.compile(r"begin"))
예제 #13
0
 def test_repr_2(self):  # type: () -> None
     validator = validate_text(min_length=4, max_length=10)
     self.assertEqual(
         repr(validator),
         'validate_text(min_length=4, max_length=10)',
     )
예제 #14
0
 def test_valid_keys(self):  # type: () -> None
     validate_mapping({
         u"key1": 1,
         u"key2": 2,
     },
                      key_validator=validate_text())
예제 #15
0
    def test_invalid_pattern(self):
        with self.assertRaises(TypeError):
            validate_text(pattern=lambda string: None)

        with self.assertRaises(Exception):
            validate_text(pattern=r"(")
예제 #16
0
 def test_valid_keys(self):
     validate_mapping({
         u"key1": 1,
         u"key2": 2,
     },
                      key_validator=validate_text())
예제 #17
0
 def test_valid(self):
     validate_text(u"hello world")
예제 #18
0
 def test_not_required(self):  # type: () -> None
     validate_text(None, required=False)
예제 #19
0
 def test_closure(self):
     validator = validate_text(min_length=4)
     validator(u"12345")
     with self.assertRaises(ValueError):
         validator(u"123")
예제 #20
0
    def test_required(self):
        validate_text(None, required=False)

        with self.assertRaises(TypeError):
            validate_text(None)
예제 #21
0
 def test_valid(self):  # type: () -> None
     validate_text(u"hello world")
예제 #22
0
    def test_max_length(self):
        validate_text(u"123456", max_length=6)

        with self.assertRaises(ValueError):
            validate_text(u"123456", max_length=5)
예제 #23
0
 def test_repr_1(self):  # type: () -> None
     validator = validate_text(pattern='hello world', required=False)
     self.assertEqual(
         repr(validator),
         'validate_text(pattern=\'hello world\', required=False)',
     )
예제 #24
0
 def test_bytestring(self):
     with self.assertRaises(TypeError):
         validate_text(b"hello world")
예제 #25
0
    def test_min_length(self):  # type: () -> None
        validate_text(u"123456", min_length=6)

        with self.assertRaises(ValueError):
            validate_text(u"123456", min_length=7)