[Piglit] [PATCH 3/8] status.py: Make StatusException a child of PiglitInternalError

Dylan Baker baker.dylan.c at gmail.com
Fri Aug 21 17:21:15 PDT 2015


This change makes makes it simpler to handle this error than being a
descendant of LookupError. The biggest advantage is that the __str__
method provides a good error message.

This will be used in a later patch in this series.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/status.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/framework/status.py b/framework/status.py
index 98a9e3d..1e974a1 100644
--- a/framework/status.py
+++ b/framework/status.py
@@ -57,6 +57,7 @@ The formula for determining fixes is:
 """
 
 from __future__ import print_function, absolute_import
+from framework import exceptions
 
 __all__ = ['NOTRUN',
            'PASS',
@@ -96,10 +97,10 @@ def status_lookup(status):
         return status_dict[status]
     except KeyError:
         # Raise a StatusException rather than a key error
-        raise StatusException
+        raise StatusException(status)
 
 
-class StatusException(LookupError):
+class StatusException(exceptions.PiglitInternalError):
     """ Raise this exception when a string is passed to status_lookup that
     doesn't exists
 
@@ -109,7 +110,12 @@ class StatusException(LookupError):
     Error class here allows for more fine-grained control.
 
     """
-    pass
+    def __init__(self, status):
+        self.__status = status
+        super(StatusException, self).__init__(self)
+
+    def __str__(self):
+        return 'Unknown status "{}"'.format(self.__status)
 
 
 class Status(object):
-- 
2.5.0



More information about the Piglit mailing list