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


Python pkg_resources.EntryPoint方法代码示例

本文整理汇总了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) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:20,代码来源:test_packaging.py

示例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) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:test_packaging.py

示例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([]) 
开发者ID:Exopy,项目名称:exopy,代码行数:25,代码来源:test___main__.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_fitters.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_fitters.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_fitters.py

示例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() 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:4,代码来源:__init__.py

示例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([]) 
开发者ID:Exopy,项目名称:exopy,代码行数:29,代码来源:test___main__.py

示例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 
开发者ID:HDI-Project,项目名称:MLBlocks,代码行数:38,代码来源:test_discovery.py

示例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'] 
开发者ID:spyder-ide,项目名称:spyder-unittest,代码行数:16,代码来源:test_noserunner.py

示例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) 
开发者ID:k4cg,项目名称:nichtparasoup,代码行数:12,代码来源:__init__.py

示例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 
开发者ID:k4cg,项目名称:nichtparasoup,代码行数:9,代码来源:__init__.py

示例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 
开发者ID:k4cg,项目名称:nichtparasoup,代码行数:7,代码来源:__init__.py

示例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) 
开发者ID:k4cg,项目名称:nichtparasoup,代码行数:9,代码来源:test_knownimagecrawlers.py

示例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 
开发者ID:aws,项目名称:aws-encryption-sdk-cli,代码行数:12,代码来源:master_key_parsing.py


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