当前位置: 首页>>代码示例>>Python>>正文


Python extension.Extension方法代码示例

本文整理汇总了Python中stevedore.extension.Extension方法的典型用法代码示例。如果您正苦于以下问题:Python extension.Extension方法的具体用法?Python extension.Extension怎么用?Python extension.Extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stevedore.extension的用法示例。


在下文中一共展示了extension.Extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _load_one_plugin

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:18,代码来源:transformers.py

示例2: test_multiple_drivers

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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') 
开发者ID:openstack,项目名称:stevedore,代码行数:27,代码来源:test_driver.py

示例3: test_goal_loader

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:watcher,代码行数:23,代码来源:test_goal_loader.py

示例4: test_strategy_loader

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:watcher,代码行数:24,代码来源:test_default_strategy_loader.py

示例5: test_collector_loader

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:watcher,代码行数:24,代码来源:test_collector_loader.py

示例6: test_load_loadable_no_opt

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:watcher,代码行数:19,代码来源:test_loader.py

示例7: test_load_loadable_with_opts

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:watcher,代码行数:25,代码来源:test_loader.py

示例8: test_plug

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:os-vif,代码行数:18,代码来源:test_os_vif.py

示例9: test_unplug

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:os-vif,代码行数:18,代码来源:test_os_vif.py

示例10: test_initialize_called

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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 = SfcDriverManager.make_test_instance([driver1, driver2])
        manager.initialize()
        driver1.obj.initialize.assert_called_once_with()
        driver2.obj.initialize.assert_called_once_with() 
开发者ID:openstack,项目名称:networking-sfc,代码行数:11,代码来源:test_driver_manager.py

示例11: _test_method_called

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:14,代码来源:test_driver_manager.py

示例12: _test_method_exception

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:13,代码来源:test_driver_manager.py

示例13: test_initialize_called

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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() 
开发者ID:openstack,项目名称:networking-sfc,代码行数:12,代码来源:test_driver_manager.py

示例14: _test_method_called

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:15,代码来源:test_driver_manager.py

示例15: test_plug

# 需要导入模块: from stevedore import extension [as 别名]
# 或者: from stevedore.extension import Extension [as 别名]
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) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:17,代码来源:test_os_vif_plug_noop.py


注:本文中的stevedore.extension.Extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。