root / test / ganeti.errors_unittest.py @ 49f986e7
History | View | Annotate | Download (2 kB)
1 | 3bd19c66 | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | 3bd19c66 | Michael Hanselmann | #
|
3 | 3bd19c66 | Michael Hanselmann | |
4 | 3bd19c66 | Michael Hanselmann | # Copyright (C) 2010 Google Inc.
|
5 | 3bd19c66 | Michael Hanselmann | #
|
6 | 3bd19c66 | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | 3bd19c66 | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | 3bd19c66 | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | 3bd19c66 | Michael Hanselmann | # (at your option) any later version.
|
10 | 3bd19c66 | Michael Hanselmann | #
|
11 | 3bd19c66 | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | 3bd19c66 | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 3bd19c66 | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 3bd19c66 | Michael Hanselmann | # General Public License for more details.
|
15 | 3bd19c66 | Michael Hanselmann | #
|
16 | 3bd19c66 | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | 3bd19c66 | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | 3bd19c66 | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 3bd19c66 | Michael Hanselmann | # 02110-1301, USA.
|
20 | 3bd19c66 | Michael Hanselmann | |
21 | 3bd19c66 | Michael Hanselmann | |
22 | 3bd19c66 | Michael Hanselmann | """Script for testing ganeti.backend"""
|
23 | 3bd19c66 | Michael Hanselmann | |
24 | 3bd19c66 | Michael Hanselmann | import os |
25 | 3bd19c66 | Michael Hanselmann | import sys |
26 | 3bd19c66 | Michael Hanselmann | import unittest |
27 | 3bd19c66 | Michael Hanselmann | |
28 | 3bd19c66 | Michael Hanselmann | from ganeti import errors |
29 | 3bd19c66 | Michael Hanselmann | |
30 | 3bd19c66 | Michael Hanselmann | import testutils |
31 | 3bd19c66 | Michael Hanselmann | |
32 | 3bd19c66 | Michael Hanselmann | |
33 | 3bd19c66 | Michael Hanselmann | class TestErrors(testutils.GanetiTestCase): |
34 | 3bd19c66 | Michael Hanselmann | def testGetErrorClass(self): |
35 | 3bd19c66 | Michael Hanselmann | tdata = { |
36 | 3bd19c66 | Michael Hanselmann | "": None, |
37 | 3bd19c66 | Michael Hanselmann | ".": None, |
38 | 3bd19c66 | Michael Hanselmann | "-": None, |
39 | 3bd19c66 | Michael Hanselmann | "ECODE_INVAL": None, |
40 | 3bd19c66 | Michael Hanselmann | "NoErrorClassName": None, |
41 | 3bd19c66 | Michael Hanselmann | "GenericError": errors.GenericError,
|
42 | 3bd19c66 | Michael Hanselmann | "ProgrammerError": errors.ProgrammerError,
|
43 | 3bd19c66 | Michael Hanselmann | } |
44 | 3bd19c66 | Michael Hanselmann | |
45 | 3bd19c66 | Michael Hanselmann | for name, cls in tdata.items(): |
46 | 3bd19c66 | Michael Hanselmann | self.assert_(errors.GetErrorClass(name) is cls) |
47 | 3bd19c66 | Michael Hanselmann | |
48 | 3bd19c66 | Michael Hanselmann | def testEncodeException(self): |
49 | 3bd19c66 | Michael Hanselmann | self.assertEqualValues(errors.EncodeException(Exception("Foobar")), |
50 | 3bd19c66 | Michael Hanselmann | ("Exception", ("Foobar", ))) |
51 | 3bd19c66 | Michael Hanselmann | err = errors.GenericError(True, 100, "foo", ["x", "y"]) |
52 | 3bd19c66 | Michael Hanselmann | self.assertEqualValues(errors.EncodeException(err),
|
53 | 3bd19c66 | Michael Hanselmann | ("GenericError", (True, 100, "foo", ["x", "y"]))) |
54 | 3bd19c66 | Michael Hanselmann | |
55 | 3bd19c66 | Michael Hanselmann | def testMaybeRaise(self): |
56 | 3bd19c66 | Michael Hanselmann | # These shouldn't raise
|
57 | 3bd19c66 | Michael Hanselmann | for i in [None, 1, 2, 3, "Hello World", (1, ), (1, 2, 3), |
58 | 3bd19c66 | Michael Hanselmann | ("NoErrorClassName", []), ("NoErrorClassName", None), |
59 | 3bd19c66 | Michael Hanselmann | ("GenericError", [1, 2, 3], None), ("GenericError", 1)]: |
60 | 3bd19c66 | Michael Hanselmann | errors.MaybeRaise(i) |
61 | 3bd19c66 | Michael Hanselmann | |
62 | 3bd19c66 | Michael Hanselmann | self.assertRaises(errors.GenericError, errors.MaybeRaise,
|
63 | 3bd19c66 | Michael Hanselmann | ("GenericError", ["Hello"])) |
64 | 3bd19c66 | Michael Hanselmann | |
65 | 3bd19c66 | Michael Hanselmann | |
66 | 3bd19c66 | Michael Hanselmann | if __name__ == "__main__": |
67 | 3bd19c66 | Michael Hanselmann | testutils.GanetiTestProgram() |