コード例 #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)