python extension_Python extension.Extension方法代碼示例

钦高峯
2023-12-01

本文整理匯總了Python中stevedore.extension.Extension方法的典型用法代碼示例。如果您正苦於以下問題:Python extension.Extension方法的具體用法?Python extension.Extension怎麽用?Python extension.Extension使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊stevedore.extension的用法示例。

在下文中一共展示了extension.Extension方法的25個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: _load_one_plugin

​點讚 6

# 需要導入模塊: 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,

示例2: test_multiple_drivers

​點讚 6

# 需要導入模塊: 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,

示例3: test_goal_loader

​點讚 6

# 需要導入模塊: 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,

示例4: test_strategy_loader

​點讚 6

# 需要導入模塊: 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,

示例5: test_collector_loader

​點讚 6

# 需要導入模塊: 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,

示例6: test_load_loadable_no_opt

​點讚 6

# 需要導入模塊: 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,

示例7: test_load_loadable_with_opts

​點讚 6

# 需要導入模塊: 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,

示例8: test_plug

​點讚 6

# 需要導入模塊: 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,

示例9: test_unplug

​點讚 6

# 需要導入模塊: 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,

示例10: test_initialize_called

​點讚 5

# 需要導入模塊: 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,

示例11: _test_method_called

​點讚 5

# 需要導入模塊: 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,

示例12: _test_method_exception

​點讚 5

# 需要導入模塊: 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,

示例13: test_initialize_called

​點讚 5

# 需要導入模塊: 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,

示例14: _test_method_called

​點讚 5

# 需要導入模塊: 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,

示例15: test_plug

​點讚 5

# 需要導入模塊: 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,

示例16: test_unplug

​點讚 5

# 需要導入模塊: 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=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)

開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:17,

示例17: setUp

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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

開發者ID:openstack,項目名稱:cliff,代碼行數:17,

示例18: add

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

def add(self, name, cmd):

ext = extension.Extension(name, None, cmd.__class__, cmd)

self.mgrs[0].extensions.append(ext)

開發者ID:eonpatapon,項目名稱:contrail-api-cli,代碼行數:5,

示例19: _make_test_manager

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

def _make_test_manager(self, plugin):

return extension.ExtensionManager.make_test_instance(

[extension.Extension('test_plugin', None, test_plugin, None)])

開發者ID:PyCQA,項目名稱:bandit,代碼行數:5,

示例20: __init__

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

def __init__(self):

self.extensions = []

self.extensions.append(

extension.Extension(name=FAKE_BACKEND,

plugin=FakeConnection,

entry_point=None,

obj=None))

開發者ID:openstack,項目名稱:manila,代碼行數:9,

示例21: _make_ext

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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)

開發者ID:openstack,項目名稱:stevedore,代碼行數:12,

示例22: test_missing_entrypoints_callback

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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'})

開發者ID:openstack,項目名稱:stevedore,代碼行數:16,

示例23: test_hook_manager_should_return_named_extensions

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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

開發者ID:openstack,項目名稱:stevedore,代碼行數:9,

示例24: setup_fake_modules

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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

開發者ID:openstack,項目名稱:cloudkitty,代碼行數:29,

示例25: setup_fake_modules

​點讚 5

# 需要導入模塊: from stevedore import extension [as 別名]

# 或者: from stevedore.extension import Extension [as 別名]

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]

開發者ID:openstack,項目名稱:cloudkitty,代碼行數:35,

注:本文中的stevedore.extension.Extension方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

 类似资料: