summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Milner <mike.milner@canonical.com>2012-02-21 15:26:08 -0400
committerMike Milner <mike.milner@canonical.com>2012-02-21 15:26:08 -0400
commit8b17caade46cf84050961e24a0006386dbe96669 (patch)
tree09a112e9f23ed581e21e32df8cf36194f1fb5f48 /tests
parent149e58e715dba9c6c332ac12ddc4cca6609cbb41 (diff)
downloadvyos-cloud-init-8b17caade46cf84050961e24a0006386dbe96669.tar.gz
vyos-cloud-init-8b17caade46cf84050961e24a0006386dbe96669.zip
Add test and fix for catching exceptions.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test__init__.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index 79df8e72..f1818e9c 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -144,3 +144,23 @@ class TestHandlerHandlePart(MockerTestCase):
self.mocker.replay()
handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ def test_exception_is_caught(self):
+ """Exceptions within C{handle_part} are caught and logged."""
+ # Build a mock part-handler module
+ mod_mock = self.mocker.mock()
+ getattr(mod_mock, "frequency")
+ self.mocker.result("once-per-instance")
+ getattr(mod_mock, "handler_version")
+ self.mocker.result(1)
+ mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload)
+ self.mocker.throw(Exception())
+ # Mock log function
+ logexc_mock = self.mocker.replace(logexc, passthrough=False)
+ logexc_mock(ANY)
+ # Mock the print_exc function
+ print_exc_mock = self.mocker.replace("traceback.print_exc", passthrough=False)
+ print_exc_mock(ARGS, KWARGS)
+ self.mocker.replay()
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)