[Piglit] [PATCH] framework; Catch "No results found" exception
Brian Paul
brianp at vmware.com
Mon Mar 23 15:24:04 PDT 2015
Reviewed-by: Brian Paul <brianp at vmware.com>
On 03/23/2015 04:22 PM, Dylan Baker wrote:
> This adds a couple of catches for results not found and cleanly exits
> without a traceback when this is an expected error condition.
>
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
> framework/programs/summary.py | 12 ++++++++++--
> framework/results.py | 7 ++++++-
> framework/summary.py | 6 +++++-
> 3 files changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/framework/programs/summary.py b/framework/programs/summary.py
> index 8aaf709..b596fe9 100644
> --- a/framework/programs/summary.py
> +++ b/framework/programs/summary.py
> @@ -156,7 +156,11 @@ def csv(input_):
> help="JSON results file to be converted")
> args = parser.parse_args(input_)
>
> - testrun = framework.results.load_results(args.testResults)
> + try:
> + testrun = framework.results.load_results(args.testResults)
> + except framework.results.ResultsLoadError as e:
> + print('Error: {}'.format(e.message), file=sys.stderr)
> + sys.exit(1)
>
> def write_results(output):
> for name, result in testrun.tests.iteritems():
> @@ -186,7 +190,11 @@ def aggregate(input_):
> assert os.path.isdir(args.results_folder)
>
> outfile = os.path.join(args.results_folder, args.output)
> - results = framework.results.load_results(args.results_folder)
> + try:
> + results = framework.results.load_results(args.results_folder)
> + except framework.results.ResultsLoadError as e:
> + print('Error: {}'.format(e.message), file=sys.stderr)
> + sys.exit(1)
>
> try:
> results.write(outfile)
> diff --git a/framework/results.py b/framework/results.py
> index 3b8fc67..497c1c2 100644
> --- a/framework/results.py
> +++ b/framework/results.py
> @@ -36,12 +36,17 @@ from framework.backends import (CURRENT_JSON_VERSION, piglit_encoder,
> JSONBackend)
>
> __all__ = [
> + 'ResultsLoadError',
> 'TestrunResult',
> 'TestResult',
> 'load_results',
> ]
>
>
> +class ResultsLoadError(Exception):
> + pass
> +
> +
> class TestResult(dict):
> def recursive_update(self, dictionary):
> """ Recursively update the TestResult
> @@ -214,7 +219,7 @@ def load_results(filename):
> elif os.path.exists(os.path.join(filename, 'main')):
> filepath = os.path.join(filename, 'main')
> else:
> - raise Exception("No results found")
> + raise ResultsLoadError('No results found in "{}"'.format(filename))
>
> with open(filepath, 'r') as f:
> testrun = TestrunResult.load(f)
> diff --git a/framework/summary.py b/framework/summary.py
> index 848486a..d709870 100644
> --- a/framework/summary.py
> +++ b/framework/summary.py
> @@ -301,7 +301,11 @@ class Summary:
>
> # Create a Result object for each piglit result and append it to the
> # results list
> - self.results = [framework.results.load_results(i) for i in resultfiles]
> + try:
> + self.results = [framework.results.load_results(i) for i in resultfiles]
> + except framework.results.ResultsLoadError as e:
> + print('Error: {}'.format(e.message), file=sys.stderr)
> + sys.exit(1)
>
> self.status = {}
> self.fractions = {}
>
More information about the Piglit
mailing list