]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
describe-tests: tolerate non-dict files
authorJosh Durgin <jdurgin@redhat.com>
Wed, 2 Dec 2015 08:08:00 +0000 (00:08 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Wed, 9 Dec 2015 21:04:54 +0000 (13:04 -0800)
Some yamls are empty to represent the absence of a setting, and parse
into None.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/describe_tests.py
teuthology/test/test_describe_tests.py

index 340d2fce0c129de05cf61f438f3b1d3f92c28c46..bae834f239648efc1bd59a86b3da641170126f40 100644 (file)
@@ -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
index 1fa44b8846ce2466dce37cc3baff8c1c52c9af44..aa8615d3e3d396d85e59b80da8f2d8a5f6c3afa4 100644 (file)
@@ -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 == {}