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 testing ganeti.backend"""
28 from ganeti import errors
33 class TestErrors(testutils.GanetiTestCase):
34 def testGetErrorClass(self):
40 "NoErrorClassName": None,
41 "GenericError": errors.GenericError,
42 "ProgrammerError": errors.ProgrammerError,
45 for name, cls in tdata.items():
46 self.assert_(errors.GetErrorClass(name) is cls)
48 def testEncodeException(self):
49 self.assertEqualValues(errors.EncodeException(Exception("Foobar")),
50 ("Exception", ("Foobar", )))
51 err = errors.GenericError(True, 100, "foo", ["x", "y"])
52 self.assertEqualValues(errors.EncodeException(err),
53 ("GenericError", (True, 100, "foo", ["x", "y"])))
55 def testMaybeRaise(self):
56 # These shouldn't raise
57 for i in [None, 1, 2, 3, "Hello World", (1, ), (1, 2, 3),
58 ("NoErrorClassName", []), ("NoErrorClassName", None),
59 ("GenericError", [1, 2, 3], None), ("GenericError", 1)]:
62 self.assertRaises(errors.GenericError, errors.MaybeRaise,
63 ("GenericError", ["Hello"]))
66 if __name__ == "__main__":
67 testutils.GanetiTestProgram()