def test_create_immu_ctx(self): ctx = context._createImmutableCtx() assert isinstance(ctx, ImmutableStruct) ctx = context._createImmutableCtx(a=3) assert isinstance(ctx, ImmutableStruct) assert ctx.a == 3 args = {"a": 3} ctx = context._createImmutableCtx(**args) assert isinstance(ctx, ImmutableStruct) assert ctx.a == 3
def test_create_immu_ctx(self): ctx = context._createImmutableCtx() assert isinstance(ctx, ImmutableStruct) ctx = context._createImmutableCtx(a=3) assert isinstance(ctx, ImmutableStruct) assert ctx.a == 3 args = {"a":3} ctx = context._createImmutableCtx(**args) assert isinstance(ctx, ImmutableStruct) assert ctx.a == 3
def test_multiprocessing(self): ctx = context.ctx() ctx.timings = [] ctx.params = context._createImmutableCtx(backend="multiprocessing", cpu_count=8, valuesMin = 1, valuesMax = 10) mapPlugin = range_map_plugin.Plugin(ctx) pluginList = [PLUGIN_NAME] reducePlugin = sum_reduce_plugin.Plugin(ctx) parallelPluginCollection = ParallelPluginCollection(pluginList, mapPlugin, reducePlugin) parallelPluginCollection() assert ctx.valuesSum == 285
def test_multiprocessing(self): ctx = context.ctx() ctx.timings = [] ctx.params = context._createImmutableCtx(backend="multiprocessing", cpu_count=8, valuesMin = 1, valuesMax = 10) mapPlugin = range_map_plugin.Plugin(ctx) pluginList = [PLUGIN_NAME] reducePlugin = sum_reduce_plugin.Plugin(ctx) parallelPluginCollection = ParallelPluginCollection(pluginList, mapPlugin, reducePlugin) parallelPluginCollection() assert ctx.valuesSum == 285
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