[Piglit] [PATCH v2 11/16] profile: use generic piglit exceptions
Dylan Baker
baker.dylan.c at gmail.com
Mon May 18 10:57:45 PDT 2015
This patch largely replaces an existing TestDictError class with a
generic exeption for exceptions.
It also simplifies some error handles in the load_test_profile function.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/profile.py | 33 ++++++++++++---------------------
framework/tests/profile_tests.py | 15 ++++++---------
2 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/framework/profile.py b/framework/profile.py
index 46a979c..66d7899 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -28,17 +28,16 @@ are represented by a TestProfile or a TestProfile derived object.
from __future__ import print_function, absolute_import
import os
-import sys
import multiprocessing
import multiprocessing.dummy
import importlib
import contextlib
import itertools
+from framework import grouptools, exceptions
from framework.dmesg import get_dmesg
from framework.log import LogManager
from framework.test.base import Test
-import framework.grouptools as grouptools
__all__ = [
'TestProfile',
@@ -47,10 +46,6 @@ __all__ = [
]
-class TestDictError(Exception):
- pass
-
-
class TestDict(dict): # pylint: disable=too-few-public-methods
"""A special kind of dict for tests.
@@ -79,13 +74,14 @@ class TestDict(dict): # pylint: disable=too-few-public-methods
"""
# keys should be strings
if not isinstance(key, basestring):
- raise TestDictError("Keys must be strings, but was {}".format(
- type(key)))
+ raise exceptions.PiglitFatalError(
+ "TestDict keys must be strings, but was {}".format(type(key)))
# Values should either be more Tests
if not isinstance(value, Test):
- raise TestDictError(
- "Values must be a Test, but was a {}".format(type(value)))
+ raise exceptions.PiglitFatalError(
+ "TestDict values must be a Test, but was a {}".format(
+ type(value)))
# This must be lowered before the following test, or the test can pass
# in error if the key has capitals in it.
@@ -103,7 +99,7 @@ class TestDict(dict): # pylint: disable=too-few-public-methods
else:
error = "and both tests are the same."
- raise TestDictError(
+ raise exceptions.PiglitFatalError(
"A test has already been asigned the name: {}\n{}".format(
key, error))
@@ -216,9 +212,8 @@ class TestProfile(object):
if check_all(item))
if not self.test_list:
- print('Error: There are no tests scheduled to run. Aborting run.',
- file=sys.stderr)
- sys.exit(1)
+ raise exceptions.PiglitFatalError(
+ 'There are no tests scheduled to run. Aborting run.')
def _pre_run_hook(self, opts):
""" Hook executed at the start of TestProfile.run
@@ -435,13 +430,9 @@ def load_test_profile(filename):
os.path.splitext(os.path.basename(filename))[0]))
return mod.profile
except AttributeError:
- print("Error: There is not profile attribute in module {0}."
- "Did you specify the right file?".format(filename),
- file=sys.stderr)
- sys.exit(2)
- except TestDictError as e:
- print("Error: {}".format(e.message), file=sys.stderr)
- sys.exit(1)
+ raise exceptions.PiglitFatalError(
+ 'There is not profile attribute in module {}.\n'
+ 'Did you specify the right file?'.format(filename))
def merge_test_profiles(profiles):
diff --git a/framework/tests/profile_tests.py b/framework/tests/profile_tests.py
index 3add41f..2488e7b 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -26,11 +26,8 @@ import copy
import nose.tools as nt
-import framework.core as core
-import framework.dmesg as dmesg
-import framework.profile as profile
from framework.tests import utils
-from framework import grouptools
+from framework import grouptools, core, dmesg, profile, exceptions
from framework.test import GleanTest
# Don't print sys.stderr to the console
@@ -43,7 +40,7 @@ def test_initialize_testprofile():
profile.TestProfile()
- at nt.raises(SystemExit)
+ at nt.raises(exceptions.PiglitFatalError)
def test_load_test_profile_no_profile():
"""profile.load_test_profile: Loading a module with no profile name exits
@@ -250,7 +247,7 @@ def test_testprofile_groupmanager_name_str():
nt.ok_(grouptools.join('foo', 'abc') in prof.test_list)
- at nt.raises(profile.TestDictError)
+ at nt.raises(exceptions.PiglitFatalError)
def test_testdict_key_not_string():
"""profile.TestDict: If key value isn't a string an exception is raised.
@@ -265,7 +262,7 @@ def test_testdict_key_not_string():
test[x] = utils.Test(['foo'])
- at nt.raises(profile.TestDictError)
+ at nt.raises(exceptions.PiglitFatalError)
def test_testdict_value_not_valid():
"""profile.TestDict: If the value isn't a Test an exception is raised.
@@ -278,7 +275,7 @@ def test_testdict_value_not_valid():
test['foo'] = x
- at nt.raises(profile.TestDictError)
+ at nt.raises(exceptions.PiglitFatalError)
def test_testdict_reassignment():
"""profile.TestDict: reassigning a key raises an exception"""
test = profile.TestDict()
@@ -286,7 +283,7 @@ def test_testdict_reassignment():
test['foo'] = utils.Test(['foo', 'bar'])
- at nt.raises(profile.TestDictError)
+ at nt.raises(exceptions.PiglitFatalError)
def test_testdict_reassignment_lower():
"""profile.TestDict: reassigning a key raises an exception (capitalization is ignored)"""
test = profile.TestDict()
--
2.4.0
More information about the Piglit
mailing list