本文整理汇总了Python中pants.base.build_configuration.BuildConfiguration._register_target_alias方法的典型用法代码示例。如果您正苦于以下问题:Python BuildConfiguration._register_target_alias方法的具体用法?Python BuildConfiguration._register_target_alias怎么用?Python BuildConfiguration._register_target_alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.base.build_configuration.BuildConfiguration
的用法示例。
在下文中一共展示了BuildConfiguration._register_target_alias方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BuildConfigurationTest
# 需要导入模块: from pants.base.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.base.build_configuration.BuildConfiguration import _register_target_alias [as 别名]
class BuildConfigurationTest(unittest.TestCase):
def setUp(self):
self.build_configuration = BuildConfiguration()
def test_register_target_alias(self):
class Fred(Target):
pass
self.build_configuration._register_target_alias('fred', Fred)
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.objects)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(fred=Fred), aliases.targets)
build_file = FilesystemBuildFile('/tmp', 'fred', must_exist=False)
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.registered_addressable_instances))
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.registered_addressable_instances))
name, target_proxy = parse_state.registered_addressable_instances.pop()
self.assertEqual('jake', target_proxy.addressed_name)
self.assertEqual(Fred, target_proxy.addressed_type)
def test_register_bad_target_alias(self):
with self.assertRaises(TypeError):
self.build_configuration._register_target_alias('fred', object())
target = Target('fred', Address.parse('a:b'), BuildGraph(address_mapper=None))
with self.assertRaises(TypeError):
self.build_configuration._register_target_alias('fred', target)
def test_register_exposed_object(self):
self.build_configuration._register_exposed_object('jane', 42)
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.targets)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(jane=42), aliases.objects)
build_file = FilesystemBuildFile('/tmp', 'jane', must_exist=False)
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.registered_addressable_instances))
self.assertEqual(1, len(parse_state.parse_globals))
self.assertEqual(42, parse_state.parse_globals['jane'])
def test_register_bad_exposed_object(self):
with self.assertRaises(TypeError):
self.build_configuration._register_exposed_object('jane', Target)
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):
return lambda: parse_context.rel_path
def test_register_exposed_context_aware_method(self):
self.do_test_exposed_context_aware_function(self.george_method)
@classmethod
def george_classmethod(cls, parse_context):
return lambda: parse_context.rel_path
def test_register_exposed_context_aware_classmethod(self):
self.do_test_exposed_context_aware_function(self.george_classmethod)
@staticmethod
def george_staticmethod(parse_context):
return lambda: parse_context.rel_path
def test_register_exposed_context_aware_staticmethod(self):
self.do_test_exposed_context_aware_function(self.george_staticmethod)
def do_test_exposed_context_aware_function(self, func, *args, **kwargs):
with self.do_test_exposed_context_aware_object(func) as context_aware_object:
self.assertEqual('george', context_aware_object(*args, **kwargs))
def test_register_exposed_context_aware_class(self):
class George(object):
def __init__(self, parse_context):
self._parse_context = parse_context
def honorific(self):
return len(self._parse_context.rel_path)
with self.do_test_exposed_context_aware_object(George) as context_aware_object:
self.assertEqual(6, context_aware_object.honorific())
@contextmanager
def do_test_exposed_context_aware_object(self, context_aware_object_factory):
self.build_configuration._register_exposed_context_aware_object_factory(
'george', context_aware_object_factory)
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.targets)
#.........这里部分代码省略.........