当前位置: 首页>>代码示例>>Python>>正文


Python Shader.temporary_rules_file方法代码示例

本文整理汇总了Python中pants.backend.jvm.subsystems.shader.Shader.temporary_rules_file方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.temporary_rules_file方法的具体用法?Python Shader.temporary_rules_file怎么用?Python Shader.temporary_rules_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.backend.jvm.subsystems.shader.Shader的用法示例。


在下文中一共展示了Shader.temporary_rules_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ShaderTest

# 需要导入模块: from pants.backend.jvm.subsystems.shader import Shader [as 别名]
# 或者: from pants.backend.jvm.subsystems.shader.Shader import temporary_rules_file [as 别名]

#.........这里部分代码省略.........
      if jar_or_cp != '-jar':
        # We don't really care what the name of the jarjar main class is - shader.command[2]
        command.pop(0)

      self.assertEqual('process', command.pop(0))

      rules_file = command.pop(0)
      self.assertTrue(os.path.exists(rules_file))
      with open(rules_file) as fp:
        lines = fp.read().splitlines()
        self.assertEqual('rule log4j.** [email protected]', lines[0])  # The custom rule.
        self.assertEqual('rule * @1', lines[1])  # Exclude main's package.
        self.assertIn('rule javax.annotation.* [email protected]', lines)  # Exclude system.
        self.assertEqual('rule com.google.common.base.* {}[email protected]'
                         .format(Shading.SHADE_PREFIX), lines[-1])  # Shade the rest.

      self.assertEqual(input_jar, command.pop(0))
      self.assertEqual(self.output_jar, command.pop(0))

  def test_infer_shaded_pattern(self):
    def assert_inference(from_pattern, prefix, to_pattern):
      result = ''.join(RelocateRule._infer_shaded_pattern_iter(from_pattern, prefix))
      self.assertEqual(to_pattern, result)

    assert_inference('com.foo.bar.Main', None, 'com.foo.bar.Main')
    assert_inference('com.foo.bar.', None, 'com.foo.bar.')
    assert_inference('com.foo.bar.', '__prefix__.', '__prefix__.com.foo.bar.')
    assert_inference('com.*.bar.', None, '[email protected]')
    assert_inference('com.*.bar.*.', None, '[email protected]@2.')
    assert_inference('com.*.bar.**', None, '[email protected]@2')
    assert_inference('*', None, '@1')
    assert_inference('**', None, '@1')
    assert_inference('**', '__prefix__.', '[email protected]')

  def test_shading_exclude(self):
    def assert_exclude(from_pattern, to_pattern):
      self.assertEqual((from_pattern, to_pattern), Shading.create_exclude(from_pattern))

    assert_exclude('com.foo.bar.Main', 'com.foo.bar.Main')
    assert_exclude('com.foo.bar.**', '[email protected]')
    assert_exclude('com.*.bar.**', '[email protected]@2')

  def test_shading_exclude_package(self):
    self.assertEqual(('com.foo.bar.**', '[email protected]'),
                     Shading.create_exclude_package('com.foo.bar'))
    self.assertEqual(('com.foo.bar.*', '[email protected]'),
                     Shading.create_exclude_package('com.foo.bar', recursive=False))

  def test_relocate(self):
    self.assertEqual(('com.foo.bar.**', '{}[email protected]'.format(Shading.SHADE_PREFIX)),
                     Shading.create_relocate(from_pattern='com.foo.bar.**'))

    self.assertEqual(('com.foo.bar.**', '{}[email protected]'.format('__my_prefix__.')),
                     Shading.create_relocate(from_pattern='com.foo.bar.**',
                                      shade_prefix='__my_prefix__.'))

    self.assertEqual(('com.foo.bar.**', '[email protected]'.format('__my_prefix__.')),
                     Shading.create_relocate(from_pattern='com.foo.bar.**',
                                      shade_prefix='__my_prefix__.',
                                      shade_pattern='[email protected]'))

  def test_relocate_package(self):
    self.assertEqual(('com.foo.bar.**', '{}[email protected]'.format(Shading.SHADE_PREFIX)),
                     Shading.create_relocate_package('com.foo.bar'))
    self.assertEqual(('com.foo.bar.*', '{}[email protected]'.format(Shading.SHADE_PREFIX)),
                     Shading.create_relocate_package('com.foo.bar', recursive=False))
    self.assertEqual(('com.foo.bar.**', '[email protected]'),
                     Shading.create_relocate_package('com.foo.bar', shade_prefix='__p__.'))

  def test_zap_package(self):
    self.assertEqual(('zap', 'com.foo.bar.**'), Shading.create_zap_package('com.foo.bar', True))
    self.assertEqual(('zap', 'com.foo.bar.*'), Shading.create_zap_package('com.foo.bar', False))

  def test_keep_package(self):
    self.assertEqual(('keep', 'com.foo.bar.**'), Shading.create_keep_package('com.foo.bar', True))
    self.assertEqual(('keep', 'com.foo.bar.*'), Shading.create_keep_package('com.foo.bar', False))

  def test_rules_file(self):
    expected = [
      'rule a.b.c.** [email protected]\n',
      'rule a.*.b [email protected]\n',
      'rule x.y.z.** [email protected]\n',
      'zap com.foo.bar.Main\n',
      'zap com.baz.*\n',
      'keep org.foobar.vegetable.Potato\n',
      'keep org.foobar.fruit.**\n',
    ]
    rules = [
      Shading.create_relocate('a.b.c.**', '[email protected]'),
      Shading.create_relocate('a.*.b', shade_prefix='shaded.'),
      Shading.create_relocate_package('x.y.z', shade_prefix='shaded.'),
      Shading.create_zap('com.foo.bar.Main'),
      Shading.create_zap_package('com.baz', recursive=False),
      Shading.create_keep('org.foobar.vegetable.Potato'),
      Shading.create_keep_package('org.foobar.fruit'),
    ]
    with self.shader.temporary_rules_file(rules) as fname:
      with open(fname, 'r') as f:
        received = f.readlines()
        self.assertEqual(received, expected)
开发者ID:CaitieM20,项目名称:pants,代码行数:104,代码来源:test_shader.py

示例2: ShaderTest

# 需要导入模块: from pants.backend.jvm.subsystems.shader import Shader [as 别名]
# 或者: from pants.backend.jvm.subsystems.shader.Shader import temporary_rules_file [as 别名]

#.........这里部分代码省略.........
                self.assertIn("rule javax.annotation.* [email protected]", lines)  # Exclude system.
                self.assertEqual(
                    "rule com.google.common.base.* {}[email protected]".format(Shading.SHADE_PREFIX), lines[-1]
                )  # Shade the rest.

            self.assertEqual(input_jar, command.pop(0))
            self.assertEqual(self.output_jar, command.pop(0))

    def test_infer_shaded_pattern(self):
        def assert_inference(from_pattern, prefix, to_pattern):
            result = "".join(Shading.RelocateRule._infer_shaded_pattern_iter(from_pattern, prefix))
            self.assertEqual(to_pattern, result)

        assert_inference("com.foo.bar.Main", None, "com.foo.bar.Main")
        assert_inference("com.foo.bar.", None, "com.foo.bar.")
        assert_inference("com.foo.bar.", "__prefix__.", "__prefix__.com.foo.bar.")
        assert_inference("com.*.bar.", None, "[email protected]")
        assert_inference("com.*.bar.*.", None, "[email protected]@2.")
        assert_inference("com.*.bar.**", None, "[email protected]@2")
        assert_inference("*", None, "@1")
        assert_inference("**", None, "@1")
        assert_inference("**", "__prefix__.", "[email protected]")

    def test_shading_exclude(self):
        def assert_exclude(from_pattern, to_pattern):
            self.assertEqual((from_pattern, to_pattern), Shading.create_exclude(from_pattern))

        assert_exclude("com.foo.bar.Main", "com.foo.bar.Main")
        assert_exclude("com.foo.bar.**", "[email protected]")
        assert_exclude("com.*.bar.**", "[email protected]@2")

    def test_shading_exclude_package(self):
        self.assertEqual(("com.foo.bar.**", "[email protected]"), Shading.create_exclude_package("com.foo.bar"))
        self.assertEqual(
            ("com.foo.bar.*", "[email protected]"), Shading.create_exclude_package("com.foo.bar", recursive=False)
        )

    def test_relocate(self):
        self.assertEqual(
            ("com.foo.bar.**", "{}[email protected]".format(Shading.SHADE_PREFIX)),
            Shading.create_relocate(from_pattern="com.foo.bar.**"),
        )

        self.assertEqual(
            ("com.foo.bar.**", "{}[email protected]".format("__my_prefix__.")),
            Shading.create_relocate(from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__."),
        )

        self.assertEqual(
            ("com.foo.bar.**", "[email protected]".format("__my_prefix__.")),
            Shading.create_relocate(
                from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__.", shade_pattern="[email protected]"
            ),
        )

    def test_relocate_package(self):
        self.assertEqual(
            ("com.foo.bar.**", "{}[email protected]".format(Shading.SHADE_PREFIX)),
            Shading.create_relocate_package("com.foo.bar"),
        )
        self.assertEqual(
            ("com.foo.bar.*", "{}[email protected]".format(Shading.SHADE_PREFIX)),
            Shading.create_relocate_package("com.foo.bar", recursive=False),
        )
        self.assertEqual(
            ("com.foo.bar.**", "[email protected]"),
            Shading.create_relocate_package("com.foo.bar", shade_prefix="__p__."),
        )

    def test_zap_package(self):
        self.assertEqual(("zap", "com.foo.bar.**"), Shading.create_zap_package("com.foo.bar", True))
        self.assertEqual(("zap", "com.foo.bar.*"), Shading.create_zap_package("com.foo.bar", False))

    def test_keep_package(self):
        self.assertEqual(("keep", "com.foo.bar.**"), Shading.create_keep_package("com.foo.bar", True))
        self.assertEqual(("keep", "com.foo.bar.*"), Shading.create_keep_package("com.foo.bar", False))

    def test_rules_file(self):
        expected = [
            "rule a.b.c.** [email protected]\n",
            "rule a.*.b [email protected]\n",
            "rule x.y.z.** [email protected]\n",
            "zap com.foo.bar.Main\n",
            "zap com.baz.*\n",
            "keep org.foobar.vegetable.Potato\n",
            "keep org.foobar.fruit.**\n",
        ]
        rules = [
            Shading.create_relocate("a.b.c.**", "[email protected]"),
            Shading.create_relocate("a.*.b", shade_prefix="shaded."),
            Shading.create_relocate_package("x.y.z", shade_prefix="shaded."),
            Shading.create_zap("com.foo.bar.Main"),
            Shading.create_zap_package("com.baz", recursive=False),
            Shading.create_keep("org.foobar.vegetable.Potato"),
            Shading.create_keep_package("org.foobar.fruit"),
        ]
        with self.shader.temporary_rules_file(rules) as fname:
            with open(fname, "r") as f:
                received = f.readlines()
                self.assertEqual(received, expected)
开发者ID:ahamilton55,项目名称:pants,代码行数:104,代码来源:test_shader.py


注:本文中的pants.backend.jvm.subsystems.shader.Shader.temporary_rules_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。