Revision 98dfcaff test/ganeti.errors_unittest.py
b/test/ganeti.errors_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010 Google Inc. |
|
4 |
# Copyright (C) 2010, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
53 | 53 |
("GenericError", (True, 100, "foo", ["x", "y"]))) |
54 | 54 |
|
55 | 55 |
def testMaybeRaise(self): |
56 |
testvals = [None, 1, 2, 3, "Hello World", (1, ), (1, 2, 3), |
|
57 |
("NoErrorClassName", []), ("NoErrorClassName", None), |
|
58 |
("GenericError", [1, 2, 3], None), ("GenericError", 1)] |
|
56 | 59 |
# 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)]: |
|
60 |
for i in testvals: |
|
60 | 61 |
errors.MaybeRaise(i) |
61 | 62 |
|
62 | 63 |
self.assertRaises(errors.GenericError, errors.MaybeRaise, |
63 | 64 |
("GenericError", ["Hello"])) |
65 |
# Check error encoding |
|
66 |
for i in testvals: |
|
67 |
src = errors.GenericError(i) |
|
68 |
try: |
|
69 |
errors.MaybeRaise(errors.EncodeException(src)) |
|
70 |
except errors.GenericError, dst: |
|
71 |
self.assertEqual(src.args, dst.args) |
|
72 |
self.assertEqual(src.__class__, dst.__class__) |
|
73 |
else: |
|
74 |
self.fail("Exception %s not raised" % repr(src)) |
|
64 | 75 |
|
65 | 76 |
def testGetEncodedError(self): |
66 | 77 |
self.assertEqualValues(errors.GetEncodedError(["GenericError", |
Also available in: Unified diff