import-export daemon: Allow changing compression method
[ganeti-local] / test / ganeti.compat_unittest.py
1 #!/usr/bin/python
2 #
3
4 # Copyright (C) 2010 Google Inc.
5 #
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.
10 #
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.
15 #
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
19 # 02110-1301, USA.
20
21
22 """Script for unittesting the compat module"""
23
24 import unittest
25
26 from ganeti import compat
27
28 import testutils
29
30
31 class TestPartial(testutils.GanetiTestCase):
32   def test(self):
33     # Test standard version
34     self._Test(compat.partial)
35
36     # Test our version
37     self._Test(compat._partial)
38
39   def _Test(self, fn):
40     def _TestFunc1(x, power=2):
41       return x ** power
42
43     cubic = fn(_TestFunc1, power=3)
44     self.assertEqual(cubic(1), 1)
45     self.assertEqual(cubic(3), 27)
46     self.assertEqual(cubic(4), 64)
47
48     def _TestFunc2(*args, **kwargs):
49       return (args, kwargs)
50
51     self.assertEqualValues(fn(_TestFunc2, "Hello", "World")("Foo"),
52                            (("Hello", "World", "Foo"), {}))
53
54     self.assertEqualValues(fn(_TestFunc2, "Hello", xyz=123)("Foo"),
55                            (("Hello", "Foo"), {"xyz": 123}))
56
57     self.assertEqualValues(fn(_TestFunc2, xyz=123)("Foo", xyz=999),
58                            (("Foo", ), {"xyz": 999,}))
59
60
61 if __name__ == "__main__":
62   testutils.GanetiTestProgram()