Esempio n. 1
0
 def test_or(self):
     return defer.DeferredList([
         self.run_test(OR(FALSE(), TRUE(), AND(TRUE(), TRUE())), True),
         self.run_test(AND(TRUE(), TRUE(), OR(TRUE(), FALSE())), True),
         self.run_test(OR(FALSE(), FALSE(), FALSE(), FALSE(), TRUE()),
                       True),
         self.run_test(OR(TRUE(), FALSE(), FALSE(), FALSE(), FALSE()), True)
     ])
Esempio n. 2
0
 def test_not(self):
     return defer.DeferredList([
         self.run_test(NOT(FALSE()), True),
         self.run_test(NOT(TRUE()), False),
         self.run_test(NOT(OR(TRUE(), FALSE())), False),
         self.run_test(NOT(AND(TRUE(), TRUE(), AND(TRUE(), FALSE()))),
                       True),
     ])
Esempio n. 3
0
 def test_all_bool(self):
     return defer.DeferredList([
         self.run_test(
             AND("sync_dynamic_arg_true", "async_dynamic_arg_true",
                 'fixed_arg_true', NOT("sync_dynamic_arg_false"),
                 NOT("async_dynamic_arg_false"), NOT("fixed_arg_false"),
                 TRUE(), NOT(FALSE()), True), True),
         self.run_test(
             OR(NOT("sync_dynamic_arg_true"), NOT("async_dynamic_arg_true"),
                NOT('fixed_arg_true'), "sync_dynamic_arg_false",
                "async_dynamic_arg_false", "fixed_arg_false", FALSE(),
                NOT(TRUE()), False), False),
     ])
Esempio n. 4
0
from txevaluate import Evaluator, AND, OR, NOT, TRUE, FALSE, ELEMENT_OF
from twisted.internet import defer

# create an expression
will_survive = lambda who: (
    OR(
        AND(
            ELEMENT_OF(who, "heart_of_gold"),
            ELEMENT_OF(who, "get_ape_descendants"),
            # make sure earth still exists
            TRUE(),
        ),
        # since we're in an OR clause, this will never be executed if the
        # other condition is true.
        NOT("meaning_of_life"),
    ))


def never_executed():
    print "Execution may stop before this is printed"
    return True


def some_database_request():
    # let's pretend we were getting that from a database
    return defer.succeed(["arthur", "trillian", "barkeeper"])


fixed_value_args = {"heart_of_gold": ["arthur", "ford", "zaphod", "trillian"]}

dynamic_args = {
Esempio n. 5
0
 def test_or_arg_count(self):
     self.failureResultOf(self.run_test(OR(), False), ValueError)
     self.failureResultOf(self.run_test(OR(TRUE()), False), ValueError)
     self.run_test(OR(TRUE(), TRUE()), True)
     self.run_test(OR(TRUE(), TRUE(), TRUE(), TRUE()), True)
Esempio n. 6
0
def async_dynamic_argument_expression():
    return defer.succeed(OR(FALSE(), TRUE()))
Esempio n. 7
0
def sync_dynamic_argument_expression():
    return OR(FALSE(), TRUE())