Exemplo n.º 1
0
def test_heavy_nested(lst):
    assert validate([[int], float, [[float]]], lst) is None

    with pytest.raises(TypeError):
        validate([[str], int, int], lst)

    with pytest.raises(TypeError):
        validate([[[float]]], lst)
Exemplo n.º 2
0
def test_different_sequences(lst, tpl):
    with pytest.raises(TypeError):
        if tpl:
            validate([int], tpl)
        else:
            validate([], tpl)

    with pytest.raises(TypeError):
        if lst:
            validate((int), lst)
        else:
            validate((), lst)
Exemplo n.º 3
0
def test_advanced(dct):
    structure = {
        'total_count': int,
        'active': bool,
        'people': [{
            'id': int,
            'title': str,
            'salary': float,
        }],
        'timestamps': [int],
    }
    assert validate(structure, dct) is None
Exemplo n.º 4
0
def test_plain_no_strict(dct):
    assert validate({'a': str}, dct, strict=False) is None
Exemplo n.º 5
0
def test_simple_error(not_string):
    with pytest.raises(TypeError):
        validate(str, not_string)
Exemplo n.º 6
0
def test_list_lengths(lst):
    with pytest.raises(ValueError):
        validate([int, int, int, str], lst)
Exemplo n.º 7
0
def test_plain(li):
    assert validate([int], li) is None
Exemplo n.º 8
0
def test_plain_type_error(tpl):
    with pytest.raises(TypeError):
        validate((int, ), tpl)
Exemplo n.º 9
0
def test_dict_nested(lst):
    assert validate([{'a': {'b': [dict]}}], lst) is None
Exemplo n.º 10
0
def test_simple_pos_int(num):
    assert validate(positive_int, num) is None
Exemplo n.º 11
0
def test_deep_nesting(data):
    type_mask = [two_item_list, [positive_int, two_item_list], [title]]
    assert validate(type_mask, data) is None
Exemplo n.º 12
0
def test_empty():
    assert validate({}, {}) is None
Exemplo n.º 13
0
def test_nested_dict(dct):
    assert validate({'a': {'b': int}}, dct) is None
Exemplo n.º 14
0
def test_strict(dct):
    assume(len(dct) > 1)
    with pytest.raises(KeyError):
        validate({'a': str}, dct)
Exemplo n.º 15
0
def test_plain_no_strict_error(dct):
    with pytest.raises(KeyError):
        validate({'a': str, 'b': float}, dct, strict=False)
Exemplo n.º 16
0
def test_simple_title(words):
    assert validate(title, words) is None
Exemplo n.º 17
0
def test_different_mappings(dct):
    with pytest.raises(TypeError):
        validate(dict, OrderedDict(dct))
        validate(OrderedDict, dct)
Exemplo n.º 18
0
def test_simple_ti_list(lst):
    assert validate(two_item_list, lst) is None
Exemplo n.º 19
0
def test_plain(tpl):
    assert validate((int, ), tpl) is None
Exemplo n.º 20
0
def test_simple_pos_int_error(num):
    with pytest.raises(TypeError):
        validate(positive_int, num)
Exemplo n.º 21
0
def test_list_lengths(tpl):
    with pytest.raises(ValueError):
        validate((int, int, int, str), tpl)
Exemplo n.º 22
0
def test_simple_title_error(words):
    assume(len(words) > 0)
    assume(not words.isspace())
    with pytest.raises(TypeError):
        validate(title, words)
Exemplo n.º 23
0
def test_plain_type_error(lst):
    with pytest.raises(TypeError):
        validate([int], lst)
Exemplo n.º 24
0
def test_simple_ti_list_error(lst):
    with pytest.raises(TypeError):
        validate(two_item_list, lst)
Exemplo n.º 25
0
def test_nested(lst):
    assert validate([[int]], lst) is None

    with pytest.raises(TypeError):
        validate([int], lst)
Exemplo n.º 26
0
def test_nested(data):
    type_mask = [{'id': positive_int, 'name': title}]

    assert validate(type_mask, data) is None
Exemplo n.º 27
0
def test_empty():
    assert validate([], []) is None
Exemplo n.º 28
0
def test_nested_error(data):
    assume(len(data) != 0)
    type_mask = [{'id': positive_int, 'name': title}]

    with pytest.raises(TypeError):
        validate(type_mask, data)
Exemplo n.º 29
0
def test_simple(string):
    assert validate(str, string) is None
Exemplo n.º 30
0
def test_plain_key_error(dct):
    with pytest.raises(KeyError):
        validate({'a': str, 'b': float}, dct)