def test_loading_python_algorithm_increases_registered_algs_by_one(self): loaded = plugins.load(self._testdir) self.assertTrue(len(loaded) > 0) expected_name = 'TestPyAlg' # Has the name appear in the module dictionary self.assertTrue(expected_name in sys.modules) # Do we have the registered algorithm algs = AlgorithmFactory.getRegisteredAlgorithms(True) self.assertTrue(expected_name in algs) # Can it be created? try: test_alg = AlgorithmManager.createUnmanaged(expected_name) self.assertEquals(expected_name, test_alg.name()) self.assertEquals(1, test_alg.version()) except RuntimeError as exc: self.fail("Failed to create plugin algorithm from the manager: '%s' " %s)
def test_loading_python_algorithm_increases_registered_algs_by_one(self): loaded = plugins.load(self._testdir) self.assertTrue(len(loaded) > 0) expected_name = 'TestPyAlg' # Has the name appear in the module dictionary self.assertTrue(expected_name in sys.modules) # Do we have the registered algorithm algs = AlgorithmFactory.getRegisteredAlgorithms(True) self.assertTrue(expected_name in algs) # Can it be created? try: test_alg = AlgorithmManager.createUnmanaged(expected_name) self.assertEquals(expected_name, test_alg.name()) self.assertEquals(1, test_alg.version()) except RuntimeError, exc: self.fail( "Failed to create plugin algorithm from the manager: '%s' " % s)
from mantid.kernel.packagesetup import update_sys_paths as _update_sys_paths _plugins_key = 'python.plugins.directories' _user_key = 'user.%s' % _plugins_key plugin_dirs = _plugins.get_plugin_paths_as_set(_plugins_key) plugin_dirs.update(_plugins.get_plugin_paths_as_set(_user_key)) _update_sys_paths(plugin_dirs, recursive=True) # Load plugin_files = [] alg_files = [] for directory in plugin_dirs: try: all_plugins, algs = _plugins.find_plugins(directory) plugin_files += all_plugins alg_files += algs except ValueError as exc: logger.warning('Exception encountered during plugin discovery: {0}'.format(str(exc))) continue # Mockup the full API first so that any Python algorithm module has something to import _simpleapi._mockup(alg_files) # Load the plugins. plugin_modules = _plugins.load(plugin_files) # Create the proper algorithm definitions in the module new_attrs = _simpleapi._translate() # Finally, overwrite the mocked function definitions in the loaded modules with the real ones _plugins.sync_attrs(_simpleapi, new_attrs, plugin_modules) ################################################################################