From: Zack Cerza Date: Mon, 13 Apr 2015 22:17:40 +0000 (-0600) Subject: Parametrize build_matrix() for unit tests X-Git-Tag: 1.1.0~971^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=90126aeae6e70c05bc418f45d1065b82d37ea029;p=teuthology.git Parametrize build_matrix() for unit tests Signed-off-by: Zack Cerza --- diff --git a/teuthology/suite.py b/teuthology/suite.py index 3170b5285..e05314f8c 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -675,7 +675,8 @@ def combine_path(left, right): return left -def build_matrix(path): +def build_matrix(path, _isfile=os.path.isfile, _isdir=os.path.isdir, + _listdir=os.listdir): """ Return a list of items describe by path @@ -698,19 +699,27 @@ def build_matrix(path): like a relative path. If there was a % product, that path component will appear as a file with braces listing the selection of chosen subitems. + + :param path: The path to search for yaml fragments + :param _isfile: Custom os.path.isfile(); for testing only + :param _isdir: Custom os.path.isdir(); for testing only + :param _listdir: Custom os.listdir(); for testing only """ - if os.path.isfile(path): + if _isfile(path): if path.endswith('.yaml'): return [(None, [path])] return [] - if os.path.isdir(path): - files = sorted(os.listdir(path)) + if _isdir(path): + files = sorted(_listdir(path)) if '+' in files: # concatenate items files.remove('+') raw = [] for fn in files: - raw.extend(build_matrix(os.path.join(path, fn))) + raw.extend( + build_matrix(os.path.join(path, fn), + _isfile, _isdir, _listdir) + ) out = [( '{' + ' '.join(files) + '}', [a[1][0] for a in raw] @@ -721,7 +730,8 @@ def build_matrix(path): files.remove('%') sublists = [] for fn in files: - raw = build_matrix(os.path.join(path, fn)) + raw = build_matrix(os.path.join(path, fn), + _isfile, _isdir, _listdir) if raw: sublists.append([(combine_path(fn, item[0]), item[1]) for item in raw]) @@ -738,7 +748,8 @@ def build_matrix(path): # list items out = [] for fn in files: - raw = build_matrix(os.path.join(path, fn)) + raw = build_matrix(os.path.join(path, fn), + _isfile, _isdir, _listdir) out.extend([(combine_path(fn, item[0]), item[1]) for item in raw]) return out