本文整理汇总了Python中pkg_resources.EntryPoint方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.EntryPoint方法的具体用法?Python pkg_resources.EntryPoint怎么用?Python pkg_resources.EntryPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.EntryPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_generate_script
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_generate_script(self):
group = 'console_scripts'
entry_point = pkg_resources.EntryPoint(
name='test-ep',
module_name='pbr.packaging',
attrs=('LocalInstallScripts',))
header = '#!/usr/bin/env fake-header\n'
template = ('%(group)s %(module_name)s %(import_target)s '
'%(invoke_target)s')
generated_script = packaging.generate_script(
group, entry_point, header, template)
expected_script = (
'#!/usr/bin/env fake-header\nconsole_scripts pbr.packaging '
'LocalInstallScripts LocalInstallScripts'
)
self.assertEqual(expected_script, generated_script)
示例2: test_generate_script_validates_expectations
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_generate_script_validates_expectations(self):
group = 'console_scripts'
entry_point = pkg_resources.EntryPoint(
name='test-ep',
module_name='pbr.packaging')
header = '#!/usr/bin/env fake-header\n'
template = ('%(group)s %(module_name)s %(import_target)s '
'%(invoke_target)s')
self.assertRaises(
ValueError, packaging.generate_script, group, entry_point, header,
template)
entry_point = pkg_resources.EntryPoint(
name='test-ep',
module_name='pbr.packaging',
attrs=('attr1', 'attr2', 'attr3'))
self.assertRaises(
ValueError, packaging.generate_script, group, entry_point, header,
template)
示例3: test_running_main_error_in_loading
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_running_main_error_in_loading(exopy_qtbot, monkeypatch):
"""Test starting the main app but encountering an error while loading
modifier.
"""
import exopy.__main__ as em
def false_iter(arg):
class FalseEntryPoint(EntryPoint):
def load(self, *args, **kwargs):
raise Exception("Can't load entry point")
return [FalseEntryPoint('dummy', 'dummy')]
monkeypatch.setattr(em, 'iter_entry_points', false_iter)
def check_dialog(qtbot, dial):
assert 'extension' in dial.text
with pytest.raises(SystemExit):
with handle_dialog(exopy_qtbot, 'reject', check_dialog):
main([])
示例4: test_import_error
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_import_error(self):
"""This raises an import error on load to test that it is handled correctly"""
with warnings.catch_warnings():
warnings.filterwarnings('error')
try:
mock_entry_importerror = mock.create_autospec(EntryPoint)
mock_entry_importerror.name = "IErr"
mock_entry_importerror.load = self.raiseimporterror
populate_entry_points([mock_entry_importerror])
except AstropyUserWarning as w:
if "ImportError" in w.args[0]: # any error for this case should have this in it.
pass
else:
raise w
else:
raise self.exception_not_thrown
示例5: test_bad_func
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_bad_func(self):
"""This returns a function which fails the type check"""
with warnings.catch_warnings():
warnings.filterwarnings('error')
try:
mock_entry_badfunc = mock.create_autospec(EntryPoint)
mock_entry_badfunc.name = "BadFunc"
mock_entry_badfunc.load = self.returnbadfunc
populate_entry_points([mock_entry_badfunc])
except AstropyUserWarning as w:
if "Class" in w.args[0]: # any error for this case should have this in it.
pass
else:
raise w
else:
raise self.exception_not_thrown
示例6: test_bad_class
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_bad_class(self):
"""This returns a class which doesn't inherient from fitter """
with warnings.catch_warnings():
warnings.filterwarnings('error')
try:
mock_entry_badclass = mock.create_autospec(EntryPoint)
mock_entry_badclass.name = "BadClass"
mock_entry_badclass.load = self.returnbadclass
populate_entry_points([mock_entry_badclass])
except AstropyUserWarning as w:
if 'modeling.Fitter' in w.args[0]: # any error for this case should have this in it.
pass
else:
raise w
else:
raise self.exception_not_thrown
示例7: get_class_from_ep
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def get_class_from_ep(self, entry_point):
return EntryPoint(**entry_point).resolve()
示例8: test_running_main_error_in_parser_modifying
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_running_main_error_in_parser_modifying(exopy_qtbot, monkeypatch):
"""Test starting the main app but encountering an issue while adding
arguments.
"""
import exopy.__main__ as em
def false_iter(arg):
class FalseEntryPoint(EntryPoint):
def load(self, *args, **kwargs):
def false_modifier(parser):
raise Exception('Failed to add stupid argument to parser')
return (false_modifier, 1)
return [FalseEntryPoint('dummy', 'dummy')]
monkeypatch.setattr(em, 'iter_entry_points', false_iter)
def check_dialog(qtbot, dial):
assert 'modifying' in dial.text
with pytest.raises(SystemExit):
with handle_dialog(exopy_qtbot, 'reject', check_dialog):
main([])
示例9: test__load_entry_points_entry_points
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test__load_entry_points_entry_points(iep_mock):
# setup
something_else_ep = EntryPoint('something_else', 'mlblocks.__version__')
primitives_ep = EntryPoint(
'primitives',
'tests.test_discovery',
attrs=['FAKE_PRIMITIVES_PATH'],
dist=Distribution()
)
another_primitives_ep = EntryPoint(
'primitives',
'tests.test_discovery',
attrs=['FAKE_PRIMITIVES_PATHS'],
dist=Distribution()
)
iep_mock.return_value = [
something_else_ep,
primitives_ep,
another_primitives_ep
]
# run
paths = discovery._load_entry_points('primitives')
# assert
expected = [
'this/is/a/fake',
'this/is/another/fake',
'this/is/yet/another/fake',
]
assert paths == expected
expected_calls = [
call('mlblocks'),
]
assert iep_mock.call_args_list == expected_calls
示例10: test_get_versions_with_plugins
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_get_versions_with_plugins(monkeypatch):
import nose
import pkg_resources
monkeypatch.setattr(nose, '__version__', '1.2.3')
dist = pkg_resources.Distribution(project_name='myPlugin',
version='4.5.6')
ep = pkg_resources.EntryPoint('name', 'module_name', dist=dist)
monkeypatch.setattr(pkg_resources,
'iter_entry_points',
lambda ept: (x for x in (ep,) if ept == nose.plugins
.manager.EntryPointPluginManager
.entry_points[0][0]))
runner = NoseRunner(None)
assert runner.get_versions() == ['nose 1.2.3', ' myPlugin 4.5.6']
示例11: __init__
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def __init__(self, entries: Iterable[EntryPoint]) -> None: # pragma: no cover
self._list: Dict[_ImagecrawlerName, _ImagecrawlerClass] = self._builtins().copy()
_log('debug', 'Builtin imagecrawlers loaded: %r', self._list)
for entry in entries:
try:
self._append(entry)
except Exception as ex: # pylint: disable=broad-except
_log('debug', 'Entry point skipped: %r from %r\n\t%s', entry.name, entry.dist, ex, exc_info=ex)
else:
_log('debug', 'Entry point added: %r from %r', entry.name, entry.dist)
示例12: _append
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def _append(self, entry: EntryPoint) -> None:
self._test_duplicate_name(entry.name)
loaded = self._load(entry)
self._test(loaded)
self._test_duplicate_class(loaded)
# if everything went well .. add
self._list[entry.name] = loaded
示例13: _load
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def _load(entry: EntryPoint) -> Any:
try:
return entry.load()
except Exception as ex:
raise ImportError(f'Error on loading entry {entry}') from ex
示例14: test_raise
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def test_raise(self) -> None:
# arrange
entry = EntryPoint('Test', '__.does.not.exist', attrs=('UnknownClass',),
dist=_TEST_PLUGIN_DIST)
# act & assert
with self.assertRaises(ImportError):
KnownImageCrawlers._load(entry)
示例15: _entry_points
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import EntryPoint [as 别名]
def _entry_points():
# type: () -> DefaultDict[str, Dict[str, pkg_resources.EntryPoint]]
"""Discover all entry points for required groups if they have not already been found.
:returns: Mapping of group to name to entry points
:rtype: dict
"""
if not _ENTRY_POINTS:
_discover_entry_points()
return _ENTRY_POINTS