コード例 #1
0
    def test_to_int_array_none_ok():
        """Test to_int transform with arrays and Nones."""
        validator = to_int(allow_none=True)

        try:
            validator(['10', '11', None, '-12'], 'test_arg', 'Test Arg')
        except ValidationError:
            assert False, '"Test Arg" (to_int) failed when it should have passed.'
コード例 #2
0
    def test_to_int_array():
        """Test to_int transform with an array."""
        validator = to_int()

        try:
            validator(['10', '11', '-12'], 'test_arg', 'Test Arg')
        except ValidationError:
            assert False, '"Test Arg" (to_int) failed when it should have passed.'
コード例 #3
0
    def test_to_int_none():
        """Test to_int transform with none."""
        validator = to_int(allow_none=True)

        try:
            assert validator(None, 'test_arg', 'Test Arg') is None
        except ValidationError:
            assert False, '"Test Arg" (to_int) failed when it should have passed.'
コード例 #4
0
    def test_to_int():
        """Test to_int transform."""
        validator = to_int()

        try:
            assert validator('10', 'test_arg', 'Test Arg') == 10
        except ValidationError:
            assert False, '"Test Arg" (to_int) failed when it should have passed.'
コード例 #5
0
    def test_to_int_array_not_none_ok():
        """Test to_int transform with None in arrays that should fail."""
        validator = to_int()

        try:
            validator(['10', '11', None, '-12'], 'test_arg', 'Test Arg')
            assert False, 'Validator passed when it should have failed.'
        except ValidationError as v:
            assert (v.message == '"Test Arg" (test_arg) must be a int.'
                    ), 'Validator failed with an incorrect message.'
コード例 #6
0
    def test_to_int_negative():
        """Test to_int transform that should fail."""
        validator = to_int()

        try:
            validator('foo', 'test_arg', 'Test Arg')
            assert False, 'Validator passed when it should have failed.'
        except ValidationError as v:
            assert (v.message == '"Test Arg" (test_arg) must be a int.'
                    ), 'Validator failed with an incorrect message.'