[Piglit] [PATCH 05/14] core.py: use PiglitFatalError instead of sys.exit

Dylan Baker dylan at pnwbakers.com
Fri May 6 20:07:15 UTC 2016


From: Dylan Baker <baker.dylan.c at gmail.com>

This is cleaner and more in keeping with the style of piglit.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/core.py       | 7 +++----
 unittests/core_tests.py | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index aa21df5..a75e598 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -28,7 +28,6 @@ from __future__ import (
 import errno
 import os
 import subprocess
-import sys
 
 from six.moves import configparser
 
@@ -121,9 +120,9 @@ def checkDir(dirname, failifexists):
         os.stat(dirname)
     except OSError as e:
         if e.errno not in [errno.ENOENT, errno.ENOTDIR] and failifexists:
-            print("%(dirname)s exists already.\nUse --overwrite if "
-                  "you want to overwrite it.\n" % locals(), file=sys.stderr)
-            exit(1)
+            raise exceptions.PiglitFatalError(
+                "%(dirname)s exists already.\nUse --overwrite if "
+                "you want to overwrite it.\n" % locals())
 
     try:
         if not os.path.exists(dirname):
diff --git a/unittests/core_tests.py b/unittests/core_tests.py
index 4b05721..043440b 100644
--- a/unittests/core_tests.py
+++ b/unittests/core_tests.py
@@ -278,7 +278,7 @@ class TestPiglitConfig(object):
 
 
 @utils.capture_stderr
- at nt.raises(SystemExit)
+ at nt.raises(exceptions.PiglitFatalError)
 def test_check_dir_exists_fail():
     """core.check_dir: if the directory exists and failifexsits is True fail"""
     with mock.patch('framework.core.os.stat', mock.Mock(side_effect=OSError)):
-- 
2.8.2



More information about the Piglit mailing list