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


Python build_file_manipulator.BuildFileManipulator類代碼示例

本文整理匯總了Python中pants.contrib.buildgen.build_file_manipulator.BuildFileManipulator的典型用法代碼示例。如果您正苦於以下問題:Python BuildFileManipulator類的具體用法?Python BuildFileManipulator怎麽用?Python BuildFileManipulator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: test_forced_target_rules

  def test_forced_target_rules(self):
    expected_target_str = dedent(
      """\
      target_type(
        # This comment should be okay
        name = 'no_bg_no_cry',  # Side comments here will stay
        # This comment should be okay
        dependencies = [
          # only_above
          ':only_above',
          ':only_side',  # only_side
          # nbgbc_above1
          # nbgnc_above2
          'really/need/this:dep',  # nobgnc_side
        ],
        # This comment is also fine
        thing = object()
        # And finally this comment survives
      )"""
    )

    build_file = self.add_to_build_file('BUILD', self.complicated_dep_comments)

    complicated_bfm = BuildFileManipulator.load(build_file, 'no_bg_no_cry', set(['target_type']))
    complicated_bfm.clear_unforced_dependencies()
    target_str = '\n'.join(complicated_bfm.target_lines())
    self.assertEqual(target_str, expected_target_str)
開發者ID:tsdeng,項目名稱:pants,代碼行數:27,代碼來源:test_build_file_manipulator.py

示例2: test_target_insertion_middle

  def test_target_insertion_middle(self):
    expected_build_string = dedent(
      """\
      # This comment should stay
      target_type(
        name = 'target_top',
        dependencies = [
          ':dep_a',
        ]
      )



      target_type(
        name = 'target_middle',
        dependencies = [
          ':dep_b',
          ':new_dep',
        ],
      )
      # This comment should be okay
      target_type(
        name = 'target_bottom',
      )
      # Also this one though it's weird"""
    )

    build_file = self.add_to_build_file('BUILD', self.multi_target_build_string)

    multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
    multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
    build_file_str = '\n'.join(multi_targ_bfm.build_file_lines())
    self.assertEqual(build_file_str, expected_build_string)
開發者ID:tsdeng,項目名稱:pants,代碼行數:33,代碼來源:test_build_file_manipulator.py

示例3: test_simple_targets

  def test_simple_targets(self):
    simple_targets = dedent(
      """
      target_type(
        name = 'no_deps',
      )

      target_type(
        name = 'empty_deps',
        dependencies = [
        ]
      )

      target_type(
        name = 'empty_deps_inline',
        dependencies = []
      )
      """
    )

    build_file = self.add_to_build_file('BUILD', simple_targets)

    for no_deps_name in ['no_deps', 'empty_deps', 'empty_deps_inline']:
      no_deps = BuildFileManipulator.load(build_file, no_deps_name, {'target_type'})
      self.assertEqual(tuple(no_deps.dependency_lines()), tuple())
      no_deps.add_dependency(Address.parse(':fake_dep'))
      self.assertEqual(tuple(no_deps.dependency_lines()),
                       tuple(['  dependencies = [',
                              "    ':fake_dep',",
                              '  ],']))
      no_deps.add_dependency(Address.parse(':b_fake_dep'))
      no_deps.add_dependency(Address.parse(':a_fake_dep'))
      self.assertEqual(tuple(no_deps.dependency_lines()),
                       tuple(['  dependencies = [',
                              "    ':a_fake_dep',",
                              "    ':b_fake_dep',",
                              "    ':fake_dep',",
                              '  ],']))
      self.assertEqual(tuple(no_deps.target_lines()),
                       tuple(['target_type(',
                              "  name = '{0}',".format(no_deps_name),
                              '  dependencies = [',
                              "    ':a_fake_dep',",
                              "    ':b_fake_dep',",
                              "    ':fake_dep',",
                              '  ],',
                              ')']))
開發者ID:tsdeng,項目名稱:pants,代碼行數:47,代碼來源:test_build_file_manipulator.py

示例4: test_target_write

  def test_target_write(self):
    expected_build_string = dedent(
      """\
      # This comment should stay
      target_type(
        name = 'target_top',
        dependencies = [
          ':dep_a',
        ]
      )



      target_type(
        name = 'target_middle',
        dependencies = [
          ':dep_b',
          ':new_dep',
        ],
      )
      # This comment should be okay
      target_type(
        name = 'target_bottom',
      )
      # Also this one though it's weird
      """
    )

    build_file = self.add_to_build_file('BUILD', self.multi_target_build_string + '\n')

    multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
    multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
    multi_targ_bfm.write(dry_run=False)

    with open(build_file.full_path, 'r') as bf:
      self.assertEqual(bf.read(), expected_build_string)
開發者ID:tsdeng,項目名稱:pants,代碼行數:36,代碼來源:test_build_file_manipulator.py

示例5: test_malformed_targets

  def test_malformed_targets(self):
    bad_targets = dedent(
      """
      target_type(name='name_on_line')

      target_type(
        name=
        'dangling_kwarg_value'
      )

      # TODO(pl):  Split this out.  Right now it fails
      # the test for all of the targets and masks other
      # expected failures
      # target_type(
      #   name=str('non_str_literal')
      # )

      target_type(
        name='end_paren_not_on_own_line')

      target_type(
        object(),
        name='has_non_kwarg'
      )

      target_type(
        name='non_list_deps',
        dependencies=object(),
      )

      target_type(
        name='deps_not_on_own_lines1',
        dependencies=['some_dep'],
      )

      target_type(
        name='deps_not_on_own_lines2',
        dependencies=[
          'some_dep', 'some_other_dep'],
      )

      target_type(
        name = 'sentinel',
      )
      """
    )

    build_file = self.add_to_build_file('BUILD', bad_targets)

    bad_target_names = [
      'name_on_line',
      'dangling_kwarg_value',
      # TODO(pl): See TODO above
      # 'non_str_literal',
      'end_paren_not_on_own_line',
      'name_not_in_build_file',
      'has_non_kwarg',
      'non_list_deps',
    ]
    # Make sure this exception isn't just being thrown no matter what.
    # TODO(pl): These exception types should be more granular.
    BuildFileManipulator.load(build_file, 'sentinel', set(['target_type']))
    for bad_target in bad_target_names:
      with self.assertRaises(BuildTargetParseError):
        BuildFileManipulator.load(build_file, bad_target, set(['target_type']))
開發者ID:tsdeng,項目名稱:pants,代碼行數:65,代碼來源:test_build_file_manipulator.py


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