Пример #1
0
 def resume(old_state, new_state, event):
     # This reaction function just updates the state machines memory
     # to include any nodes that need to be executed (from a previous
     # attempt, which may be empty if never ran before) and any nodes
     # that are now ready to be ran.
     memory.next_up.update(
         iter_utils.unique_seen(self._completer.resume(),
                                iter_next_atoms()))
     return SCHEDULE
 def test_unique_seen(self):
     iters = [
         ['a', 'b'],
         ['a', 'c', 'd'],
         ['a', 'e', 'f'],
         ['f', 'm', 'n'],
     ]
     self.assertEqual(['a', 'b', 'c', 'd', 'e', 'f', 'm', 'n'],
                      list(iter_utils.unique_seen(iters)))
Пример #3
0
 def resume(old_state, new_state, event):
     # This reaction function just updates the state machines memory
     # to include any nodes that need to be executed (from a previous
     # attempt, which may be empty if never ran before) and any nodes
     # that are now ready to be ran.
     memory.next_up.update(
         iter_utils.unique_seen((self._completer.resume(),
                                 iter_next_atoms())))
     return SCHEDULE
 def test_unique_seen_selector(self):
     iters = [
         [(1, 'a'), (1, 'a')],
         [(2, 'b')],
         [(3, 'c')],
         [(1, 'a'), (3, 'c')],
     ]
     it = iter_utils.unique_seen(iters,
                                 seen_selector=lambda value: value[0])
     self.assertEqual([(1, 'a'), (2, 'b'), (3, 'c')], list(it))
Пример #5
0
 def iter_next_atoms(self, atom=None):
     """Iterate next atoms to run (originating from atom or all atoms)."""
     if atom is None:
         return iter_utils.unique_seen(self.browse_atoms_for_execute(),
                                       self.browse_atoms_for_revert())
     state = self.get_state(atom)
     intention = self._storage.get_atom_intention(atom.name)
     if state == st.SUCCESS:
         if intention == st.REVERT:
             return iter([
                 (atom, NoOpDecider()),
             ])
         elif intention == st.EXECUTE:
             return self.browse_atoms_for_execute(atom=atom)
         else:
             return iter([])
     elif state == st.REVERTED:
         return self.browse_atoms_for_revert(atom=atom)
     elif state == st.FAILURE:
         return self.browse_atoms_for_revert()
     else:
         return iter([])
Пример #6
0
 def iter_next_atoms(self, atom=None):
     """Iterate next atoms to run (originating from atom or all atoms)."""
     if atom is None:
         return iter_utils.unique_seen((self.browse_atoms_for_execute(),
                                        self.browse_atoms_for_revert()),
                                       seen_selector=operator.itemgetter(0))
     state = self._storage.get_atom_state(atom.name)
     intention = self._storage.get_atom_intention(atom.name)
     if state == st.SUCCESS:
         if intention == st.REVERT:
             return iter([
                 (atom, deciders.NoOpDecider()),
             ])
         elif intention == st.EXECUTE:
             return self.browse_atoms_for_execute(atom=atom)
         else:
             return iter([])
     elif state == st.REVERTED:
         return self.browse_atoms_for_revert(atom=atom)
     elif state == st.FAILURE:
         return self.browse_atoms_for_revert()
     else:
         return iter([])
 def test_unique_seen_empty(self):
     iters = []
     self.assertEqual([], list(iter_utils.unique_seen(iters)))