4 # Copyright (C) 2010 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Script for unittesting the compat module"""
26 from ganeti import compat
31 class TestPartial(testutils.GanetiTestCase):
33 # Test standard version
34 self._Test(compat.partial)
37 self._Test(compat._partial)
40 def _TestFunc1(x, power=2):
43 cubic = fn(_TestFunc1, power=3)
44 self.assertEqual(cubic(1), 1)
45 self.assertEqual(cubic(3), 27)
46 self.assertEqual(cubic(4), 64)
48 def _TestFunc2(*args, **kwargs):
51 self.assertEqualValues(fn(_TestFunc2, "Hello", "World")("Foo"),
52 (("Hello", "World", "Foo"), {}))
54 self.assertEqualValues(fn(_TestFunc2, "Hello", xyz=123)("Foo"),
55 (("Hello", "Foo"), {"xyz": 123}))
57 self.assertEqualValues(fn(_TestFunc2, xyz=123)("Foo", xyz=999),
58 (("Foo", ), {"xyz": 999,}))
61 if __name__ == "__main__":
62 testutils.GanetiTestProgram()