[v2,15/16] programs/run.py: use piglit exceptions

Submitted by Dylan Baker on May 18, 2015, 5:57 p.m.

Details

Message ID 1431971870-20138-16-git-send-email-baker.dylan.c@gmail.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Dylan Baker May 18, 2015, 5:57 p.m.
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@intel.com>
---
 framework/programs/run.py           | 15 ++++++---------
 framework/tests/run_parser_tests.py | 14 +++++++-------
 2 files changed, 13 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/framework/programs/run.py b/framework/programs/run.py
index f3b1963..69975fb 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'])