[Piglit] [PATCH 15/16] programs/run.py: use piglit exceptions

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


Use an exception rather than passing booleans. This removes a bunch of
biolerplate code and makes things easier.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/programs/run.py           | 15 ++++++---------
 framework/tests/run_parser_tests.py | 14 +++++++-------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index 3f3c268..c7eb201 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -59,10 +59,9 @@ def _default_platform():
         try:
             plat = core.PIGLIT_CONFIG.get('core', 'platform')
             if plat not in core.PLATFORMS:
-                print('Platform is not valid\n'
-                      'valid platforms are: {}'.format(core.PLATFORMS),
-                      file=sys.stderr)
-                sys.exit(1)
+                raise exceptions.PiglitFatalError(
+                    'Platform is not valid\nvalid platforms are: {}'.format(
+                        core.PLATFORMS))
             return plat
         except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
             return 'mixed_glx_egl'
@@ -78,11 +77,9 @@ def _default_backend():
     try:
         backend = core.PIGLIT_CONFIG.get('core', 'backend')
         if backend not in backends.BACKENDS.keys():
-            print('Backend is not valid\n',
-                  'valid backends are: {}'.format(
-                      ' '.join(backends.BACKENDS.keys())),
-                  file=sys.stderr)
-            sys.exit(1)
+            raise exceptions.PiglitFatalError(
+                'Backend is not valid\nvalid backends are: {}'.format(
+                      ' '.join(backends.BACKENDS.keys())))
         return backend
     except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
         return 'json'
diff --git a/framework/tests/run_parser_tests.py b/framework/tests/run_parser_tests.py
index 77f60bb..cddaa58 100644
--- a/framework/tests/run_parser_tests.py
+++ b/framework/tests/run_parser_tests.py
@@ -28,9 +28,9 @@ import ConfigParser
 
 import nose.tools as nt
 
+from framework import core, exceptions
 import framework.tests.utils as utils
 import framework.programs.run as run
-import framework.core as core
 
 
 class TestWithEnvClean(object):
@@ -151,6 +151,7 @@ class TestBackend(_Helpers):
             args = run._run_parser(['quick.py', 'foo'])
             nt.assert_equal(args.backend, 'junit')
 
+    @nt.raises(exceptions.PiglitFatalError)
     def test_bad_value_in_conf(self):
         """ run parser: an error is raised when the platform in conf is bad """
         self._unset_config()
@@ -165,9 +166,8 @@ class TestBackend(_Helpers):
             with open(os.path.join(tdir, 'piglit.conf'), 'w') as f:
                 f.write('[core]\nbackend=foobar')
 
-            with nt.assert_raises(SystemExit):
-                run._run_parser(['-f', os.path.join(tdir, 'piglit.conf'),
-                                 'quick.py', 'foo'])
+            run._run_parser(['-f', os.path.join(tdir, 'piglit.conf'),
+                             'quick.py', 'foo'])
 
 
 class TestPlatform(_Helpers):
@@ -244,6 +244,7 @@ class TestPlatform(_Helpers):
             args = run._run_parser(['quick.py', 'foo'])
             nt.assert_equal(args.platform, 'glx')
 
+    @nt.raises(exceptions.PiglitFatalError)
     def test_bad_value_in_conf(self):
         """ run parser: an error is raised when the platform in conf is bad """
         self._unset_config()
@@ -258,6 +259,5 @@ class TestPlatform(_Helpers):
             with open(os.path.join(tdir, 'piglit.conf'), 'w') as f:
                 f.write('[core]\nplatform=foobar')
 
-            with nt.assert_raises(SystemExit):
-                run._run_parser(['-f', os.path.join(tdir, 'piglit.conf'),
-                                 'quick.py', 'foo'])
+            run._run_parser(['-f', os.path.join(tdir, 'piglit.conf'),
+                             'quick.py', 'foo'])
-- 
2.3.5



More information about the Piglit mailing list