Esempio n. 1
0
    def reset(self):
        """
        Resets the internal state of the loop
        """

        self.pluginListItr = ListIter(self.pluginList)
        loopCtx(self).reset()
Esempio n. 2
0
 def reset(self):
     """
     Resets the internal state of the loop
     """
     
     self.pluginListItr = ListIter(self.pluginList)
     loopCtx(self).reset()    
Esempio n. 3
0
    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()
Esempio n. 4
0
 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()
Esempio n. 5
0
    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()
Esempio n. 6
0
    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()
Esempio n. 7
0
    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
Esempio n. 8
0
    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
Esempio n. 9
0
 def test_loop_ctx(self):
     loop = Loop(PLUGIN_NAME)
     ctx = loopCtx(loop)
     assert ctx is not None
Esempio n. 10
0
 def test_loop_ctx(self):
     loop = Loop(PLUGIN_NAME)
     ctx = loopCtx(loop)
     assert ctx is not None
Esempio n. 11
0
    def isStop(self):
        ctx = loopCtx(self.parent)
        if (ctx.iter >= self.maxIter):
            ctx.stop()

        return ctx.state == WorkflowState.STOP
Esempio n. 12
0
 def isStop(self):
     ctx = loopCtx(self.parent)
     if(ctx.iter >= self.maxIter):
         ctx.stop()
         
     return ctx.state == WorkflowState.STOP