Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
def test_check_regex_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'abcdef', str, regex=r'^\d+$')
Ejemplo n.º 4
0
def test_check_pattern_int_pass():
    check('test', 1, (int, str), pattern='ipv4')
Ejemplo n.º 5
0
def test_check_regex_pattern():
    check('test', '12345', str, regex=r'^\d+$')
Ejemplo n.º 6
0
def test_check_type_fail():
    with pytest.raises(TypeError):
        check('test', 1, str)
Ejemplo n.º 7
0
def test_check_list_items_type():
    assert isinstance(check('test', [1, 2], list, items_type=int), list)
Ejemplo n.º 8
0
def test_pattern_map_failure():
    with pytest.raises(IndexError):
        check('test', 'something', str, pattern='something')
Ejemplo n.º 9
0
def test_check_pattern_mapping_hex():
    check('test', examples['hex'], str, pattern='hex')
Ejemplo n.º 10
0
def test_check_pattern_mapping_email():
    check('test', examples['email'], str, pattern='email')
Ejemplo n.º 11
0
def test_check_patern_mapping_uuid():
    check('test', examples['uuid'], str, pattern='uuid')
Ejemplo n.º 12
0
def test_check_choices_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', [1, 2, 3, 500], list, choices=list(range(5)))
Ejemplo n.º 13
0
def test_check_choices():
    check('test', [1, 2, 3], list, choices=list(range(5)))
Ejemplo n.º 14
0
def test_check_list_items_softcheck():
    assert check('test', [1, 2, '3'], list, items_type=int) == [1, 2, 3]
Ejemplo n.º 15
0
def test_check_list_items_fail():
    with pytest.raises(TypeError):
        check('test', [1, 2, 'three'], list, items_type=int)
Ejemplo n.º 16
0
def test_check_allow_none_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', None, str, allow_none=False)
Ejemplo n.º 17
0
def test_check_pattern_mapping_hex_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'something', str, pattern='hex')
Ejemplo n.º 18
0
def test_check_pattern_mapping_url():
    check('test', examples['url'], str, pattern='url')
Ejemplo n.º 19
0
def test_return_defaults():
    assert check('test', None, int) is None
    assert check('test', None, int, default=1) == 1
Ejemplo n.º 20
0
def test_check_pattern_mapping_ipv6():
    check('test', examples['ipv6'], str, pattern='ipv6')
Ejemplo n.º 21
0
def test_check_single_type():
    assert isinstance(check('test', 1, int), int)
Ejemplo n.º 22
0
def test_check_pattern_mapping_ipv6_fail():
    with pytest.raises(UnexpectedValueError):
        check('test', 'abcdef', str, pattern='ipv6')
Ejemplo n.º 23
0
def test_check_single_type_softchecking():
    assert isinstance(check('test', '1', int), int)
Ejemplo n.º 24
0
def test_check_single_type_softcheck_fail():
    with pytest.raises(TypeError):
        check('test', '1', int, softcheck=False)