本文整理汇总了Python中pkg_resources.WorkingSet方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.WorkingSet方法的具体用法?Python pkg_resources.WorkingSet怎么用?Python pkg_resources.WorkingSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.WorkingSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_denormalized_package_names
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_denormalized_package_names(self):
working_dir = utils.mkdtemp(self)
utils.make_dummy_dist(self, (
('entry_points.txt', '\n'.join([
'[calmjs.artifacts]',
'full.js = calmjs_testbuild:full',
])),
), 'de_normal_name', '1.0', working_dir=working_dir)
mock_ws = WorkingSet([working_dir])
# stub the default working set in calmjs.dist for the resolver
# to work.
utils.stub_item_attr_value(self, dist, 'default_working_set', mock_ws)
# still specify the working set.
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
self.assertEqual(
1, len(list(registry.iter_records_for('de_normal_name'))))
# also test internal consistency
self.assertIn('de_normal_name', registry.compat_builders['full'])
self.assertIn('de_normal_name', registry.packages)
default = registry.get_artifact_filename('de_normal_name', 'full.js')
normal = registry.get_artifact_filename(
safe_name('de_normal_name'), 'full.js')
self.assertEqual(default, normal)
示例2: test_iter_builders_side_effect
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_iter_builders_side_effect(self):
# inject dummy module and add cleanup
mod = ModuleType('calmjs_testing_dummy')
mod.complete = generic_builder
self.addCleanup(sys.modules.pop, 'calmjs_testing_dummy')
sys.modules['calmjs_testing_dummy'] = mod
working_dir = utils.mkdtemp(self)
utils.make_dummy_dist(self, (
('entry_points.txt', '\n'.join([
'[calmjs.artifacts]',
'artifact.js = calmjs_testing_dummy:complete',
])),
), 'app', '1.0', working_dir=working_dir)
mock_ws = WorkingSet([working_dir])
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
registry.update_artifact_metadata('app', {})
root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
self.assertFalse(exists(root))
ep, toolchain, spec = next(registry.iter_builders_for('app'))
self.assertFalse(exists(root))
# directory only created after the toolchain is executed
toolchain(spec)
self.assertTrue(exists(root))
示例3: test_runtime_main_with_broken_runtime
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_runtime_main_with_broken_runtime(self):
stub_stdouts(self)
working_set = mocks.WorkingSet({'calmjs.runtime': [
'broken = calmjs.tests.test_runtime:broken',
]})
with self.assertRaises(SystemExit):
runtime.main(
['-vvd', '-h'],
runtime_cls=lambda: runtime.Runtime(working_set=working_set)
)
out = sys.stdout.getvalue()
err = sys.stderr.getvalue()
self.assertIn('broken', err)
self.assertIn('Traceback', err)
self.assertIn('a fake import error', err)
self.assertNotIn('broken', out)
示例4: test_spec_debugged_via_cmdline
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_spec_debugged_via_cmdline(self):
stub_stdouts(self)
stub_item_attr_value(
self, mocks, 'dummy',
runtime.ToolchainRuntime(toolchain.NullToolchain()),
)
working_set = mocks.WorkingSet({
'calmjs.runtime': [
'tool = calmjs.testing.mocks:dummy',
],
})
rt = runtime.Runtime(working_set=working_set, prog='calmjs')
with pretty_logging(logger='calmjs', stream=mocks.StringIO()) as s:
result = rt(['tool', '--export-target', 'dummy', '-d'])
self.assertEqual(result['debug'], 1)
# also test for the export_target resolution
self.assertIn(
"'export_target' resolved to '%s'" % join(self.cwd, 'dummy'),
s.getvalue())
示例5: test_runtime_group_not_runtime_reported
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_runtime_group_not_runtime_reported(self):
stub_stdouts(self)
make_dummy_dist(self, ((
'entry_points.txt',
'[calmjs.runtime]\n'
'bs = calmjs.testing.module3.runtime:fake_bootstrap\n'
),), 'example.package', '1.0')
working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
with self.assertRaises(SystemExit):
runtime.main(
['-h'],
runtime_cls=lambda: runtime.Runtime(working_set=working_set)
)
self.assertIn(
"'calmjs.runtime' entry point "
"'bs = calmjs.testing.module3.runtime:fake_bootstrap' from "
"'example.package 1.0' invalid for instance of "
"'calmjs.runtime.Runtime': target not an instance of "
"'calmjs.runtime.BaseRuntime' or its subclass; not registering "
"invalid entry point", sys.stderr.getvalue()
)
示例6: test_subparser_level_2_missing_argument
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_subparser_level_2_missing_argument(self):
stub_stdouts(self)
working_set = mocks.WorkingSet({
'calmjs.runtime': [
'artifact = calmjs.runtime:artifact',
],
'calmjs.runtime.artifact': [
'build = calmjs.runtime:artifact_build',
],
})
rt = runtime.Runtime(working_set=working_set, prog='calmjs')
# An underspecified command should also return False.
with self.assertRaises(SystemExit):
rt(['artifact', 'build'])
# ensure the help for the command itself is printed
self.assertIn('calmjs artifact build: error', sys.stderr.getvalue())
示例7: test_subparser_level_2_unrecognized_argument_final
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_subparser_level_2_unrecognized_argument_final(self):
stub_stdouts(self)
working_set = mocks.WorkingSet({
'calmjs.runtime': [
'artifact = calmjs.runtime:artifact',
],
'calmjs.runtime.artifact': [
'build = calmjs.runtime:artifact_build',
],
})
rt = runtime.Runtime(working_set=working_set, prog='calmjs')
# An underspecified command should also return False.
with self.assertRaises(SystemExit):
rt(['artifact', 'build', 'package', '--no-such-argument'])
# ensure the help for the command itself is printed
self.assertIn('calmjs artifact build: error', sys.stderr.getvalue())
示例8: test_subparsers_unrecognized_argument_interspersed
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_subparsers_unrecognized_argument_interspersed(self):
working_set = mocks.WorkingSet({
'calmjs.runtime': [
'broken = calmjs.tests.test_runtime:default_cmd',
],
})
rt = runtime.Runtime(working_set=working_set, prog='calmjs')
# An underspecified command should also return False.
with self.assertRaises(SystemExit):
rt(['--1', 'broken', '--2', 'dummy', '--3'])
# ensure the help for the command itself is printed
err = sys.stderr.getvalue()
self.assertIn(
'calmjs: error: unrecognized arguments: --1', err)
self.assertIn(
'calmjs broken: error: unrecognized arguments: --2', err)
self.assertIn(
'calmjs broken dummy: error: unrecognized arguments: --3', err)
示例9: test_simple_record
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_simple_record(self):
working_set = mocks.WorkingSet({__name__: [
'dummy/whatever/module.js = module',
'dummy/whatever/module-slim.js = module',
]}, dist=Distribution(project_name='calmjs.testing'))
registry = base.BaseExternalModuleRegistry(
__name__, _working_set=working_set)
self.assertEqual(len(registry.raw_entry_points), 2)
self.assertEqual(registry.get_record('module'), {
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
})
self.assertEqual(list(registry.iter_records()), [('module', {
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
})])
self.assertEqual(registry.get_records_for_package('calmjs.testing'), [
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
])
示例10: test_wrong_registry_type
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_wrong_registry_type(self):
advice = AdviceRegistry('adv', _working_set=WorkingSet({}))
registries = {'adv': advice}
stub_item_attr_value(
self, calmjs_toolchain, 'get_registry', registries.get)
spec = {'calmjs_loaderplugin_registry_name': 'adv'}
with pretty_logging(stream=StringIO()) as s:
registry = spec_update_loaderplugin_registry(spec)
self.assertIn(
"object referenced in spec is not a valid", s.getvalue())
self.assertIsNot(registry, advice)
self.assertTrue(isinstance(registry, BaseLoaderPluginRegistry))
spec = {}
with pretty_logging(stream=StringIO()) as s:
registry = spec_update_loaderplugin_registry(spec, default='adv')
self.assertIn(
"provided default is not a valid loaderplugin registry",
s.getvalue())
self.assertIsNot(registry, advice)
self.assertTrue(isinstance(registry, BaseLoaderPluginRegistry))
示例11: test_resolve_and_order
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_resolve_and_order(self):
fake = LoaderPluginRegistry('fake_registry', _working_set=WorkingSet({
'fake_registry': [
'foo = calmjs.tests.test_toolchain:MockLPHandler']}))
registries = {'fake_registry': fake}
stub_item_attr_value(
self, calmjs_toolchain, 'get_registry', registries.get)
spec = {'calmjs_loaderplugin_registry_name': 'fake_registry'}
with pretty_logging(stream=StringIO()) as s:
registry = spec_update_loaderplugin_registry(spec)
self.assertIn(
"using loaderplugin registry 'fake_registry'", s.getvalue())
self.assertIs(registry, fake)
spec = {
'calmjs_loaderplugin_registry_name': 'fake_registry',
'calmjs_loaderplugin_registry': BaseLoaderPluginRegistry('raw'),
}
示例12: test_standard_toolchain_process
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_standard_toolchain_process(self):
make_dummy_dist(self, ((
'entry_points.txt',
'[calmjs.toolchain.advice]\n'
'calmjs.toolchain:Toolchain = calmjs.tests.test_toolchain:dummy\n'
),), 'example.package', '1.0')
working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
reg = AdviceRegistry(CALMJS_TOOLCHAIN_ADVICE, _working_set=working_set)
toolchain = Toolchain()
spec = Spec()
with pretty_logging(stream=StringIO()) as s:
reg.process_toolchain_spec_package(
toolchain, spec, 'example.package')
self.assertEqual(spec['dummy'], ['dummy'])
self.assertIn(
"found advice setup steps registered for package/requirement "
"'example.package'; checking for compatibility with toolchain "
"'calmjs.toolchain:Toolchain'",
s.getvalue(),
)
示例13: test_get_record_key_normalised
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_get_record_key_normalised(self):
make_dummy_dist(self, ((
'entry_points.txt',
'[calmjs.toolchain.advice.apply]\n'
'example = example.advice[extra]\n'
),), 'example_namespace_package', '1.0')
working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
reg = AdviceApplyRegistry(
CALMJS_TOOLCHAIN_ADVICE + CALMJS_TOOLCHAIN_ADVICE_APPLY_SUFFIX,
_working_set=working_set
)
# key will be normalized
record = reg.get_record('example-namespace-package')
self.assertEqual(1, len(record))
self.assertEqual(
pkg_resources.Requirement.parse('example.advice[extra]'),
record[0],
)
示例14: tests_flatten_egginfo_json_missing_deps
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def tests_flatten_egginfo_json_missing_deps(self):
"""
Missing dependencies should not cause a hard failure.
"""
make_dummy_dist(self, (
('requires.txt', '\n'.join([
'uilib>=1.0',
])),
), 'app', '2.0')
working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
# Python dependency acquisition failures should fail hard.
with self.assertRaises(pkg_resources.DistributionNotFound):
calmjs_dist.flatten_egginfo_json(['app'], working_set=working_set)
示例15: test_conflict_registration
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import WorkingSet [as 别名]
def test_conflict_registration(self):
# create an empty working set for a clean-slate test.
cwd = utils.mkdtemp(self)
mock_ws = WorkingSet([])
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# using named case for case sensitivity test.
st = join(cwd, 'calmjs_artifacts', 'Simple.js')
dist_ = Distribution(cwd, project_name='pkg', version='1.0')
dist_.egg_info = cwd # just lazy
s1 = EntryPoint.parse('Simple.js = dummy_builder:builder1')
s1.dist = dist_
s2 = EntryPoint.parse('Simple.js = dummy_builder:builder2')
s2.dist = dist_
with pretty_logging(stream=mocks.StringIO()) as stream:
registry.register_entry_point(s1)
# normal registry usage shouldn't be able to do this.
registry.register_entry_point(s2)
log = stream.getvalue()
self.assertIn(
"entry point 'Simple.js = dummy_builder:builder2' from package "
"'pkg 1.0' resolves to the path '%s' which was already "
"registered to entry point 'Simple.js = dummy_builder:builder1'; "
"conflicting entry point registration will be ignored." % st,
log
)