當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。