From: Josh Durgin Date: Wed, 2 Dec 2015 08:08:00 +0000 (-0800) Subject: describe-tests: tolerate non-dict files X-Git-Tag: 1.1.0~727^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7662c5bc14434f0759936fa6696b748d90556fe6;p=teuthology.git describe-tests: tolerate non-dict files Some yamls are empty to represent the absence of a setting, and parse into None. Signed-off-by: Josh Durgin --- diff --git a/teuthology/describe_tests.py b/teuthology/describe_tests.py index 340d2fce0..bae834f23 100644 --- a/teuthology/describe_tests.py +++ b/teuthology/describe_tests.py @@ -31,12 +31,16 @@ def main(args): print(table) def extract_info(file_name, fields, _isdir=os.path.isdir, _open=open): + empty_result = {f: '' for f in fields} if _isdir(file_name) or not file_name.endswith('.yaml'): - return {f: '' for f in fields} + return empty_result with _open(file_name, 'r') as f: parsed = yaml.load(f) + if not isinstance(parsed, dict): + return empty_result + description = parsed.get('description', [{}]) if not (isinstance(description, list) and len(description) == 1 and diff --git a/teuthology/test/test_describe_tests.py b/teuthology/test/test_describe_tests.py index 1fa44b884..aa8615d3e 100644 --- a/teuthology/test/test_describe_tests.py +++ b/teuthology/test/test_describe_tests.py @@ -214,3 +214,9 @@ def test_extract_info_not_a_list(): def test_extract_info_not_a_dict(): check_parse_error({'a.yaml': 'description: [[a, b]]'}) + +def test_extract_info_empty_file(): + simple_fs = {'a.yaml': ''} + _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs) + info = extract_info('a.yaml', [], fake_isdir, fake_open) + assert info == {}