[Piglit] [PATCH 06/14] framework: core.checkDir raises PiglitException
Dylan Baker
dylan at pnwbakers.com
Fri May 6 20:07:16 UTC 2016
From: Dylan Baker <baker.dylan.c at gmail.com>
This requires each caller that sets failifexists=True to handle the
error, but it allows them to set a custom message or handle the failure
themselves, rather than just bailing. This makes the function more
generically useful, and removes a layering violation.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/core.py | 4 +---
framework/programs/summary.py | 8 +++++++-
unittests/core_tests.py | 2 +-
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index a75e598..d052bd5 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -120,9 +120,7 @@ def checkDir(dirname, failifexists):
os.stat(dirname)
except OSError as e:
if e.errno not in [errno.ENOENT, errno.ENOTDIR] and failifexists:
- raise exceptions.PiglitFatalError(
- "%(dirname)s exists already.\nUse --overwrite if "
- "you want to overwrite it.\n" % locals())
+ raise exceptions.PiglitException
try:
if not os.path.exists(dirname):
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index b42675f..13368e4 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -101,7 +101,13 @@ def html(input_):
shutil.rmtree(args.summaryDir)
# If the requested directory doesn't exist, create it or throw an error
- core.checkDir(args.summaryDir, not args.overwrite)
+ try:
+ core.checkDir(args.summaryDir, not args.overwrite)
+ except exceptions.PiglitException:
+ raise exceptions.PiglitFatalError(
+ '{} already exists.\n'
+ 'use -o/--overwrite if you want to overwrite it.'.format(
+ args.summaryDir))
# Merge args.list and args.resultsFiles
if args.list:
diff --git a/unittests/core_tests.py b/unittests/core_tests.py
index 043440b..e152336 100644
--- a/unittests/core_tests.py
+++ b/unittests/core_tests.py
@@ -278,7 +278,7 @@ class TestPiglitConfig(object):
@utils.capture_stderr
- at nt.raises(exceptions.PiglitFatalError)
+ at nt.raises(exceptions.PiglitException)
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