本文整理汇总了Python中types.ModuleType.complete方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.complete方法的具体用法?Python ModuleType.complete怎么用?Python ModuleType.complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.complete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iter_builders_verify_export_target
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [as 别名]
def test_iter_builders_verify_export_target(self):
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',
'invalid.js = calmjs_testing_dummy:complete',
])),
), 'app', '1.0', working_dir=working_dir)
mock_ws = WorkingSet([working_dir])
class FakeArtifactRegistry(ArtifactRegistry):
def verify_export_target(self, export_target):
return 'invalid.js' not in export_target
registry = FakeArtifactRegistry(
'calmjs.artifacts', _working_set=mock_ws)
# the invalid.js should be filtered out
with pretty_logging(stream=mocks.StringIO()) as stream:
self.assertEqual(1, len(list(registry.iter_builders_for('app'))))
self.assertIn("invalid.js' has been rejected", stream.getvalue())
示例2: test_iter_builders_side_effect_build_issue
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [as 别名]
def test_iter_builders_side_effect_build_issue(self):
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')
# clog the build directory so build cannot happen
with open(join(root), 'w'):
pass
ep, toolchain, spec = next(registry.iter_builders_for('app'))
check = []
spec.advise('after_prepare', check.append, True)
with pretty_logging(stream=mocks.StringIO()) as stream:
with self.assertRaises(ToolchainAbort):
toolchain(spec)
self.assertIn(
"an advice in group 'before_prepare' triggered an abort",
stream.getvalue())
# should have stopped at before_prepare
self.assertFalse(check)
示例3: test_iter_builders_side_effect
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [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))
示例4: test_update_artifact_metadata
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [as 别名]
def test_update_artifact_metadata(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, (
('requires.txt', '\n'.join([
'calmjs',
])),
('entry_points.txt', '\n'.join([
'[calmjs.artifacts]',
'artifact.js = calmjs_testing_dummy:complete',
])),
), 'app', '1.0', working_dir=working_dir)
# mock a version of calmjs within that environment too
utils.make_dummy_dist(self, (
('entry_points.txt', ''),
), 'calmjs', '1.0', working_dir=working_dir)
mock_ws = WorkingSet([working_dir])
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
registry.update_artifact_metadata('app', {})
self.assertTrue(exists(registry.metadata.get('app')))
with pretty_logging(stream=mocks.StringIO()) as s:
registry.update_artifact_metadata('calmjs', {})
self.assertIn(
"package 'calmjs' has not declare any artifacts", s.getvalue())
示例5: test_iter_builders_verify_export_target_legacy
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [as 别名]
def test_iter_builders_verify_export_target_legacy(self):
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])
root = join(working_dir, 'app-1.0.egg-info', 'calmjs_artifacts')
targets = []
def check_target(export_target):
# manually create the root here, to allow the completion
# of the build process by doing what an existing
# implementation that reuse existing code might have done.
targets.append(export_target)
prepare_export_location(export_target)
# ensure that the build directory exists, because the default
class FakeArtifactRegistry(ArtifactRegistry):
def verify_export_target(self, export_target):
return check_target
registry = FakeArtifactRegistry(
'calmjs.artifacts', _working_set=mock_ws)
# the invalid.js should be filtered out
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
self.assertEqual(1, len(list(registry.iter_builders_for('app'))))
self.assertIn(
"FakeArtifactRegistry.verify_export_target returned a callable",
str(w[-1].message))
# ensure no early execution of check_target
self.assertFalse(targets)
self.assertFalse(exists(root))
with warnings.catch_warnings(record=True):
with pretty_logging(stream=mocks.StringIO()):
registry.process_package('app')
# ensure no early execution of check_target
self.assertTrue(targets)
self.assertTrue(exists(root))
示例6: test_build_artifacts_success
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import complete [as 别名]
def test_build_artifacts_success(self):
# inject dummy module and add cleanup
mod = ModuleType('calmjs_testing_dummy')
mod.extra = generic_builder
mod.complete = generic_builder
mod.partial = 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, (
('requires.txt', '\n'.join([
'calmjs',
])),
('entry_points.txt', '\n'.join([
'[calmjs.artifacts]',
'artifact.js = calmjs_testing_dummy:complete',
'partial.js = calmjs_testing_dummy:partial',
])),
), 'app', '1.0', working_dir=working_dir)
# mock a version of calmjs within that environment too
utils.make_dummy_dist(self, (
('entry_points.txt', ''),
), 'calmjs', '1.0', working_dir=working_dir)
def version(bin_path, version_flag='-v', kw={}):
return '0.0.0'
mock_ws = WorkingSet([working_dir])
utils.stub_item_attr_value(self, dist, 'default_working_set', mock_ws)
utils.stub_item_attr_value(
self, artifact, 'get_bin_version_str', version)
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# quick check of the artifact metadata beforehand
self.assertEqual({}, registry.get_artifact_metadata('app'))
registry.process_package('app')
complete = list(registry.resolve_artifacts_by_builder_compat(
['app'], 'complete'))
partial = list(registry.resolve_artifacts_by_builder_compat(
['app'], 'partial'))
self.assertEqual(len(complete), 1)
self.assertEqual(len(partial), 1)
self.assertEqual(basename(complete[0]), 'artifact.js')
self.assertEqual(basename(partial[0]), 'partial.js')
with open(complete[0]) as fd:
self.assertEqual(fd.read(), 'app')
with open(partial[0]) as fd:
self.assertEqual(fd.read(), 'app')
self.assertEqual({
'calmjs_artifacts': {
'artifact.js': {
'builder': 'calmjs_testing_dummy:complete',
'toolchain_bases': [
{'calmjs.testing.artifact:ArtifactToolchain': {
'project_name': 'calmjs',
'version': '1.0',
}},
{'calmjs.toolchain:NullToolchain': {
'project_name': 'calmjs',
'version': '1.0',
}},
{'calmjs.toolchain:Toolchain': {
'project_name': 'calmjs',
'version': '1.0',
}}
],
'toolchain_bin': ['artifact', '0.0.0'],
},
'partial.js': {
'builder': 'calmjs_testing_dummy:partial',
'toolchain_bases': [
{'calmjs.testing.artifact:ArtifactToolchain': {
'project_name': 'calmjs',
'version': '1.0'}},
{'calmjs.toolchain:NullToolchain': {
'project_name': 'calmjs',
'version': '1.0',
}},
{'calmjs.toolchain:Toolchain': {
'project_name': 'calmjs',
'version': '1.0',
}}
],
'toolchain_bin': ['artifact', '0.0.0'],
}
},
'versions': [
'app 1.0',
'calmjs 1.0',
]
}, registry.get_artifact_metadata('app'))
#.........这里部分代码省略.........