Example #1
0
def test_typ():
    meta_test(
        typ(int),
        good=[1, -1],
        bad=['string']
    )
    assert str(typ(int)) == '<type {BI}.int>'.format(BI=BI)
Example #2
0
def test_typ_no_inheritance():
    meta_test(
        typ(A),
        good=[A()],
        bad=[B()]
    )

    assert str(typ(A)) == '<type test_clauses.A>'
Example #3
0
def test_clause_or_shortcut():
    meta_test(
        typ(int)._or(typ(float)),
        good=[1, 1.9],
        bad=['string']
    )

    assert str(typ(int)._or(typ(float))) == '<<type {BI}.int> or <type {BI}.float>>'.format(BI=BI)
Example #4
0
def test_clause_and_shortcut():
    meta_test(
        typ(int)._and(between(0, 10)),
        good=[1, 9],
        bad=[11]
    )

    assert str(typ(int)._and(between(0, 10))) == '<<type {BI}.int> and <in range [0..10)>>'.format(BI=BI)
Example #5
0
def test_list_of():
    meta_test(
        list_of(typ(int)),
        good=[[1, 2, 3, 4], []],
        bad=[{1: 2}, [1, 2, 3, 'lol']]
    )

    with pytest.raises(TypeError):
        list_of(object())

    assert str(list_of(typ(float))) == '<list of <type {BI}.float>>'.format(BI=BI)
Example #6
0
def test_dict_of():
    meta_test(
        dict_of(typ(str), typ(int)),
        good=[{'a': 1, 'b': 2, 'd': 3}, {}],
        bad=[{'a': 1, 'b': 2, 'd': 'straaang'}, None],
    )

    with pytest.raises(TypeError):
        dict_of(object(), typ(int))

    with pytest.raises(TypeError):
        dict_of(typ(int), object())

    assert str(dict_of(typ(str), typ(float))) == '<dict of <type {BI}.str> -> <type {BI}.float>>'.format(BI=BI)