def reset(self): """ Resets the internal state of the loop """ self.pluginListItr = ListIter(self.pluginList) loopCtx(self).reset()
def test_RangeStopCriteria(self): try: stopCriteria = RangeStopCriteria(0) pytest.fail("0 iterations not allowed") except InvalidAttributeException: assert True stopCriteria = RangeStopCriteria(1) loop = Loop("", stopCriteria) assert False == stopCriteria.isStop() loopCtx(loop).increment() assert True == stopCriteria.isStop()
def next(self): """ Returns the next plugin. Allows for using a Loop as an iter """ try: if (self._stopCriteria.isStop()): raise StopIteration if self._currentPlugin is None: self._currentPlugin = self.pluginListItr.next() plugin = self._currentPlugin if isinstance(plugin, BasePlugin): self._currentPlugin = None plugin.ctx = self.ctx return plugin if isinstance(plugin, basestring): self._currentPlugin = None return self._instantiate(plugin) if isinstance(self._currentPlugin, Loop): innerLoop = self._currentPlugin try: plugin = innerLoop.next() return plugin except StopIteration: if (loopCtx(innerLoop).state == WorkflowState.EXIT): raise StopIteration #inner loopCtx(innerLoop).reset() self._currentPlugin = None return self.next() else: raise UnsupportedPluginTypeException() except StopIteration: loopCtx(self).increment() self._createIter() if (self._stopCriteria.isStop()): raise StopIteration else: return self.next()
def next(self): """ Returns the next plugin. Allows for using a Loop as an iter """ try: if(self._stopCriteria.isStop()): raise StopIteration if self._currentPlugin is None: self._currentPlugin = self.pluginListItr.next() plugin = self._currentPlugin if isinstance(plugin, BasePlugin): self._currentPlugin = None plugin.ctx = self.ctx return plugin if isinstance(plugin, basestring): self._currentPlugin = None return self._instantiate(plugin) if isinstance(self._currentPlugin, Loop): innerLoop = self._currentPlugin try: plugin = innerLoop.next() return plugin except StopIteration: if(loopCtx(innerLoop).state == WorkflowState.EXIT): raise StopIteration #inner loopCtx(innerLoop).reset() self._currentPlugin = None return self.next() else: raise UnsupportedPluginTypeException() except StopIteration: loopCtx(self).increment() self._createIter() if(self._stopCriteria.isStop()): raise StopIteration else: return self.next()
def test_register(self): loop = Loop("plugin") try: register(loop) pytest.fail("Loop registered twice") except InvalidLoopException as ex: assert True lctx = loopCtx(loop) assert lctx is not None
def test_loop_ctx(self): loop = Loop(PLUGIN_NAME) ctx = loopCtx(loop) assert ctx is not None
def isStop(self): ctx = loopCtx(self.parent) if (ctx.iter >= self.maxIter): ctx.stop() return ctx.state == WorkflowState.STOP
def isStop(self): ctx = loopCtx(self.parent) if(ctx.iter >= self.maxIter): ctx.stop() return ctx.state == WorkflowState.STOP