コード例 #1
0
def check_iterable_bad(input, expected_exception):
    checker = dc.Checker(dc.iterable)
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #2
0
def check_length_bounds_bad(input, min, max):
    checker = dc.Checker(dc.length(min=min, max=max))
    try:
        output = checker.process(input)
    except dc.BoundsError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #3
0
def check_length_exact_bad(input, length):
    checker = dc.Checker(dc.length(exact=length))
    try:
        output = checker.process(input)
    except dc.BoundsError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #4
0
def test_length_noninterable():
    checker = dc.Checker(dc.length(min=5))
    try:
        output = checker.process(3)
    except dc.DataTypeError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #5
0
def check_bad_dict(input, processor, expected_exception):
    checker = dc.Checker(processor)
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #6
0
def check_bad_list(input, processors, coerce):
    checker = dc.Checker(dc.list(*processors, coerce=coerce))
    try:
        output = checker.process(input)
    except dc.CheckerError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #7
0
def check_email_bad(input, check_dns, expected_exception):
    checker = dc.Checker(dc.email(check_dns=check_dns))
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #8
0
def check_bad_required(input):
    checker = dc.Checker(dc.required)
    try:
        output = checker.process(input)
    except dc.DataRequiredError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #9
0
def check_bad_datatype_bounds(processor, min, max, input):
    checker = dc.Checker(processor(coerce=True, min=min, max=max))
    try:
        output = checker.process(input)
    except dc.CheckerError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #10
0
def check_bad_datatype(processor, input, coerce):
    checker = dc.Checker(processor(coerce=coerce))
    try:
        output = checker.process(input)
    except dc.CheckerError:
        pass
    else:
        assert False, 'Got output of: %s' % output
コード例 #11
0
def check_bad_isvalid(input, processor):
    checker = dc.Checker(processor)
    try:
        output = checker.process(input)
    except dc.CheckerError:
        assert checker.is_valid(input) == False, 'is_valid() failed'
    else:
        assert False, 'Got output of: %s' % output
コード例 #12
0
def test_constant_bad():
    checker = dc.Checker(dc.constant('foo'))
    try:
        output = checker.process('bar')
    except dc.InvalidError:
        pass
    except Exception as ex:
        raise ex
    else:
        assert False, 'Got output of: %s' % output
コード例 #13
0
def check_ip_bad(input, ipv4, ipv6, expected_exception):
    checker = dc.Checker(dc.ip(ipv4=ipv4, ipv6=ipv6))
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    except Exception as ex:
        raise ex
    else:
        assert False, 'Got output of: %s' % output
コード例 #14
0
def check_regex_bad(processor, input, expected_exception):
    checker = dc.Checker(processor)
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    except Exception as ex:
        raise ex
    else:
        assert False, 'Got output of: %s' % output
コード例 #15
0
def check_url_bad(input, schemes, expected_exception):
    checker = dc.Checker(dc.url(schemes=schemes))
    try:
        output = checker.process(input)
    except expected_exception:
        pass
    except Exception as ex:
        raise ex
    else:
        assert False, 'Got output of: %s' % output
コード例 #16
0
def check_string_manip_bad(processor, input):
    checker = dc.Checker(processor)
    try:
        output = checker.process(input)
    except dc.DataTypeError:
        pass
    except Exception as ex:
        raise ex
    else:
        assert False, 'Got output of: %s' % output
コード例 #17
0
def test_choice_bad():
    choices = ('a', 'b', 'c')
    checker = dc.Checker(dc.choice(*choices))
    for input in (1, 'foo', False, Decimal('1.234')):
        try:
            output = checker.process(input)
        except dc.InvalidError:
            pass
        except Exception as ex:
            raise ex
        else:
            assert False, 'Got output of: %s' % output
コード例 #18
0
def check_length_exact_good(input, length):
    checker = dc.Checker(dc.length(exact=length))
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #19
0
def check_url_good(input, schemes):
    checker = dc.Checker(dc.url(schemes=schemes))
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #20
0
def check_ip_good(input, ipv4, ipv6):
    checker = dc.Checker(dc.ip(ipv4=ipv4, ipv6=ipv6))
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #21
0
def check_email_good(input, check_dns):
    checker = dc.Checker(dc.email(check_dns=check_dns))
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #22
0
def check_good_optional(input, default, expected):
    checker = dc.Checker(dc.optional(default=default))
    output = checker.process(input)
    assert output == expected, 'Got output of: %s' % output
コード例 #23
0
def check_good_dict(input, expected, processor):
    checker = dc.Checker(processor)
    output = checker.process(input)
    assert output == expected, 'Got output of: %s' % output
コード例 #24
0
def check_good_required(input):
    checker = dc.Checker(dc.required)
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #25
0
def check_string_manip_good(processor, input, expected):
    checker = dc.Checker(processor)
    output = checker.process(input)
    assert output == expected, 'Got output of: %s' % output
コード例 #26
0
def check_good_tuple(input, expected, processors, coerce):
    checker = dc.Checker(dc.tuple(*processors, coerce=coerce))
    output = checker.process(input)
    assert output == expected, 'Got output of: %s' % output
コード例 #27
0
def test_choice_good():
    choices = (5, 10, 15, 20, 25, 'foo', 'bar')
    checker = dc.Checker(dc.choice(*choices))
    for input in choices:
        output = checker.process(input)
        assert output == input, 'Got output of: %s' % output
コード例 #28
0
def check_length_bounds_good(input, min, max):
    checker = dc.Checker(dc.length(min=min, max=max))
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output
コード例 #29
0
def test_constant_good():
    for input in ('foo', 100, Decimal('1.234')):
        checker = dc.Checker(dc.constant(input))
        output = checker.process(input)
        assert output == input, 'Got output of: %s' % output
コード例 #30
0
def check_iterable_good(input):
    checker = dc.Checker(dc.iterable)
    output = checker.process(input)
    assert output == input, 'Got output of: %s' % output