예제 #1
0
 def test_look_and_feel(self):
     br = Runnable(), Runnable()
     pb = Branches(*br)
     self.assertEqual(pb.name, 'Branches')
     self.assertEqual(str(pb), '(Runnable) & (Runnable)')
     self.assertEqual(repr(pb), 'Branches(Runnable(), Runnable())')
     self.assertEqual(tuple(pb), br)
예제 #2
0
 def test_look_and_feel(self):
     br = Runnable(), Runnable()
     rb = RacingBranches(*br)
     self.assertEqual(rb.name, 'RacingBranches')
     self.assertEqual(str(rb), '(Runnable) !! (Runnable)')
     self.assertEqual(repr(rb), 'RacingBranches(Runnable(), Runnable())')
     self.assertEqual(tuple(rb), br)
 def test_iter_walk(self):
     flow = Loop(RacingBranches(Runnable(), Runnable()) | ArgMin())
     names = [r.name for r in iter_inorder(flow)]
     self.assertEqual(names, [
         'Loop', 'Branch', 'RacingBranches', 'Runnable', 'Runnable',
         'ArgMin'
     ])
 def test_callback_walk(self):
     flow = Loop(RacingBranches(Runnable(), Runnable()) | ArgMin())
     names = []
     walk_inorder(flow, visit=lambda r, _: names.append(r.name))
     self.assertEqual(names, [
         'Loop', 'Branch', 'RacingBranches', 'Runnable', 'Runnable',
         'ArgMin'
     ])
예제 #5
0
 def test_look_and_feel(self):
     r = Runnable()
     self.assertEqual(r.name, 'Runnable')
     self.assertEqual(str(r), 'Runnable')
     self.assertEqual(repr(r), 'Runnable()')
     self.assertEqual(tuple(r), tuple())
     self.assertRaises(NotImplementedError, r.next, State())
     self.assertIsNone(r.stop())
     self.assertIsInstance(r | r, Branch)
예제 #6
0
 def test_input_validation(self):
     with self.assertRaises(TypeError):
         Map(False)
     with self.assertRaises(TypeError):
         Map(lambda: None)
     with self.assertRaises(TypeError):
         Map(Runnable)
     self.assertIsInstance(Map(Runnable()), Runnable)
예제 #7
0
    def test_simple_run(self):
        r = Runnable()

        # async run with valid state
        f = r.run(State())
        self.assertIsInstance(f, Future)
        self.assertNotIsInstance(f, Present)
        self.assertRaises(NotImplementedError, f.result)

        # sync run with valid state
        f = r.run(State(), executor=immediate_executor)
        self.assertIsInstance(f, Present)
        self.assertRaises(NotImplementedError, f.result)

        # run with error state, check exc is propagated (default)
        f = r.run(Present(exception=ZeroDivisionError()))
        self.assertRaises(ZeroDivisionError, f.result)

        class MyRunnable(Runnable):
            def init(self, state):
                self.first = state.problem

            def next(self, state):
                return state.updated(problem=state.problem + 1)

        r = MyRunnable()
        s1 = State(problem=1)
        s2 = r.run(s1).result()

        self.assertEqual(r.first, s1.problem)
        self.assertEqual(s2.problem, s1.problem + 1)
예제 #8
0
 def test_runnable(self):
     self.assertEqual(list(Runnable()), [])
 def test_runnable_default_counter_value(self):
     self.assertEqual(Runnable().counters['my-counter'], 0)
 def test_runnable_default_timer_value(self):
     self.assertEqual(Runnable().timers['my-timer'], [])