コード例 #1
0
    def test_hello_world_and(self):
        # First set the condition to true so we see Hello World! in the out put.
        actionPass = SampleOutAction(
            "I have a true action condition... Hello World!")
        actionPass.addAndCondition(SampleCondition(True))
        Engine(actions=[actionPass], data=EngineData()).execute()

        # output: I have a true action condition... Hello World!

        # Now we set the condition to false to prevent SampleAction from execution.
        actionFail = SampleOutAction("I have a false condition...")
        actionFail.addAndCondition(SampleCondition(False))
        Engine(actions=[actionFail], data=EngineData()).execute()

        # No output.

        # Now back to true but with a EnginePipeline condition set to false.
        actionFailWithGeneralCondition1 = SampleOutAction(
            "I have a true action condition but a false pipeline condition...")
        actionFailWithGeneralCondition1.addAndCondition(SampleCondition(True))
        Engine(actions=[actionFailWithGeneralCondition1],
               data=EngineData(),
               ands=[SampleCondition(False)]).execute()

        # No output.

        # Now back to true but with a EnginePipeline condition set to true.
        actionFailWithGeneralCondition2 = SampleOutAction(
            "I have a true action condition and a true pipeline condition... Hello World!"
        )
        actionFailWithGeneralCondition2.addAndCondition(SampleCondition(True))
        Engine(actions=[actionFailWithGeneralCondition2],
               data=EngineData(),
               ands=[SampleCondition(True)]).execute()
コード例 #2
0
    def test_hello_world_or(self):
        # First set one condition true and one false...
        actionPass = SampleOutAction(
            "I have 2 conditions true and false... Hello World!")
        actionPass.addOrCondition(SampleCondition(True)).addOrCondition(
            SampleCondition(True))
        Engine(actions=[actionPass], data=EngineData()).execute()

        # output: I have 2 conditions true and false... Hello World!

        # Then we set both conditions false
        actionFail = SampleOutAction(
            "I have 2 conditions false and false... Hello World!")
        actionFail.addOrCondition(SampleCondition(False)).addOrCondition(
            SampleCondition(False))
        Engine(actions=[actionFail], data=EngineData()).execute()

        # No output.

        # Then we set both conditions false, and we pass a pipeline true condition...
        actionPassWithGeneralCondition = SampleOutAction(
            "I have 2 conditions false and false, with a true pipeline condition... Hello World!"
        )
        actionPassWithGeneralCondition.addOrCondition(
            SampleCondition(False)).addOrCondition(SampleCondition(False))
        Engine(actions=[actionPassWithGeneralCondition],
               data=EngineData(),
               ors=[SampleCondition(True)]).execute()
コード例 #3
0
 def test_engine_pipeline_TrueFalse_2actions_fail(self):
     d = self.d()
     Engine(actions=[self.a1(), self.a2()],
            data=d,
            ands=[self.f(), self.t()]).execute()
     assert d.get("key1") is None
     assert d.get("key2") is None
コード例 #4
0
 def test_TrueFalseOrs_pass(self):
     a1 = self.a1().addOrCondition(self.t()).addOrCondition(self.f())
     a2 = self.a2().addOrCondition(self.t()).addOrCondition(self.f())
     data = self.d()
     Engine(actions=[a1, a2], data=data).execute()
     assert data.get("key1") == "one"
     assert data.get("key2") == "two"
コード例 #5
0
 def test_TrueTrueOrs_TrueFalseAnds_fails(self):
     d = self.d()
     a1 = self.a1()
     a1.addOrCondition(self.t()).addOrCondition(self.t()).addAndCondition(
         self.t()).addAndCondition(self.f())
     Engine(actions=[a1], data=d).execute()
     assert d.get("key1") is None
コード例 #6
0
 def test_FalseOrCondition_fail(self):
     a1 = self.a1().addOrCondition(self.f())
     a2 = self.a2().addOrCondition(self.f())
     data = self.d()
     Engine(actions=[a1, a2], data=data).execute()
     assert data.get("key1") is None
     assert data.get("key2") is None
コード例 #7
0
 def test_FalseFalse_FalseTrue_Ors_Condition_2actions_fail_pass(self):
     a1 = self.a1().addOrCondition(self.f()).addOrCondition(self.f())
     a2 = self.a2().addOrCondition(self.f()).addOrCondition(self.t())
     data = self.d()
     Engine(actions=[a1, a2], data=data).execute()
     assert data.get("key1") is None
     assert data.get("key2") == "two"
コード例 #8
0
 def test_TrueFalseAndCondition_2actions_1pass_2fail(self):
     a1 = self.a1().addAndCondition(self.t()).addAndCondition(self.t())
     a2 = self.a2().addAndCondition(self.f()).addAndCondition(self.t())
     data = self.d()
     Engine(actions=[a1, a2], data=data).execute()
     assert data.get("key1") == "one"
     assert data.get("key2") is None
コード例 #9
0
 def test_engine_pipeline_pass(self):
     d = self.d()
     Engine(actions=[self.a1(), self.a2(), self.a3()],
            data=d,
            ands=[self.f(), self.t()]).execute()
     assert d.get("key1") is None
     assert d.get("key2") is None
     assert d.get("key3") is None
コード例 #10
0
 def test_engine_pipeline_TrueFalseOr_TrueTrueAnd_2actions_pass(self):
     d = self.d()
     Engine(actions=[self.a1(), self.a2()],
            data=d,
            ors=[self.f(), self.t()],
            ands=[self.t(), self.t()]).execute()
     assert d.get("key1") == "one"
     assert d.get("key2") == "two"
コード例 #11
0
 def test_NullEngineData_fail(self):
     result = None
     try:
         Engine(actions=SampleAction("key1", "one"), data=None)
     except Exception as e:
         result = e
     finally:
         assert isinstance(result, Exception)
コード例 #12
0
 def test_EmptyActions_fail(self):
     result = None
     try:
         Engine(actions=[], data=EngineData())
     except Exception as e:
         result = e
     finally:
         assert isinstance(result, EngineException)
コード例 #13
0
 def test_engine_pipeline_fail_pass_fail(self):
     d = self.d()
     a2 = self.a2().addOrCondition(self.t())
     Engine(actions=[self.a1(), a2, self.a3()],
            data=d,
            ors=[self.f()],
            ands=[self.t()]).execute()
     assert d.get("key1") is None
     assert d.get("key2") == "two"
     assert d.get("key3") is None
コード例 #14
0
 def test_engine_pipeline_fail_fail_pass(self):
     d = self.d()
     a1 = self.a1().addOrCondition(self.t()).addAndCondition(self.f())
     a2 = self.a2().addOrCondition(self.t()).addAndCondition(self.f())
     a3 = self.a3().addOrCondition(self.t())
     Engine(actions=[a1, a2, a3], data=d, ors=[self.f()],
            ands=[self.t()]).execute()
     assert d.get("key1") is None
     assert d.get("key2") is None
     assert d.get("key3") == "three"
コード例 #15
0
 def test_allTogether(self):
     d = self.d()
     a1 = self.a1()
     a1 = self.a1().addOrCondition(self.t()).addOrCondition(
         self.t()).addAndCondition(self.t()).addAndCondition(self.f())
     a2 = self.a2().addOrCondition(self.t()).addOrCondition(
         self.f()).addAndCondition(self.t())
     a3 = self.a3().addAndCondition(self.f())
     Engine(actions=[a1, a2, a3], data=d).execute()
     assert d.get("key1") is None
     assert d.get("key2") == "two"
     assert d.get("key3") is None
コード例 #16
0
 def test_engine_pipeline_True_pass(self):
     d = self.d()
     Engine(actions=[self.a1()], data=d, ands=[self.t()]).execute()
     assert d.get("key1") == "one"
コード例 #17
0
 def test_NoConditions_pass(self):
     data = EngineData()
     Engine(actions=[self.a1(), self.a2()], data=data).execute()
     assert data.get("key1") == "one"
     assert data.get("key2") == "two"
コード例 #18
0
 def test_helloWorld(self):
     Engine(actions=[SampleOutAction(content="Hello World!")],
            data=EngineData()).execute()
コード例 #19
0
 def test_FalseAnd_general_TrueOr_TrueAnd_fail(self):
     d = self.d()
     a1 = self.a1().addAndCondition(self.f())
     Engine(actions=[a1], data=d, ors=[self.t()], ands=[self.t()]).execute()
     assert d.get("key1") is None
コード例 #20
0
 def test_TrueOr_general_FalseOr_TrueAnd_pass(self):
     d = self.d()
     a1 = self.a1().addOrCondition(self.t())
     Engine(actions=[a1], data=d, ors=[self.f()], ands=[self.t()]).execute()
     assert d.get("key1") == "one"
コード例 #21
0
 def test_engine_pipeline_False_fail(self):
     d = self.d()
     Engine(actions=[self.a1()], data=d, ors=[self.f()]).execute()
     assert d.get("key1") is None