本文整理汇总了Python中pants.build_graph.build_configuration.BuildConfiguration.registered_aliases方法的典型用法代码示例。如果您正苦于以下问题:Python BuildConfiguration.registered_aliases方法的具体用法?Python BuildConfiguration.registered_aliases怎么用?Python BuildConfiguration.registered_aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.build_graph.build_configuration.BuildConfiguration
的用法示例。
在下文中一共展示了BuildConfiguration.registered_aliases方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoaderTest
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import registered_aliases [as 别名]
class LoaderTest(unittest.TestCase):
def setUp(self):
self.build_configuration = BuildConfiguration()
self.working_set = WorkingSet()
for entry in working_set.entries:
self.working_set.add_entry(entry)
def tearDown(self):
Goal.clear()
@contextmanager
def create_register(self, build_file_aliases=None, register_goals=None, global_subsystems=None,
module_name='register'):
package_name = b'__test_package_{0}'.format(uuid.uuid4().hex)
self.assertFalse(package_name in sys.modules)
package_module = types.ModuleType(package_name)
sys.modules[package_name] = package_module
try:
register_module_fqn = b'{0}.{1}'.format(package_name, module_name)
register_module = types.ModuleType(register_module_fqn)
setattr(package_module, module_name, register_module)
sys.modules[register_module_fqn] = register_module
def register_entrypoint(function_name, function):
if function:
setattr(register_module, function_name, function)
register_entrypoint('build_file_aliases', build_file_aliases)
register_entrypoint('global_subsystems', global_subsystems)
register_entrypoint('register_goals', register_goals)
yield package_name
finally:
del sys.modules[package_name]
def assert_empty_aliases(self):
registered_aliases = self.build_configuration.registered_aliases()
self.assertEqual(0, len(registered_aliases.target_types))
self.assertEqual(0, len(registered_aliases.target_macro_factories))
self.assertEqual(0, len(registered_aliases.objects))
self.assertEqual(0, len(registered_aliases.context_aware_object_factories))
self.assertEqual(self.build_configuration.subsystems(), set())
def test_load_valid_empty(self):
with self.create_register() as backend_package:
load_backend(self.build_configuration, backend_package)
self.assert_empty_aliases()
def test_load_valid_partial_aliases(self):
aliases = BuildFileAliases(targets={'bob': DummyTarget},
objects={'obj1': DummyObject1,
'obj2': DummyObject2})
with self.create_register(build_file_aliases=lambda: aliases) as backend_package:
load_backend(self.build_configuration, backend_package)
registered_aliases = self.build_configuration.registered_aliases()
self.assertEqual(DummyTarget, registered_aliases.target_types['bob'])
self.assertEqual(DummyObject1, registered_aliases.objects['obj1'])
self.assertEqual(DummyObject2, registered_aliases.objects['obj2'])
self.assertEqual(self.build_configuration.subsystems(), {DummySubsystem1, DummySubsystem2})
def test_load_valid_partial_goals(self):
def register_goals():
Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
with self.create_register(register_goals=register_goals) as backend_package:
Goal.clear()
self.assertEqual(0, len(Goal.all()))
load_backend(self.build_configuration, backend_package)
self.assert_empty_aliases()
self.assertEqual(1, len(Goal.all()))
task_names = Goal.by_name('jack').ordered_task_names()
self.assertEqual(1, len(task_names))
task_name = task_names[0]
self.assertEqual('jill', task_name)
def test_load_invalid_entrypoint(self):
def build_file_aliases(bad_arg):
return BuildFileAliases()
with self.create_register(build_file_aliases=build_file_aliases) as backend_package:
with self.assertRaises(BuildConfigurationError):
load_backend(self.build_configuration, backend_package)
def test_load_invalid_module(self):
with self.create_register(module_name='register2') as backend_package:
with self.assertRaises(BuildConfigurationError):
load_backend(self.build_configuration, backend_package)
def test_load_missing_plugin(self):
with self.assertRaises(PluginNotFound):
self.load_plugins(['Foobar'])
def get_mock_plugin(self, name, version, reg=None, alias=None, after=None):
"""Make a fake Distribution (optionally with entry points)
#.........这里部分代码省略.........
示例2: BuildConfigurationTest
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import registered_aliases [as 别名]
class BuildConfigurationTest(unittest.TestCase):
def setUp(self):
self.build_configuration = BuildConfiguration()
def _register_aliases(self, **kwargs):
self.build_configuration.register_aliases(BuildFileAliases(**kwargs))
def test_register_bad(self):
with self.assertRaises(TypeError):
self.build_configuration.register_aliases(42)
def test_register_target_alias(self):
class Fred(Target):
pass
self._register_aliases(targets={'fred': Fred})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_macro_factories)
self.assertEqual({}, aliases.objects)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(fred=Fred), aliases.target_types)
with self._create_mock_build_file('fred') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
target_call_proxy = parse_state.parse_globals['fred']
target_call_proxy(name='jake')
self.assertEqual(1, len(parse_state.objects))
target_proxy = parse_state.objects[0]
self.assertEqual('jake', target_proxy.addressed_name)
self.assertEqual(Fred, target_proxy.addressed_type)
def test_register_target_macro_facory(self):
class Fred(Target):
pass
class FredMacro(TargetMacro):
def __init__(self, parse_context):
self._parse_context = parse_context
def expand(self, *args, **kwargs):
return self._parse_context.create_object(Fred, name='frog', dependencies=[kwargs['name']])
class FredFactory(TargetMacro.Factory):
@property
def target_types(self):
return {Fred}
def macro(self, parse_context):
return FredMacro(parse_context)
factory = FredFactory()
self._register_aliases(targets={'fred': factory})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_types)
self.assertEqual({}, aliases.objects)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(fred=factory), aliases.target_macro_factories)
with self._create_mock_build_file('fred') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
target_call_proxy = parse_state.parse_globals['fred']
target_call_proxy(name='jake')
self.assertEqual(1, len(parse_state.objects))
target_proxy = parse_state.objects[0]
self.assertEqual('frog', target_proxy.addressed_name)
self.assertEqual(Fred, target_proxy.addressed_type)
self.assertEqual(['jake'], target_proxy.dependency_specs)
def test_register_exposed_object(self):
self._register_aliases(objects={'jane': 42})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_types)
self.assertEqual({}, aliases.target_macro_factories)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(jane=42), aliases.objects)
with self._create_mock_build_file('jane') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
self.assertEqual(42, parse_state.parse_globals['jane'])
def test_register_exposed_context_aware_function(self):
self.do_test_exposed_context_aware_function(lambda context: lambda: context.rel_path)
self.do_test_exposed_context_aware_function(lambda context=None: lambda: context.rel_path)
def george_method(self, parse_context):
#.........这里部分代码省略.........