Exemplo n.º 1
0
def test_and_or_kwargs():
    assert And(module=1, function=2) == Query(module=1, function=2)
    assert Or(module=1, function=2) == Or(Query(module=1), Query(function=2))

    assert And(3, module=1, function=2) == And(3, Query(module=1, function=2))
    assert Or(3, module=1, function=2) == Or(3, Query(module=1),
                                             Query(function=2))
Exemplo n.º 2
0
def test_no_inf_recursion(mockevent):
    assert Or(And(1)) == 1
    assert Or(Or(1)) == 1
    assert And(Or(1)) == 1
    assert And(And(1)) == 1
    predicate = Q(Q(lambda ev: 1, module='wat'))
    print('predicate:', predicate)
    predicate(mockevent)
Exemplo n.º 3
0
def test_predicate_no_inf_recursion():
    assert Or(And(1)) == 1
    assert Or(Or(1)) == 1
    assert And(Or(1)) == 1
    assert And(And(1)) == 1
    predicate = Q(Q(lambda ev: 1, module='wat'))
    print('predicate:', predicate)
    predicate({'module': 'foo'})
Exemplo n.º 4
0
def test_or(mockevent):
    assert Q(module=1) | Q(module=2) == Or(Q(module=1), Q(module=2))
    assert Q(module=1) | Q(module=2) | Q(module=3) == Or(
        Q(module=1), Q(module=2), Q(module=3))

    assert (Q(module='foo') | Q(module='bar'))(mockevent) is False
    assert (Q(module='foo') | Q(module=__name__))(mockevent) is True

    assert Or(1, 2) & 3 == And(Or(1, 2), 3)
Exemplo n.º 5
0
def test_predicate_or():
    assert Q(module=1) | Q(module=2) == Or(Q(module=1), Q(module=2))
    assert Q(module=1) | Q(module=2) | Q(module=3) == Or(
        Q(module=1), Q(module=2), Q(module=3))

    assert (Q(module=1) | Q(module=2))({'module': 3}) == False
    assert (Q(module=1) | Q(module=2))({'module': 2}) == True

    assert Or(1, 2) & 3 == And(Or(1, 2), 3)
Exemplo n.º 6
0
def test_and(mockevent):
    assert And(C(1), C(2)) == And(C(1), C(2))
    assert Q(module=1) & Q(module=2) == And(Q(module=1), Q(module=2))
    assert Q(module=1) & Q(module=2) & Q(module=3) == And(
        Q(module=1), Q(module=2), Q(module=3))

    assert (Q(module=__name__) & Q(module='foo'))(mockevent) is False
    assert (Q(module=__name__) & Q(function='mockevent'))(mockevent) is True

    assert And(1, 2) | 3 == Or(And(1, 2), 3)
Exemplo n.º 7
0
def test_predicate_and():
    assert And(C(1), C(2)) == And(C(1), C(2))
    assert Q(module=1) & Q(module=2) == And(Q(module=1), Q(module=2))
    assert Q(module=1) & Q(module=2) & Q(module=3) == And(
        Q(module=1), Q(module=2), Q(module=3))

    assert (Q(module=1) & Q(module=2))({'module': 3}) == False
    assert (Q(module=1) & Q(function=2))({'module': 1, 'function': 2}) == True

    assert And(1, 2) | 3 == Or(And(1, 2), 3)
Exemplo n.º 8
0
def test_not(mockevent):
    assert Not(1).predicate == 1
    assert ~Or(1, 2) == Not(Or(1, 2))
    assert ~And(1, 2) == Not(And(1, 2))

    assert ~Not(1) == 1

    assert ~Query(module=1) | ~Query(module=2) == Not(
        And(Query(module=1), Query(module=2)))
    assert ~Query(module=1) & ~Query(module=2) == Not(
        Or(Query(module=1), Query(module=2)))

    assert ~Query(module=1) | Query(module=2) == Or(Not(Query(module=1)),
                                                    Query(module=2))
    assert ~Query(module=1) & Query(module=2) == And(Not(Query(module=1)),
                                                     Query(module=2))

    assert ~(Query(module=1) & Query(module=2)) == Not(
        And(Query(module=1), Query(module=2)))
    assert ~(Query(module=1) | Query(module=2)) == Not(
        Or(Query(module=1), Query(module=2)))

    assert repr(~Or(1, 2)) == repr(Not(Or(1, 2)))
    assert repr(~And(1, 2)) == repr(Not(And(1, 2)))

    assert repr(~Query(module=1) | ~Query(module=2)) == repr(
        Not(And(Query(module=1), Query(module=2))))
    assert repr(~Query(module=1) & ~Query(module=2)) == repr(
        Not(Or(Query(module=1), Query(module=2))))

    assert repr(~(Query(module=1) & Query(module=2))) == repr(
        Not(And(Query(module=1), Query(module=2))))
    assert repr(~(Query(module=1) | Query(module=2))) == repr(
        Not(Or(Query(module=1), Query(module=2))))

    assert Not(Q(module=__name__))(mockevent) is False
Exemplo n.º 9
0
def test_predicate_not():
    assert Not(1).predicate == 1
    assert ~Or(1, 2) == Not(Or(1, 2))
    assert ~And(1, 2) == Not(And(1, 2))

    assert ~Not(1) == 1

    assert ~Query(module=1) | ~Query(module=2) == Not(
        And(Query(module=1), Query(module=2)))
    assert ~Query(module=1) & ~Query(module=2) == Not(
        Or(Query(module=1), Query(module=2)))

    assert ~Query(module=1) | Query(module=2) == Or(Not(Query(module=1)),
                                                    Query(module=2))
    assert ~Query(module=1) & Query(module=2) == And(Not(Query(module=1)),
                                                     Query(module=2))

    assert ~(Query(module=1) & Query(module=2)) == Not(
        And(Query(module=1), Query(module=2)))
    assert ~(Query(module=1) | Query(module=2)) == Not(
        Or(Query(module=1), Query(module=2)))

    assert repr(~Or(1, 2)) == repr(Not(Or(1, 2)))
    assert repr(~And(1, 2)) == repr(Not(And(1, 2)))

    assert repr(~Query(module=1) | ~Query(module=2)) == repr(
        Not(And(Query(module=1), Query(module=2))))
    assert repr(~Query(module=1) & ~Query(module=2)) == repr(
        Not(Or(Query(module=1), Query(module=2))))

    assert repr(~(Query(module=1) & Query(module=2))) == repr(
        Not(And(Query(module=1), Query(module=2))))
    assert repr(~(Query(module=1) | Query(module=2))) == repr(
        Not(Or(Query(module=1), Query(module=2))))

    assert Not(Q(module=1))({'module': 1}) == False
Exemplo n.º 10
0
def test_compression():
    assert Or(Or(1, 2), And(3)) == Or(1, 2, 3)
    assert Or(Or(1, 2), 3) == Or(1, 2, 3)
    assert Or(1, Or(2, 3), 4) == Or(1, 2, 3, 4)
    assert And(1, 2, Or(3, 4)).predicates == (1, 2, Or(3, 4))

    assert repr(Or(Or(1, 2), And(3))) == repr(Or(1, 2, 3))
    assert repr(Or(Or(1, 2), 3)) == repr(Or(1, 2, 3))
    assert repr(Or(1, Or(2, 3), 4)) == repr(Or(1, 2, 3, 4))
Exemplo n.º 11
0
def test_and_or_kwargs():
    assert And(1, function=2) == And(1, Query(function=2))
    assert Or(1, function=2) == Or(1, Query(function=2))