[Piglit] [PATCH 10/16] backends: replace error class with generic error

Dylan Baker baker.dylan.c at gmail.com
Tue Apr 21 15:44:27 PDT 2015


This allows more exceptions to be caught at the top level exception
handling, requiring fewer try/except blocks in the middle of the code
that exit. This should make the code a little easier to read.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/errors.py  | 25 -------------------------
 framework/backends/json.py    |  7 +++----
 framework/programs/summary.py | 12 ++----------
 framework/summary.py          |  6 +-----
 4 files changed, 6 insertions(+), 44 deletions(-)
 delete mode 100644 framework/backends/errors.py

diff --git a/framework/backends/errors.py b/framework/backends/errors.py
deleted file mode 100644
index 150bc19..0000000
--- a/framework/backends/errors.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (c) 2015 Intel Corporation
-
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-"""Shared errors for the backends."""
-
-
-class ResultsLoadError(Exception):
-    pass
diff --git a/framework/backends/json.py b/framework/backends/json.py
index affd64e..ea87781 100644
--- a/framework/backends/json.py
+++ b/framework/backends/json.py
@@ -31,10 +31,9 @@ try:
 except ImportError:
     import json
 
-from framework import status, results
+from framework import status, results, exceptions
 from .abstract import FileBackend
 from .register import Registry
-from . import errors
 
 __all__ = [
     'REGISTRY',
@@ -186,8 +185,8 @@ def load_results(filename):
         elif os.path.exists(os.path.join(filename, 'main')):
             filepath = os.path.join(filename, 'main')
         else:
-            raise errors.ResultsLoadError('No results found in "{}"'.format(
-                filename))
+            raise exceptions.PiglitFatalError(
+                'No results found in "{}"'.format(filename))
 
     with open(filepath, 'r') as f:
         testrun = _load(f)
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index 6ce4365..76ff6cc 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -156,11 +156,7 @@ def csv(input_):
                         help="JSON results file to be converted")
     args = parser.parse_args(input_)
 
-    try:
-        testrun = backends.load(args.testResults)
-    except backends.errors.ResultsLoadError as e:
-        print('Error: {}'.format(e.message), file=sys.stderr)
-        sys.exit(1)
+    testrun = backends.load(args.testResults)
 
     def write_results(output):
         for name, result in testrun.tests.iteritems():
@@ -191,11 +187,7 @@ def aggregate(input_):
     assert os.path.isdir(args.results_folder)
 
     outfile = os.path.join(args.results_folder, args.output)
-    try:
-        results = backends.load(args.results_folder)
-    except backends.errors.ResultsLoadError as e:
-        print('Error: {}'.format(e.message), file=sys.stderr)
-        sys.exit(1)
+    results = backends.load(args.results_folder)
 
     try:
         # FIXME: This works, it fixes the problem, but it only works because
diff --git a/framework/summary.py b/framework/summary.py
index 9b30b5e..b5c9d44 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -299,11 +299,7 @@ class Summary:
 
         # Create a Result object for each piglit result and append it to the
         # results list
-        try:
-            self.results = [backends.load(i) for i in resultfiles]
-        except backends.errors.ResultsLoadError as e:
-            print('Error: {}'.format(e.message), file=sys.stderr)
-            sys.exit(1)
+        self.results = [backends.load(i) for i in resultfiles]
 
         self.status = {}
         self.fractions = {}
-- 
2.3.5



More information about the Piglit mailing list