Merge lp:~javier.collado/utah/bug1055802 into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 707
Merged at revision: 718
Proposed branch: lp:~javier.collado/utah/bug1055802
Merge into: lp:utah
Diff against target: 89 lines (+24/-4)
4 files modified
utah/client/common.py (+6/-1)
utah/client/exceptions.py (+8/-1)
utah/client/runner.py (+5/-1)
utah/client/testsuite.py (+5/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1055802
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+128999@code.launchpad.net

Description of the change

This branch adds a new exception to detect when a yaml file is empty.

This exception is caught when parsing the ts_control file, to allow empty files.

The case for the file not being there at all was already covered.

I think that the testsuite module needs some refactoring. In particular, I found confusing what's
the _control data variable used for and why None is used as default value when an empty dictionary
could be more appropriate since that would remove the need to handle special cases.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'utah/client/common.py'
--- utah/client/common.py 2012-10-10 14:44:00 +0000
+++ utah/client/common.py 2012-10-10 17:25:23 +0000
@@ -15,7 +15,10 @@
15import yaml15import yaml
16import jsonschema16import jsonschema
1717
18from utah.client.exceptions import YAMLParsingError18from utah.client.exceptions import (
19 YAMLParsingError,
20 YAMLEmptyFile,
21 )
1922
2023
21PASS = 024PASS = 0
@@ -167,6 +170,8 @@
167 try:170 try:
168 with open(filename, 'r') as fp:171 with open(filename, 'r') as fp:
169 data = yaml.load(fp)172 data = yaml.load(fp)
173 if data is None:
174 raise YAMLEmptyFile('Empty YAML file: {}'.format(filename))
170 except yaml.YAMLError as exception:175 except yaml.YAMLError as exception:
171 if hasattr(exception, 'problem_mark'):176 if hasattr(exception, 'problem_mark'):
172 mark = exception.problem_mark177 mark = exception.problem_mark
173178
=== modified file 'utah/client/exceptions.py'
--- utah/client/exceptions.py 2012-10-04 15:39:50 +0000
+++ utah/client/exceptions.py 2012-10-10 17:25:23 +0000
@@ -31,11 +31,18 @@
3131
32class YAMLParsingError(UTAHClientError):32class YAMLParsingError(UTAHClientError):
33 """33 """
34 Used to provided the filename and the location34 Used to provide the filename and the location
35 in which the parsing error happened when calling yaml.load35 in which the parsing error happened when calling yaml.load
36 """36 """
3737
3838
39class YAMLEmptyFile(UTAHClientError):
40 """
41 Used to signal that a file that was supposed to contain yaml data
42 is actually empty
43 """
44
45
39class ValidationError(UTAHClientError):46class ValidationError(UTAHClientError):
40 """47 """
41 Used to provide additional information when schema validation fails48 Used to provide additional information when schema validation fails
4249
=== modified file 'utah/client/runner.py'
--- utah/client/runner.py 2012-10-10 14:44:00 +0000
+++ utah/client/runner.py 2012-10-10 17:25:23 +0000
@@ -424,7 +424,11 @@
424 # Fetch the testsuite. On resume don't remove the testsuite424 # Fetch the testsuite. On resume don't remove the testsuite
425 # directory.425 # directory.
426 if not resume and os.path.exists(name):426 if not resume and os.path.exists(name):
427 shutil.rmtree(name)427 # Using absolute name makes no difference
428 # except on failures where it's easier
429 # to find troubleshoot permission problems
430 absolute_name = os.path.abspath(name)
431 shutil.rmtree(absolute_name)
428 if not os.path.exists(name):432 if not os.path.exists(name):
429 os.mkdir(name)433 os.mkdir(name)
430434
431435
=== modified file 'utah/client/testsuite.py'
--- utah/client/testsuite.py 2012-08-28 11:22:41 +0000
+++ utah/client/testsuite.py 2012-10-10 17:25:23 +0000
@@ -11,7 +11,7 @@
11from .common import CMD_TS_BUILD, CMD_TS_SETUP, CMD_TS_CLEANUP11from .common import CMD_TS_BUILD, CMD_TS_SETUP, CMD_TS_CLEANUP
12from .common import do_nothing12from .common import do_nothing
13from .testcase import TestCase13from .testcase import TestCase
14from .exceptions import MissingFile, ValidationError14from .exceptions import MissingFile, ValidationError, YAMLEmptyFile
1515
1616
17def parse_runlist_file(runlist_file):17def parse_runlist_file(runlist_file):
@@ -111,6 +111,10 @@
111 try:111 try:
112 control_data = parse_control_file(self.control_file,112 control_data = parse_control_file(self.control_file,
113 self.CONTROL_SCHEMA)113 self.CONTROL_SCHEMA)
114 except YAMLEmptyFile:
115 # Skip schema validation for empty file
116 # Schema allows an empty dictionary, but not None
117 control_data = None
114 except jsonschema.ValidationError as exception:118 except jsonschema.ValidationError as exception:
115 raise ValidationError(119 raise ValidationError(
116 '{!r} test suite control file invalid: {!r}\n'120 '{!r} test suite control file invalid: {!r}\n'

Subscribers

People subscribed via source and target branches