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 <[email protected]> --- 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 d5d140c..ba37fa2 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 @@ -434,13 +429,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 95f8dda..bb179e7 100644 --- a/framework/tests/profile_tests.py +++ b/framework/tests/profile_tests.py @@ -28,11 +28,8 @@ import platform import nose.tools as nt from nose.plugins.skip import SkipTest -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 @@ -44,7 +41,7 @@ def test_initialize_testprofile(): profile.TestProfile() [email protected](SystemExit) [email protected](exceptions.PiglitFatalError) def test_load_test_profile_no_profile(): """ Loading a module with no profile name exits @@ -257,7 +254,7 @@ def test_testprofile_groupmanager_name_str(): nt.ok_(grouptools.join('foo', 'abc') in prof.test_list) [email protected](profile.TestDictError) [email protected](exceptions.PiglitFatalError) def test_testdict_key_not_string(): """TestDict: If key value isn't a string an exception is raised. @@ -272,7 +269,7 @@ def test_testdict_key_not_string(): test[x] = utils.Test(['foo']) [email protected](profile.TestDictError) [email protected](exceptions.PiglitFatalError) def test_testdict_value_not_valid(): """TestDict: If the value isn't a Tree, Test, or None an exception is raised. @@ -285,7 +282,7 @@ def test_testdict_value_not_valid(): test['foo'] = x [email protected](profile.TestDictError) [email protected](exceptions.PiglitFatalError) def test_testdict_reassignment(): """TestDict: reassigning a key raises an exception.""" test = profile.TestDict() @@ -293,7 +290,7 @@ def test_testdict_reassignment(): test['foo'] = utils.Test(['foo', 'bar']) [email protected](profile.TestDictError) [email protected](exceptions.PiglitFatalError) def test_testdict_reassignment_lower(): """TestDict: reassigning a key raises an exception (capitalization is ignored).""" test = profile.TestDict() -- 2.3.5 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
