root / test / ganeti.objects_unittest.py @ d357f531
History | View | Annotate | Download (1.4 kB)
1 | 4c14965f | Guido Trotter | #!/usr/bin/python
|
---|---|---|---|
2 | 4c14965f | Guido Trotter | #
|
3 | 4c14965f | Guido Trotter | |
4 | 4c14965f | Guido Trotter | # Copyright (C) 2006, 2007, 2008 Google Inc.
|
5 | 4c14965f | Guido Trotter | #
|
6 | 4c14965f | Guido Trotter | # This program is free software; you can redistribute it and/or modify
|
7 | 4c14965f | Guido Trotter | # it under the terms of the GNU General Public License as published by
|
8 | 4c14965f | Guido Trotter | # the Free Software Foundation; either version 2 of the License, or
|
9 | 4c14965f | Guido Trotter | # (at your option) any later version.
|
10 | 4c14965f | Guido Trotter | #
|
11 | 4c14965f | Guido Trotter | # This program is distributed in the hope that it will be useful, but
|
12 | 4c14965f | Guido Trotter | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 4c14965f | Guido Trotter | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 4c14965f | Guido Trotter | # General Public License for more details.
|
15 | 4c14965f | Guido Trotter | #
|
16 | 4c14965f | Guido Trotter | # You should have received a copy of the GNU General Public License
|
17 | 4c14965f | Guido Trotter | # along with this program; if not, write to the Free Software
|
18 | 4c14965f | Guido Trotter | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 4c14965f | Guido Trotter | # 0.0510-1301, USA.
|
20 | 4c14965f | Guido Trotter | |
21 | 4c14965f | Guido Trotter | |
22 | 4c14965f | Guido Trotter | """Script for unittesting the objects module"""
|
23 | 4c14965f | Guido Trotter | |
24 | 4c14965f | Guido Trotter | |
25 | 4c14965f | Guido Trotter | import unittest |
26 | 4c14965f | Guido Trotter | |
27 | 4c14965f | Guido Trotter | from ganeti import objects |
28 | 4c14965f | Guido Trotter | |
29 | 4c14965f | Guido Trotter | class SimpleObject(objects.ConfigObject): |
30 | 4c14965f | Guido Trotter | __slots__ = ['a', 'b'] |
31 | 4c14965f | Guido Trotter | |
32 | 4c14965f | Guido Trotter | class TestDictState(unittest.TestCase): |
33 | 4c14965f | Guido Trotter | """Simple dict tansformation tests"""
|
34 | 4c14965f | Guido Trotter | |
35 | 4c14965f | Guido Trotter | def testSimpleObjectToDict(self): |
36 | 4c14965f | Guido Trotter | o1 = SimpleObject(a='1')
|
37 | 4c14965f | Guido Trotter | self.assertEquals(o1.ToDict(), {'a': '1'}) |
38 | 4c14965f | Guido Trotter | self.assertEquals(o1.__getstate__(), {'a': '1'}) |
39 | 4c14965f | Guido Trotter | self.assertEquals(o1.__getstate__(), o1.ToDict())
|
40 | 4c14965f | Guido Trotter | o1.a = 2
|
41 | 4c14965f | Guido Trotter | o1.b = 5
|
42 | 4c14965f | Guido Trotter | self.assertEquals(o1.ToDict(), {'a': 2, 'b': 5}) |
43 | 4c14965f | Guido Trotter | o2 = SimpleObject.FromDict(o1.ToDict()) |
44 | 4c14965f | Guido Trotter | self.assertEquals(o1.ToDict(), {'a': 2, 'b': 5}) |
45 | 4c14965f | Guido Trotter | |
46 | 4c14965f | Guido Trotter | |
47 | 4c14965f | Guido Trotter | if __name__ == '__main__': |
48 | 4c14965f | Guido Trotter | unittest.main() |