Smarter way that tests handle default exceptions (unhandled errors) and also a cleanup on test exception classes.
From: [email protected]
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1899 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/error.py b/client/common_lib/error.py
index 582810d..642860b 100644
--- a/client/common_lib/error.py
+++ b/client/common_lib/error.py
@@ -34,38 +34,62 @@
pass
-class TestError(AutotestError):
+class TestBaseException(AutotestError):
+ """The parent of all test exceptions."""
+
+
+class TestError(TestBaseException):
"""Indicates that something went wrong with the test harness itself."""
exit_status="ERROR"
pass
-class TestUnknownError(AutotestError):
- """Indicates an error which terminates and fails the test."""
- exit_status="FAIL"
- pass
-
-
-class TestNAError(AutotestError):
+class TestNAError(TestBaseException):
"""Indictates that the test is Not Applicable. Should be thrown
when various conditions are such that the test is inappropriate."""
exit_status="TEST_NA"
pass
-class TestFail(AutotestError):
+class TestFail(TestBaseException):
"""Indicates that the test failed, but the job will not continue."""
exit_status="FAIL"
pass
-class TestWarn(AutotestError):
+class TestWarn(TestBaseException):
"""Indicates that bad things (may) have happened, but not an explicit
failure."""
exit_status="WARN"
pass
+class UnhandledTestError(TestError):
+ """Indicates an unhandled error in a test."""
+ def __init__(self, unhandled_exception):
+ if isinstance(unhandled_exception, TestError):
+ TestError.__init__(self, *unhandled_exception.args)
+ else:
+ msg = "Unhandled %s: %s"
+ msg %= (unhandled_exception.__class__.__name__,
+ unhandled_exception)
+ msg += "\n" + traceback.format_exc()
+ TestError.__init__(self, msg)
+
+
+class UnhandledTestFail(TestFail):
+ """Indicates an unhandled fail in a test."""
+ def __init__(self, unhandled_exception):
+ if isinstance(unhandled_exception, TestFail):
+ TestFail.__init__(self, *unhandled_exception.args)
+ else:
+ msg = "Unhandled %s: %s"
+ msg %= (unhandled_exception.__class__.__name__,
+ unhandled_exception)
+ msg += "\n" + traceback.format_exc()
+ TestFail.__init__(self, msg)
+
+
class CmdError(TestError):
"""\
Indicates that a command failed, is fatal to the test unless caught.
@@ -95,19 +119,6 @@
pass
-class UnhandledError(TestUnknownError):
- """Indicates an unhandled exception in a test."""
- def __init__(self, unhandled_exception):
- if isinstance(unhandled_exception, AutotestError):
- TestUnknownError.__init__(self, *unhandled_exception.args)
- else:
- msg = "Unhandled %s: %s"
- msg %= (unhandled_exception.__class__.__name__,
- unhandled_exception)
- msg += "\n" + traceback.format_exc()
- TestUnknownError.__init__(self, msg)
-
-
class InstallError(JobError):
"""Indicates an installation error which Terminates and fails the job."""
pass