Example #1
0
 def test_fixed_values(self):
     return defer.DeferredList([
         self.run_test(AND("fixed_arg_true", TRUE()), True),
         self.run_test(AND("fixed_arg_false", TRUE()), False),
         self.run_test(ELEMENT_OF("doesntexist", "fixed_arg_list"), False),
         self.run_test(ELEMENT_OF("test", "fixed_arg_list"), True),
     ])
Example #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),
     ])
Example #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),
     ])
Example #4
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)
     ])
Example #5
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 = {
Example #6
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)
Example #7
0
 def test_true(self):
     return self.run_test(TRUE(), True)
Example #8
0
def async_dynamic_argument_expression():
    return defer.succeed(OR(FALSE(), TRUE()))
Example #9
0
def sync_dynamic_argument_expression():
    return OR(FALSE(), TRUE())
Example #10
0
    def test_not_arg_count(self):
        with self.assertRaises(TypeError):
            self.run_test(NOT(), False)

        with self.assertRaises(TypeError):
            self.run_test(NOT(TRUE(), TRUE()), False)
Example #11
0
 def test_and(self):
     return defer.DeferredList([
         self.run_test(AND(TRUE(), TRUE(), AND(TRUE(), TRUE())), True),
         self.run_test(AND(TRUE(), TRUE(), AND(TRUE(), FALSE())), False),
         self.run_test(AND(FALSE(), TRUE(), TRUE(), TRUE(), TRUE()), False),
         self.run_test(AND(TRUE(), TRUE(), TRUE(), TRUE(), FALSE()), False)
     ])