Пример #1
0
def test_arrow_type_inputs():
    arw = arrow.utcnow().floor('hour')

    # Test a floating point
    assert check('test', arw.timestamp(), arrow.Arrow) == arw

    # Test an integer
    assert check('test', int(arw.timestamp()), arrow.Arrow) == arw

    # Test a string
    assert check('test', arw.format(), arrow.Arrow) == arw

    # Test an arrow obj
    assert check('test', arw, arrow.Arrow) == arw
Пример #2
0
def test_bool_softchecks():
    assert check('test', 'yes', bool) is True
    assert check('test', 'true', bool) is True
    assert check('test', 'TRUE', bool) is True
    assert check('test', 'false', bool) is False
    assert check('test', 'FALSE', bool) is False
    assert check('test', 'no', bool) is False
Пример #3
0
def test_check_regex_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'abcdef', str, regex=r'^\d+$')
Пример #4
0
def test_check_pattern_int_pass():
    check('test', 1, (int, str), pattern='ipv4')
Пример #5
0
def test_check_regex_pattern():
    check('test', '12345', str, regex=r'^\d+$')
Пример #6
0
def test_check_type_fail():
    with pytest.raises(TypeError):
        check('test', 1, str)
Пример #7
0
def test_check_list_items_type():
    assert isinstance(check('test', [1, 2], list, items_type=int), list)
Пример #8
0
def test_pattern_map_failure():
    with pytest.raises(IndexError):
        check('test', 'something', str, pattern='something')
Пример #9
0
def test_check_pattern_mapping_hex():
    check('test', examples['hex'], str, pattern='hex')
Пример #10
0
def test_check_pattern_mapping_email():
    check('test', examples['email'], str, pattern='email')
Пример #11
0
def test_check_patern_mapping_uuid():
    check('test', examples['uuid'], str, pattern='uuid')
Пример #12
0
def test_check_choices_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', [1, 2, 3, 500], list, choices=list(range(5)))
Пример #13
0
def test_check_choices():
    check('test', [1, 2, 3], list, choices=list(range(5)))
Пример #14
0
def test_check_list_items_softcheck():
    assert check('test', [1, 2, '3'], list, items_type=int) == [1, 2, 3]
Пример #15
0
def test_check_list_items_fail():
    with pytest.raises(TypeError):
        check('test', [1, 2, 'three'], list, items_type=int)
Пример #16
0
def test_check_allow_none_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', None, str, allow_none=False)
Пример #17
0
def test_check_pattern_mapping_hex_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'something', str, pattern='hex')
Пример #18
0
def test_check_pattern_mapping_url():
    check('test', examples['url'], str, pattern='url')
Пример #19
0
def test_return_defaults():
    assert check('test', None, int) is None
    assert check('test', None, int, default=1) == 1
Пример #20
0
def test_check_pattern_mapping_ipv6():
    check('test', examples['ipv6'], str, pattern='ipv6')
Пример #21
0
def test_check_single_type():
    assert isinstance(check('test', 1, int), int)
Пример #22
0
def test_check_pattern_mapping_ipv6_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'abcdef', str, pattern='ipv6')
Пример #23
0
def test_check_single_type_softchecking():
    assert isinstance(check('test', '1', int), int)
Пример #24
0
def test_check_single_type_softcheck_fail():
    with pytest.raises(TypeError):
        check('test', '1', int, softcheck=False)