當前位置: 首頁>>代碼示例>>Python>>正文


Python BuildConfiguration.initialize_parse_state方法代碼示例

本文整理匯總了Python中pants.build_graph.build_configuration.BuildConfiguration.initialize_parse_state方法的典型用法代碼示例。如果您正苦於以下問題:Python BuildConfiguration.initialize_parse_state方法的具體用法?Python BuildConfiguration.initialize_parse_state怎麽用?Python BuildConfiguration.initialize_parse_state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pants.build_graph.build_configuration.BuildConfiguration的用法示例。


在下文中一共展示了BuildConfiguration.initialize_parse_state方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: BuildConfigurationTest

# 需要導入模塊: from pants.build_graph.build_configuration import BuildConfiguration [as 別名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import initialize_parse_state [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):
#.........這裏部分代碼省略.........
開發者ID:cosmicexplorer,項目名稱:pants,代碼行數:103,代碼來源:test_build_configuration.py


注:本文中的pants.build_graph.build_configuration.BuildConfiguration.initialize_parse_state方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。