Пример #1
0
 def test_unassigned_out(self):
     
     subgraph = G(
         C(START_TICK, "sin", 1, "x"),
         T(1, "subtask"),
         C(1, "y", FINAL_TICK, "sout")
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           C(START_TICK, "sout2", 1, "sout2"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           C(1, "sout2", FINAL_TICK, "out2")
           )
     
     expected  = G(
           C(START_TICK, "in", (1,1), "x"),
           T((1,1), "subtask"),
           C((1,1), "y", FINAL_TICK, "out"),
           C(START_TICK, "sout2", FINAL_TICK, "out2")
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
Пример #2
0
    def test_get_task_state_waiting_for_refiner(self):
        task = MockTask("in")
        g = G(T(1, tasks.ConstTask(None)), C(1, "value", 2, "in"), T(2, task),
              C(2, "out", FINAL_TICK, "retval"))
        self.target.execute(g, {"a": "refinedata"})

        self.assertEqual(traverser.TaskState.WAITING_FOR_REFINE_INPUTS,
                         self.target.get_task_state(TICK2))
Пример #3
0
 def test_get_task_state_evaluated(self):
     g = G(T(1, tasks.ConstTask(None)), C(1, "value", 2, "in"),
           T(2, "task"), C(2, "out", FINAL_TICK, "retval"))
     self.target.execute(g, {})
     self.next_ready()[-1].callback(traverser.EvalResult({"value":
                                                          "Hello"}))
     self.assertEqual(traverser.TaskState.EVALUATED,
                      self.target.get_task_state(TICK1))
Пример #4
0
 def test_injest_result(self):
     g = G(T(1, tasks.ConstTask(None)), C(1, "value", 2, "in"),
           T(2, "task"), C(2, "out", FINAL_TICK, "retval"))
     self.target.execute(g, {})
     self.next_ready()[-1].callback(traverser.EvalResult({"value":
                                                          "Hello"}))
     self.assertEqual((TICK2, "task", {
         "in": "Hello"
     }),
                      self.next_ready()[1:-1])
Пример #5
0
    def test_mocking(self):
        self.target.add_task(START_TICK + 100, "task1", {'nicename': 'test1'})
        self.target.add_task(START_TICK + 101, "task2", {'nicename': 'test2'})
        self.target.connect(graph.Endpoint(START_TICK + 100, 'out'),
                            graph.Endpoint(START_TICK + 101, 'in'))

        expected = G(
            T(100, 'task1', {'nicename': 'test1'}),
            C(100, 'out', 101, 'in'),
            T(101, 'task2', {'nicename': 'test2'}),
        )

        utils.assert_graph_equal(expected, self.target)
Пример #6
0
    def test_finish_nomoretasks(self):
        g = G(T(1, tasks.ConstTask(None)), C(1, "value", FINAL_TICK, "retval"))
        self.target.execute(g, {})

        self.next_ready()[-1].callback({"value": "Hello"})

        self.assertIsNone(self.next_ready())
Пример #7
0
    def test_get_task_state_refining(self):
        task = MockTask("in")
        g = G(C(START_TICK, "a", 1, "in"), T(1, task),
              C(1, "out", FINAL_TICK, "retval"))
        self.target.execute(g, {"a": "refinedata"})

        self.assertEqual(traverser.TaskState.REFINING,
                         self.target.get_task_state(TICK1))
Пример #8
0
    def test_refine_only_once(self):
        task = MockTask("in")
        g = G(C(START_TICK, "a", 1, "in"), T(1, task),
              C(1, "out", FINAL_TICK, "retval"))
        self.target.execute(g, {"a": "refinedata"})

        self.next_refine()[-1].callback(None)
        self.assertEqual(None, self.next_refine())
Пример #9
0
    def test_finish(self):
        g = G(T(1, tasks.ConstTask(None)), C(1, "value", FINAL_TICK, "retval"))
        d = self.target.execute(g, {})
        self.next_ready()[-1].callback(traverser.EvalResult({"value":
                                                             "Hello"}))

        outputs = extract(d)
        self.assertEqual({"retval": "Hello"}, outputs)
Пример #10
0
    def test_eval_fail(self):
        g = G(T(1, tasks.ConstTask(None)), C(1, "value", FINAL_TICK, "retval"))
        d = self.target.execute(g, {})
        self.next_ready()[-1].errback(failure.Failure(MockError()))

        f = twistit.extract_failure(d)
        self.assertTrue(f.check(traverser.EvaluationError))
        self.assertTrue(f.value.cause.check(MockError))
        self.assertEqual(Tick.parse_tick(1), f.value.tick)
Пример #11
0
    def test_refine_called(self):
        task = MockTask("in")
        g = G(C(START_TICK, "a", 1, "in"), T(1, task),
              C(1, "out", FINAL_TICK, "retval"))
        self.target.execute(g, {"a": "refinedata"})

        self.assertEqual((TICK1, task, {
            "in": "refinedata"
        }),
                         self.next_refine()[1:-1])
Пример #12
0
    def test_refine_fail(self):
        task = MockTask("in")
        g = G(C(START_TICK, "a", 1, "in"), T(1, task),
              C(1, "out", FINAL_TICK, "retval"))
        d = self.target.execute(g, {"a": "refinedata"})

        self.next_refine()[-1].errback(failure.Failure(MockError()))

        f = twistit.extract_failure(d)
        self.assertTrue(f.check(traverser.RefineError))
        self.assertTrue(f.value.cause.check(MockError))
        self.assertEqual(Tick.parse_tick(1), f.value.tick)
Пример #13
0
    def test_refine_removes_task(self):
        task = MockTask("in")
        g = G(C(START_TICK, "a", 1, "in"), T(1, task),
              C(1, "out", FINAL_TICK, "retval"))
        self.target.execute(g, {"a": "refinedata"})

        refine_g, _, _, _, refine_d = self.next_refine()
        refine_g.disconnect(Endpoint(START_TICK, "a"), Endpoint(TICK1, "in"))
        refine_g.disconnect(Endpoint(TICK1, "out"),
                            Endpoint(FINAL_TICK, "retval"))
        refine_g.remove_task(TICK1)
        refine_d.callback(None)

        self.assertEqual(None, self.next_refine())
Пример #14
0
 def test_passhtrough(self):
     
     subgraph = G(
         C(START_TICK, "sin", FINAL_TICK,"sout"),
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           )
     
     expected  = G(
           C(START_TICK, "in", FINAL_TICK, "out"),
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
     
Пример #15
0
 def test_eval_not_before_refine(self):
     task = MockTask("in")
     g = G(C(START_TICK, "a", 1, "in"), T(1, task),
           C(1, "out", FINAL_TICK, "retval"))
     self.target.execute(g, {"a": "refinedata"})
     self.assertEqual(None, self.next_ready())
Пример #16
0
 def test_no_inputs_task_ready(self):
     g = G(T(1, tasks.ConstTask(None)), C(1, "value", FINAL_TICK, "retval"))
     self.target.execute(g, {})
     self.assertEqual((TICK1, tasks.ConstTask(None), {}),
                      self.next_ready()[1:-1])
     self.assertEqual(None, self.next_ready())
Пример #17
0
 def test_get_task_state_waiting_for_inputs(self):
     g = G(T(1, tasks.ConstTask(None)), C(1, "value", 2, "in"),
           T(2, "task"), C(2, "out", FINAL_TICK, "retval"))
     self.target.execute(g, {})
     self.assertEqual(traverser.TaskState.WAITING_FOR_INPUTS,
                      self.target.get_task_state(TICK2))