Python stevedore.extension.Extension() Examples
The following are 30
code examples of stevedore.extension.Extension().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stevedore.extension
, or try the search function
.
Example #1
Source File: test_driver.py From stevedore with Apache License 2.0 | 6 votes |
def test_multiple_drivers(self): # The idea for this test was contributed by clayg: # https://gist.github.com/clayg/6311348 extensions = [ extension.Extension( 'backend', pkg_resources.EntryPoint.parse('backend = pkg1:driver'), 'pkg backend', None, ), extension.Extension( 'backend', pkg_resources.EntryPoint.parse('backend = pkg2:driver'), 'pkg backend', None, ), ] try: dm = driver.DriverManager.make_test_instance(extensions[0]) # Call the initialization code that verifies the extension dm._init_plugins(extensions) except exception.MultipleMatches as err: self.assertIn("Multiple", str(err)) else: self.fail('Should have had an error')
Example #2
Source File: test_driver.py From bazarr with GNU General Public License v3.0 | 6 votes |
def test_multiple_drivers(self): # The idea for this test was contributed by clayg: # https://gist.github.com/clayg/6311348 extensions = [ extension.Extension( 'backend', pkg_resources.EntryPoint.parse('backend = pkg1:driver'), 'pkg backend', None, ), extension.Extension( 'backend', pkg_resources.EntryPoint.parse('backend = pkg2:driver'), 'pkg backend', None, ), ] try: dm = driver.DriverManager.make_test_instance(extensions[0]) # Call the initialization code that verifies the extension dm._init_plugins(extensions) except exception.MultipleMatches as err: self.assertIn("Multiple", str(err)) else: self.fail('Should have had an error')
Example #3
Source File: test_os_vif.py From os-vif with Apache License 2.0 | 6 votes |
def test_unplug(self, mock_unplug): plg = extension.Extension(name="demo", entry_point="os-vif", plugin=DemoPlugin, obj=None) with mock.patch('stevedore.extension.ExtensionManager.names', return_value=['foobar']),\ mock.patch('stevedore.extension.ExtensionManager.__getitem__', return_value=plg): os_vif.initialize() info = objects.instance_info.InstanceInfo() vif = objects.vif.VIFBridge( id='9a12694f-f95e-49fa-9edb-70239aee5a2c', plugin='foobar') os_vif.unplug(vif, info) mock_unplug.assert_called_once_with(vif, info)
Example #4
Source File: test_os_vif.py From os-vif with Apache License 2.0 | 6 votes |
def test_plug(self, mock_plug): plg = extension.Extension(name="demo", entry_point="os-vif", plugin=DemoPlugin, obj=None) with mock.patch('stevedore.extension.ExtensionManager.names', return_value=['foobar']),\ mock.patch('stevedore.extension.ExtensionManager.__getitem__', return_value=plg): os_vif.initialize() info = objects.instance_info.InstanceInfo() vif = objects.vif.VIFBridge( id='9a12694f-f95e-49fa-9edb-70239aee5a2c', plugin='foobar') os_vif.plug(vif, info) mock_plug.assert_called_once_with(vif, info)
Example #5
Source File: test_goal_loader.py From watcher with Apache License 2.0 | 6 votes |
def test_goal_loader(self): dummy_goal_name = "dummy" # Set up the fake Stevedore extensions fake_extmanager_call = extension.ExtensionManager.make_test_instance( extensions=[extension.Extension( name=dummy_goal_name, entry_point="%s:%s" % ( goals.Dummy.__module__, goals.Dummy.__name__), plugin=goals.Dummy, obj=None, )], namespace="watcher_goals", ) with mock.patch.object(extension, "ExtensionManager") as m_ext_manager: m_ext_manager.return_value = fake_extmanager_call loaded_goal = self.goal_loader.load("dummy") self.assertEqual("dummy", loaded_goal.name) self.assertEqual("Dummy goal", loaded_goal.display_name)
Example #6
Source File: test_default_strategy_loader.py From watcher with Apache License 2.0 | 6 votes |
def test_strategy_loader(self): dummy_strategy_name = "dummy" # Set up the fake Stevedore extensions fake_extmanager_call = extension.ExtensionManager.make_test_instance( extensions=[extension.Extension( name=dummy_strategy_name, entry_point="%s:%s" % ( dummy_strategy.DummyStrategy.__module__, dummy_strategy.DummyStrategy.__name__), plugin=dummy_strategy.DummyStrategy, obj=None, )], namespace="watcher_strategies", ) with mock.patch.object(extension, "ExtensionManager") as m_ext_manager: m_ext_manager.return_value = fake_extmanager_call loaded_strategy = self.strategy_loader.load( "dummy") self.assertEqual("dummy", loaded_strategy.name) self.assertEqual("Dummy strategy", loaded_strategy.display_name)
Example #7
Source File: test_loader.py From watcher with Apache License 2.0 | 6 votes |
def test_load_loadable_with_opts(self): fake_driver = drivermanager.DriverManager.make_test_instance( extension=stevedore_extension.Extension( name="fake", entry_point="%s:%s" % (FakeLoadableWithOpts.__module__, FakeLoadableWithOpts.__name__), plugin=FakeLoadableWithOpts, obj=None), namespace="TESTING") loader_manager = default.DefaultLoader(namespace='TESTING') with mock.patch.object(drivermanager, "DriverManager") as m_driver_manager: m_driver_manager.return_value = fake_driver loaded_driver = loader_manager.load(name='fake') self.assertIsInstance(loaded_driver, FakeLoadableWithOpts) self.assertEqual( "fake_with_opts", loaded_driver.config.get("test_opt")) self.assertEqual( "fake_with_opts", loaded_driver.config.test_opt)
Example #8
Source File: test_loader.py From watcher with Apache License 2.0 | 6 votes |
def test_load_loadable_no_opt(self): fake_driver = drivermanager.DriverManager.make_test_instance( extension=stevedore_extension.Extension( name="fake", entry_point="%s:%s" % (FakeLoadable.__module__, FakeLoadable.__name__), plugin=FakeLoadable, obj=None), namespace="TESTING") loader_manager = default.DefaultLoader(namespace='TESTING') with mock.patch.object(drivermanager, "DriverManager") as m_driver_manager: m_driver_manager.return_value = fake_driver loaded_driver = loader_manager.load(name='fake') self.assertIsInstance(loaded_driver, FakeLoadable)
Example #9
Source File: transformers.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds, verify_requirements=True): if not ep.dist: # `require` argument of ep.load() is deprecated in newer versions of setuptools if hasattr(ep, 'resolve'): plugin = ep.resolve() elif hasattr(ep, '_load'): plugin = ep._load() else: plugin = ep.load(require=False) else: plugin = ep.load() if invoke_on_load: obj = plugin(*invoke_args, **invoke_kwds) else: obj = None return Extension(ep.name, ep, plugin, obj)
Example #10
Source File: test_collector_loader.py From watcher with Apache License 2.0 | 6 votes |
def test_collector_loader(self): fake_driver = "fake" # Set up the fake Stevedore extensions fake_driver_call = drivermanager.DriverManager.make_test_instance( extension=stevedore_extension.Extension( name=fake_driver, entry_point="%s:%s" % ( faker_cluster_state.FakerModelCollector.__module__, faker_cluster_state.FakerModelCollector.__name__), plugin=faker_cluster_state.FakerModelCollector, obj=None, ), namespace="watcher_cluster_data_model_collectors", ) with mock.patch.object(drivermanager, "DriverManager") as m_driver_manager: m_driver_manager.return_value = fake_driver_call loaded_collector = self.collector_loader.load("fake") self.assertIsInstance( loaded_collector, faker_cluster_state.FakerModelCollector)
Example #11
Source File: fixtures.py From cloudkitty with Apache License 2.0 | 5 votes |
def setup_fake_modules(self): def fake_metric(start, end=None, project_id=None, q_filter=None): return None fake_module1 = tests.FakeCollectorModule() fake_module1.collector_name = 'fake1' fake_module1.get_compute = fake_metric fake_module2 = tests.FakeCollectorModule() fake_module2.collector_name = 'fake2' fake_module2.get_volume = fake_metric fake_module3 = tests.FakeCollectorModule() fake_module3.collector_name = 'fake3' fake_module3.get_compute = fake_metric fake_extensions = [ extension.Extension( 'fake1', 'cloudkitty.tests.FakeCollectorModule1', None, fake_module1), extension.Extension( 'fake2', 'cloudkitty.tests.FakeCollectorModule2', None, fake_module2), extension.Extension( 'fake3', 'cloudkitty.tests.FakeCollectorModule3', None, fake_module3)] return fake_extensions[0]
Example #12
Source File: test_test_manager.py From stevedore with Apache License 2.0 | 5 votes |
def test_hook_manager_should_return_named_extensions(self): hook1 = Extension('captain', None, None, None) hook2 = Extension('captain', None, None, None) em = HookManager.make_test_instance([hook1, hook2]) self.assertEqual([hook1, hook2], em['captain']) # DriverManager
Example #13
Source File: fixtures.py From cloudkitty with Apache License 2.0 | 5 votes |
def setup_fake_modules(self): class FakeConfigController(rating.RatingRestControllerBase): _custom_actions = { 'test': ['GET'] } @wsme_pecan.wsexpose(wtypes.text) def get_test(self): """Return the list of every mapping type available. """ return 'OK' fake_module1 = tests.FakeRatingModule() fake_module1.module_name = 'fake1' fake_module1.set_priority(3) fake_module2 = tests.FakeRatingModule() fake_module2.module_name = 'fake2' fake_module2.config_controller = FakeConfigController fake_module2.set_priority(1) fake_module3 = tests.FakeRatingModule() fake_module3.module_name = 'fake3' fake_module3.set_priority(2) fake_extensions = [ extension.Extension( 'fake1', 'cloudkitty.tests.FakeRatingModule1', None, fake_module1), extension.Extension( 'fake2', 'cloudkitty.tests.FakeRatingModule2', None, fake_module2), extension.Extension( 'fake3', 'cloudkitty.tests.FakeRatingModule3', None, fake_module3)] return fake_extensions
Example #14
Source File: fixtures.py From cloudkitty with Apache License 2.0 | 5 votes |
def setup_app(): messaging.setup() # FIXME(sheeprine): Extension fixtures are interacting with transformers # loading, since collectors are not needed here we shunt them no_collector = mock.patch( 'cloudkitty.collector.get_collector', return_value=None) with no_collector: return app.load_app()
Example #15
Source File: test_list_opts.py From watcher with Apache License 2.0 | 5 votes |
def test_list_opts_with_opts(self): expected_sections = self.base_sections + [ 'watcher_strategies.strategy_1'] # Set up the fake Stevedore extensions fake_extmanager_call = extension.ExtensionManager.make_test_instance( extensions=[extension.Extension( name=fake_strategies.FakeDummy1Strategy1.get_name(), entry_point="%s:%s" % ( fake_strategies.FakeDummy1Strategy1.__module__, fake_strategies.FakeDummy1Strategy1.__name__), plugin=fake_strategies.FakeDummy1Strategy1, obj=None, )], namespace="watcher_strategies", ) def m_list_available(namespace): if namespace == "watcher_strategies": return fake_extmanager_call else: return extension.ExtensionManager.make_test_instance( extensions=[], namespace=namespace) with mock.patch.object(extension, "ExtensionManager") as m_ext_manager: m_ext_manager.side_effect = m_list_available result = opts.list_opts() self.assertIsNotNone(result) self._assert_name_or_group(result, expected_sections) result_map = dict(result) strategy_opts = result_map['watcher_strategies.strategy_1'] self.assertEqual(['test_opt'], [opt.name for opt in strategy_opts])
Example #16
Source File: test_list_opts.py From watcher with Apache License 2.0 | 5 votes |
def test_show_plugins(self): # Set up the fake Stevedore extensions fake_extmanager_call = extension.ExtensionManager.make_test_instance( extensions=[extension.Extension( name=fake_strategies.FakeDummy1Strategy1.get_name(), entry_point="%s:%s" % ( fake_strategies.FakeDummy1Strategy1.__module__, fake_strategies.FakeDummy1Strategy1.__name__), plugin=fake_strategies.FakeDummy1Strategy1, obj=None, )], namespace="watcher_strategies", ) def m_list_available(namespace): if namespace == "watcher_strategies": return fake_extmanager_call else: return extension.ExtensionManager.make_test_instance( extensions=[], namespace=namespace) with mock.patch.object(extension, "ExtensionManager") as m_ext_manager: with mock.patch.object( plugins, "_show_plugins_ascii_table" ) as m_show: m_ext_manager.side_effect = m_list_available plugins.show_plugins() m_show.assert_called_once_with( [('watcher_strategies.strategy_1', 'strategy_1', 'watcher.tests.decision_engine.' 'fake_strategies.FakeDummy1Strategy1')])
Example #17
Source File: test_sphinxext.py From bazarr with GNU General Public License v3.0 | 5 votes |
def _make_ext(name, docstring): def inner(): pass inner.__doc__ = docstring m1 = mock.Mock(spec=pkg_resources.EntryPoint) m1.module_name = '%s_module' % name s = mock.Mock(return_value='ENTRY_POINT(%s)' % name) m1.__str__ = s return extension.Extension(name, m1, inner, None)
Example #18
Source File: test_callback.py From bazarr with GNU General Public License v3.0 | 5 votes |
def test_missing_entrypoints_callback(self, load_fn): errors = set() def callback(names): errors.update(names) load_fn.return_value = [ extension.Extension('foo', None, None, None) ] named.NamedExtensionManager('stevedore.test.extension', names=['foo', 'bar'], invoke_on_load=True, on_missing_entrypoints_callback=callback) self.assertEqual(errors, {'bar'})
Example #19
Source File: test_test_manager.py From bazarr with GNU General Public License v3.0 | 5 votes |
def test_hook_manager_should_return_named_extensions(self): hook1 = Extension('captain', None, None, None) hook2 = Extension('captain', None, None, None) em = HookManager.make_test_instance([hook1, hook2]) self.assertEqual([hook1, hook2], em['captain']) # DriverManager
Example #20
Source File: test_evaluator.py From aodh with Apache License 2.0 | 5 votes |
def setUp(self): super(TestAlarmEvaluationService, self).setUp() conf = service.prepare_service(argv=[], config_files=[]) self.CONF = self.useFixture(fixture_config.Config(conf)).conf self.CONF.set_override('workers', 1, 'evaluator') self.setup_messaging(self.CONF) self.threshold_eval = mock.MagicMock() self._fake_conn = mock.Mock() self._fake_conn.get_alarms.return_value = [] self._fake_pc = mock.Mock() self._fake_em = extension.ExtensionManager.make_test_instance( [ extension.Extension( 'gnocchi_aggregation_by_metrics_threshold', None, None, self.threshold_eval), ] ) self.useFixture(fixtures.MockPatch( 'stevedore.extension.ExtensionManager', return_value=self._fake_em )) self.useFixture(fixtures.MockPatch( 'aodh.coordination.PartitionCoordinator', return_value=self._fake_pc )) self.useFixture(fixtures.MockPatch( 'aodh.storage.get_connection_from_config', return_value=self._fake_conn ))
Example #21
Source File: test_command_hooks.py From cliff with Apache License 2.0 | 5 votes |
def setUp(self): super(TestShowOneHooks, self).setUp() self.app = make_app() self.cmd = TestShowCommand(self.app, None, cmd_name='test') self.hook = TestHook(self.cmd) self.mgr = extension.ExtensionManager.make_test_instance( [extension.Extension( 'parser-hook', None, None, self.hook)], ) # Replace the auto-loaded hooks with our explicitly created # manager. self.cmd._hooks = self.mgr
Example #22
Source File: test_driver_manager.py From networking-sfc with Apache License 2.0 | 5 votes |
def _test_method_called(self, method_name): driver1 = Extension('mock_driver1', Mock(), None, Mock(native_bulk_support=True)) driver2 = Extension('mock_driver2', Mock(), None, Mock(native_bulk_support=True)) manager = SfcDriverManager.make_test_instance([driver1, driver2]) mocked_context = Mock() getattr(manager, method_name)(mocked_context) getattr(driver1.obj, method_name).assert_called_once_with( mocked_context) getattr(driver2.obj, method_name).assert_called_once_with( mocked_context)
Example #23
Source File: test_driver_manager.py From networking-sfc with Apache License 2.0 | 5 votes |
def _test_method_exception(self, method_name, expected_exc=sfc_exc.SfcDriverError): driver = Extension('mock_driver', Mock(), None, Mock(native_bulk_support=True)) mock_method = Mock(side_effect=sfc_exc.SfcException) setattr(driver.obj, method_name, mock_method) manager = SfcDriverManager.make_test_instance([driver]) mocked_context = Mock() self.assertRaises(expected_exc, getattr(manager, method_name), mocked_context)
Example #24
Source File: test_driver_manager.py From networking-sfc with Apache License 2.0 | 5 votes |
def test_initialize_called(self): driver1 = Extension('mock_driver1', Mock(), None, Mock(native_bulk_support=True)) driver2 = Extension('mock_driver2', Mock(), None, Mock(native_bulk_support=True)) manager = FlowClassifierDriverManager.make_test_instance([driver1, driver2]) manager.initialize() driver1.obj.initialize.assert_called_once_with() driver2.obj.initialize.assert_called_once_with()
Example #25
Source File: test_driver_manager.py From networking-sfc with Apache License 2.0 | 5 votes |
def _test_method_called(self, method_name): driver1 = Extension('mock_driver1', Mock(), None, Mock(native_bulk_support=True)) driver2 = Extension('mock_driver2', Mock(), None, Mock(native_bulk_support=True)) manager = FlowClassifierDriverManager.make_test_instance([driver1, driver2]) mocked_context = Mock() getattr(manager, method_name)(mocked_context) getattr(driver1.obj, method_name).assert_called_once_with( mocked_context) getattr(driver2.obj, method_name).assert_called_once_with( mocked_context)
Example #26
Source File: test_os_vif_plug_noop.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def test_plug(self, mock_plug): plg = extension.Extension(name="noop", entry_point="os-vif", plugin=NoOpPlugin, obj=None) with mock.patch('stevedore.extension.ExtensionManager.names', return_value=['foobar']),\ mock.patch('stevedore.extension.ExtensionManager.__getitem__', return_value=plg): os_vif.initialize() info = mock.sentinel.info vif = mock.MagicMock() vif.plugin_name = 'noop' os_vif.plug(vif, info) mock_plug.assert_called_once_with(vif, info)
Example #27
Source File: test_os_vif_plug_noop.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def test_unplug(self, mock_unplug): plg = extension.Extension(name="demo", entry_point="os-vif", plugin=NoOpPlugin, obj=None) with mock.patch('stevedore.extension.ExtensionManager.names', return_value=['foobar']),\ mock.patch('stevedore.extension.ExtensionManager.__getitem__', return_value=plg): os_vif.initialize() info = mock.sentinel.info vif = mock.MagicMock() vif.plugin_name = 'noop' os_vif.unplug(vif, info) mock_unplug.assert_called_once_with(vif, info)
Example #28
Source File: test_command_hooks.py From cliff with Apache License 2.0 | 5 votes |
def setUp(self): super(TestHooks, self).setUp() self.app = make_app() self.cmd = TestCommand(self.app, None, cmd_name='test') self.hook = TestHook(self.cmd) self.mgr = extension.ExtensionManager.make_test_instance( [extension.Extension( 'parser-hook', None, None, self.hook)], ) # Replace the auto-loaded hooks with our explicitly created # manager. self.cmd._hooks = self.mgr
Example #29
Source File: test_command_hooks.py From cliff with Apache License 2.0 | 5 votes |
def setUp(self): super(TestChangeHooks, self).setUp() self.app = make_app() self.cmd = TestCommand(self.app, None, cmd_name='test') self.hook = TestChangeHook(self.cmd) self.mgr = extension.ExtensionManager.make_test_instance( [extension.Extension( 'parser-hook', None, None, self.hook)], ) # Replace the auto-loaded hooks with our explicitly created # manager. self.cmd._hooks = self.mgr
Example #30
Source File: test_orchestrator.py From cloudkitty with Apache License 2.0 | 5 votes |
def setup_fake_modules(self): fake_module1 = tests.FakeRatingModule() fake_module1.module_name = 'fake1' fake_module1.set_priority(3) fake_module2 = tests.FakeRatingModule() fake_module2.module_name = 'fake2' fake_module2.set_priority(1) fake_module3 = tests.FakeRatingModule() fake_module3.module_name = 'fake3' fake_module3.set_priority(2) fake_extensions = [ extension.Extension( 'fake1', 'cloudkitty.tests.FakeRatingModule1', None, fake_module1), extension.Extension( 'fake2', 'cloudkitty.tests.FakeRatingModule2', None, fake_module2), extension.Extension( 'fake3', 'cloudkitty.tests.FakeRatingModule3', None, fake_module3)] return fake_extensions