Exemple #1
0
 def test_one_plugin(self):
     plugin = Plugin(ctx())
     loop = Loop(plugin)
     
     p = loop.next()
     assert p == plugin
     
     try:
         loop.next()
         assert False
     except StopIteration:
         assert True
Exemple #2
0
    def test_inner_loop(self):
        loop = Loop(Loop([PLUGIN_NAME, PLUGIN_NAME]))

        p = next(loop)
        assert isinstance(p, Plugin)
        p = next(loop)
        assert isinstance(p, Plugin)

        try:
            next(loop)
            assert False
        except StopIteration:
            assert True
Exemple #3
0
 def test_plugin_names(self):
     loop = Loop([PLUGIN_NAME, PLUGIN_NAME])
     
     p = loop.next()
     assert isinstance(p, Plugin)
     p = loop.next()
     assert isinstance(p, Plugin)
     
     try:
         loop.next()
         assert False
     except StopIteration:
         assert True
Exemple #4
0
    def test_loop_max_iter_nested(self):
        maxIter = 3
        pList = [Plugin(ctx()), Plugin(ctx())]

        loop = Loop(Loop(pList, stop=RangeStopCriteria(maxIter=maxIter)),
                    stop=RangeStopCriteria(maxIter=maxIter))

        cnt = 0
        for p in loop:
            assert isinstance(p, Plugin)
            p()
            cnt += 1

        assert cnt == len(pList) * maxIter * maxIter
Exemple #5
0
 def test_plugin_instances(self):
     plugin1 = Plugin(ctx())
     plugin2 = Plugin(ctx())
     loop = Loop([plugin1, plugin2])
     
     p = loop.next()
     assert p == plugin1
     p = loop.next()
     assert p == plugin2
     
     try:
         loop.next()
         assert False
     except StopIteration:
         assert True
    def __init__(self,
                 pluginList,
                 mapPlugin,
                 reducePlugin=None,
                 ctx=None,
                 parallel=True):
        '''
        Constructor
        '''
        if ctx is None:
            ctx = context.ctx()
        self.ctx = ctx

        super(ParallelPluginCollection, self).__init__(self.ctx)

        if not isinstance(pluginList, Loop):
            pluginList = Loop(pluginList)

        self.pluginList = pluginList

        if mapPlugin is None:
            raise InvalidAttributeException("No map plugin provided")

        self.mapPlugin = mapPlugin
        self.reducePlugin = reducePlugin
        self.parallel = parallel
Exemple #7
0
    def test_loop_pickle(self):
        loop = Loop([PLUGIN_NAME, PLUGIN_NAME])
        p = loop.next()

        sLoop = dumps(loop)
        loop2 = loads(sLoop)

        for p in loop2:
            p()

        loop.reset()

        sLoop = dumps(loop)
        loop2 = loads(sLoop)

        for p in loop2:
            p()
Exemple #8
0
    def test_loop_pickle(self):
        loop = Loop([PLUGIN_NAME, PLUGIN_NAME])
        p = loop.next()
        
        sLoop = dumps(loop)
        loop2 = loads(sLoop)
        
        for p in loop2:
            p()

        loop.reset()
        
        sLoop = dumps(loop)
        loop2 = loads(sLoop)
        
        for p in loop2:
            p()
Exemple #9
0
    def test_unknown_plugin(self):
        plugin = "unknown.plugin.invalid"
        loop = Loop(plugin)
        try:
            next(loop)
            assert False
        except UnsupportedPluginTypeException as ex:
            print(ex)
            assert True

        plugin = {}
        loop = Loop(plugin)
        try:
            next(loop)
            assert False
        except UnsupportedPluginTypeException as ex:
            print(ex)
            assert True
Exemple #10
0
    def test_loop_iter(self):
        pList = [PLUGIN_NAME, PLUGIN_NAME]
        loop = Loop(pList)

        cnt = 0
        for p in loop:
            assert isinstance(p, Plugin)
            cnt += 1

        assert cnt == len(pList)
Exemple #11
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
Exemple #12
0
    def test_loop_max_iter(self):
        maxIter = 3
        pList = [PLUGIN_NAME, PLUGIN_NAME]

        loop = Loop(pList, stop=RangeStopCriteria(maxIter=maxIter))

        cnt = 0
        for p in loop:
            assert isinstance(p, Plugin)
            cnt += 1

        assert cnt == len(pList) * maxIter
Exemple #13
0
    def test_one_plugin(self):
        plugin = Plugin(ctx())
        loop = Loop(plugin)

        p = next(loop)
        assert p == plugin

        try:
            next(loop)
            assert False
        except StopIteration:
            assert True
Exemple #14
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()
Exemple #15
0
    def test_plugin_instances(self):
        plugin1 = Plugin(ctx())
        plugin2 = Plugin(ctx())
        loop = Loop([plugin1, plugin2])

        p = next(loop)
        assert p == plugin1
        p = next(loop)
        assert p == plugin2

        try:
            next(loop)
            assert False
        except StopIteration:
            assert True
 def _setup(self, argv):
     config = self._parseArgs(argv)
     
     if not config.has_key(PLUGINS_KEY):
         raise InvalidAttributeException("plugins definition is missing")
     
     if config.has_key(CONTEXT_PROVIDER_KEY):
         def getContextProviderWrapper():
             #todo load class not module
             clazz = config[CONTEXT_PROVIDER_KEY]
             moduleName = ".".join(clazz.split(".")[:-1])
             module = importlib.import_module(moduleName)
             return getattr(module, clazz.split(".")[-1])
         context.getContextProvider = getContextProviderWrapper
     
     if not isinstance(config[PLUGINS_KEY], Loop):
         config[PLUGINS_KEY] = Loop(config[PLUGINS_KEY])
         
     ctx().params = context._createImmutableCtx(**config)
     #just to maintain backward compatibility
     ctx().parameters = ctx().params
     ctx().plugins = ctx().params.plugins
Exemple #17
0
 def test_unknown_plugin(self):
     plugin = "unknown.plugin.invalid"
     loop = Loop(plugin)
     try:
         loop.next()
         assert False
     except UnsupportedPluginTypeException as ex:
         print(ex)
         assert True
     
     plugin = {}
     loop = Loop(plugin)
     try:
         loop.next()
         assert False
     except UnsupportedPluginTypeException as ex:
         print(ex)
         assert True
Exemple #18
0
# IVY is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IVY is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IVY.  If not, see <http://www.gnu.org/licenses/>.
'''
Created on Mar 5, 2014

author: jakeret
'''
from ivy.config import base_config
from ivy.loop import Loop

plugins = Loop(["test.plugin.simple_plugin", "test.plugin.simple_plugin"])
Exemple #19
0
 def test_loop_ctx(self):
     loop = Loop(PLUGIN_NAME)
     ctx = loopCtx(loop)
     assert ctx is not None
Exemple #20
0
 def test_none(self):
     try:
         loop = Loop(None)
         assert False
     except InvalidLoopException:
         assert True