Revision cea881e5 test/ganeti.utils_unittest.py

b/test/ganeti.utils_unittest.py
1592 1592
                             "", "x"])
1593 1593

  
1594 1594

  
1595
class TestPartial(testutils.GanetiTestCase):
1596
  def test(self):
1597
    self._Test(utils.partial)
1598
    self._Test(utils._partial)
1599

  
1600
  def _Test(self, fn):
1601
    def _TestFunc1(x, power=2):
1602
      return x ** power
1603

  
1604
    cubic = fn(_TestFunc1, power=3)
1605
    self.assertEqual(cubic(1), 1)
1606
    self.assertEqual(cubic(3), 27)
1607
    self.assertEqual(cubic(4), 64)
1608

  
1609
    def _TestFunc2(*args, **kwargs):
1610
      return (args, kwargs)
1611

  
1612
    self.assertEqualValues(fn(_TestFunc2, "Hello", "World")("Foo"),
1613
                           (("Hello", "World", "Foo"), {}))
1614

  
1615
    self.assertEqualValues(fn(_TestFunc2, "Hello", xyz=123)("Foo"),
1616
                           (("Hello", "Foo"), {"xyz": 123}))
1617

  
1618
    self.assertEqualValues(fn(_TestFunc2, xyz=123)("Foo", xyz=999),
1619
                           (("Foo", ), {"xyz": 999,}))
1620

  
1621

  
1622 1595
if __name__ == '__main__':
1623 1596
  testutils.GanetiTestProgram()

Also available in: Unified diff