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


Python UnionProducts.copy方法代码示例

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


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

示例1: UnionProductsTest

# 需要导入模块: from pants.goal.products import UnionProducts [as 别名]
# 或者: from pants.goal.products.UnionProducts import copy [as 别名]
class UnionProductsTest(BaseTest):
  def setUp(self):
    super(UnionProductsTest, self).setUp()
    self.products = UnionProducts()

  def test_get_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2, 3]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))
    self.assertEquals(self.products.get_for_target(a, transitive=False), OrderedSet([1]))
    self.assertEquals(self.products.get_for_target(b, transitive=False), OrderedSet([2]))
    self.assertEquals(self.products.get_for_target(c, transitive=False), OrderedSet([3]))

  def test_copy(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])

    copied = self.products.copy()

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEquals(copied.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(copied.get_for_target(b), OrderedSet([2]))

    copied.add_for_target(c, [3])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet())
    self.assertEquals(copied.get_for_target(a), OrderedSet([1, 2, 3]))
    self.assertEquals(copied.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(copied.get_for_target(c), OrderedSet([3]))

  def test_remove_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.products.remove_for_target(a, [1])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))

  def test_empty_products(self):
    c = self.make_target('c')
    self.assertFalse(self.products.get_for_target(c))

  def test_non_empty_products(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])
    self.assertTrue(self.products.get_for_target(c))

  def test_target_for_product_existing_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(3)

    self.assertEqual(c, found_target)

  def test_target_for_product_nonexistent_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(1000)

    self.assertIsNone(found_target)
开发者ID:kslundberg,项目名称:pants,代码行数:83,代码来源:test_union_products.py

示例2: UnionProductsTest

# 需要导入模块: from pants.goal.products import UnionProducts [as 别名]
# 或者: from pants.goal.products.UnionProducts import copy [as 别名]
class UnionProductsTest(TestBase):
  def setUp(self):
    super(UnionProductsTest, self).setUp()
    self.products = UnionProducts()

  def test_get_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2, 3]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))
    self.assertEqual(self.products.get_for_target(a), OrderedSet([1]))
    self.assertEqual(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEqual(self.products.get_for_target(c), OrderedSet([3]))

  def test_get_product_target_mappings_for_targets(self):
    b = self.make_target('b')
    a = self.make_target('a', dependencies=[b])
    self.products.add_for_target(a, [1, 3])
    self.products.add_for_target(b, [2, 3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 3, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))

    self.assertEqual(self.products.get_product_target_mappings_for_targets(a.closure(bfs=True)),
                      [(1, a), (3, a), (2, b), (3, b)])

  def test_copy(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])

    copied = self.products.copy()

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))
    self.assertEqual(copied.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(copied.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))

    copied.add_for_target(c, [3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet())
    self.assertEqual(copied.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2, 3]))
    self.assertEqual(copied.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(copied.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))

  def test_remove_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.products.remove_for_target(a, [1])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))

  def test_empty_products(self):
    c = self.make_target('c')
    self.assertFalse(self.products.get_for_target(c))

  def test_non_empty_products(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])
    self.assertTrue(self.products.get_for_target(c))

  def test_target_for_product_existing_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(3)

    self.assertEqual(c, found_target)

  def test_target_for_product_nonexistent_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(1000)

    self.assertIsNone(found_target)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:95,代码来源:test_union_products.py


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