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