from teuthology.exceptions import ParseError
from teuthology.suite import build_matrix, combine_path
+
def main(args):
try:
describe_tests(args)
except ParseError:
sys.exit(1)
+
def describe_tests(args):
suite_dir = os.path.abspath(args["<suite_dir>"])
fields = args["--fields"].split(',')
output_results(headers, rows, output_format, hrule)
+
def output_results(headers, rows, output_format, hrule):
"""Write the headers and rows given in the specified output format to
stdout.
table.add_row(row)
print(table)
+
def get_combinations(suite_dir, fields, subset,
limit, filter_in, filter_out,
include_facet, _isdir=os.path.isdir, _open=open,
return headers, sorted([[row.get(field, '') for field in headers]
for row in rows])
+
def describe_suite(suite_dir, fields, include_facet, output_format):
"""Describe a suite listing each subdirectory and file once as a separate
row.
headers.append('facet')
return headers + fields, rows
+
def extract_info(file_name, fields, _isdir=os.path.isdir, _open=open):
"""Read a yaml file and return a dictionary mapping the fields to the
values of those fields in the file.
return {field: meta[0].get(field, '') for field in fields}
+
def path_relative_to_suites(path):
"""Attempt to trim the ceph-qa-suite root directory from the beginning
of a path.
except ValueError:
return path
+
def tree_with_info(cur_dir, fields, include_facet, prefix, rows,
_listdir=os.listdir, _isdir=os.path.isdir,
_open=open, output_format='plain'):
os.isdir() and os.isfile()
An example fake_filesystem value:
- >>> fake_fs = {
- 'a_directory': {
- 'another_directory': {
- 'empty_file': None,
- 'another_empty_file': None,
- },
- 'random_file': None,
- 'yet_another_directory': {
- 'empty_directory': {},
- },
- 'file_with_contents': 'data',
- },
+ >>> fake_fs = {\
+ 'a_directory': {\
+ 'another_directory': {\
+ 'empty_file': None,\
+ 'another_empty_file': None,\
+ },\
+ 'random_file': None,\
+ 'yet_another_directory': {\
+ 'empty_directory': {},\
+ },\
+ 'file_with_contents': 'data',\
+ },\
}
-
- >>> fake_listdir = make_fake_listdir(fake_fs)
+ >>> fake_listdir, fake_isfile, _, _ = \
+ make_fake_fstools(fake_fs)
>>> fake_listdir('a_directory/yet_another_directory')
['empty_directory']
>>> fake_isfile('a_directory/yet_another_directory')
rows = tree_with_info('basic', [], False, '', [],
self.fake_listdir, self.fake_isdir,
self.fake_open)
- assert rows == [ [x] for x in expected_tree]
+ assert rows == [[x] for x in expected_tree]
def test_single_filter(self):
rows = tree_with_info('basic', ['desc'], False, '', [],
expected_rbd_features,
expected_desc))
-
def test_multiple_filters_with_facets(self):
rows = tree_with_info('basic', ['desc', 'rbd_features'], True,
'', [], self.fake_listdir,
expected_desc))
def test_combinations_only_facets(self):
- headers, rows = get_combinations('basic', [], None, 1, None, None, True,
+ headers, rows = get_combinations('basic', [], None, 1, None,
+ None, True,
self.fake_isdir, self.fake_open,
- self.fake_isfile, self.fake_listdir)
+ self.fake_isfile,
+ self.fake_listdir)
self.assert_expected_combo_headers(headers)
assert rows == [['basic', 'install', 'fixed-1', 'rbd_api_tests']]
headers, rows = get_combinations('basic', ['desc', 'rbd_features'],
None, 1, None, None, False,
self.fake_isdir, self.fake_open,
- self.fake_isfile, self.fake_listdir)
+ self.fake_isfile,
+ self.fake_listdir)
assert headers == ['desc', 'rbd_features']
- assert rows == [['install ceph\nsingle node cluster\nc/c++ librbd api tests with default settings',
- 'default']]
+ descriptions = '\n'.join([
+ 'install ceph',
+ 'single node cluster',
+ 'c/c++ librbd api tests with default settings',
+ ])
+ assert rows == [[descriptions, 'default']]
def test_combinations_filter_in(self):
headers, rows = get_combinations('basic', [], None, 0, ['old_format'],
self.fake_isdir, self.fake_open,
self.fake_isfile, self.fake_listdir)
self.assert_expected_combo_headers(headers)
- assert rows == [['basic', 'install', 'fixed-1', 'rbd_api_tests_old_format']]
+ assert rows == [['basic', 'install', 'fixed-1',
+ 'rbd_api_tests_old_format']]
def test_combinations_filter_out(self):
headers, rows = get_combinations('basic', [], None, 0, None,
info = extract_info('a/b.yaml', ['foo', 'bar'], fake_isdir, fake_open)
assert info == {'foo': 'c', 'bar': ''}
+
def check_parse_error(fs):
_, _, fake_isdir, fake_open = make_fake_fstools(fs)
with pytest.raises(ParseError):
a = extract_info('a.yaml', ['a'], fake_isdir, fake_open)
raise Exception(str(a))
+
def test_extract_info_too_many_elements():
check_parse_error({'a.yaml': 'meta: [{a: b}, {b: c}]'})
+
def test_extract_info_not_a_list():
check_parse_error({'a.yaml': 'meta: {a: b}'})
+
def test_extract_info_not_a_dict():
check_parse_error({'a.yaml': 'meta: [[a, b]]'})
+
def test_extract_info_empty_file():
simple_fs = {'a.yaml': ''}
_, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)