matrix.generate_paths(path, output, combine_path)))
return ret
-def build_matrix(path, _isfile=os.path.isfile,
- _isdir=os.path.isdir,
- _listdir=os.listdir,
- subset=None):
+def build_matrix(path,
+ _exists=os.path.exists,
+ _isfile=os.path.isfile,
+ _isdir=os.path.isdir,
+ _listdir=os.listdir,
+ subset=None):
"""
Return a list of items descibed by path such that if the list of
items is chunked into mincyclicity pieces, each piece is still a
of chosen subitems.
:param path: The path to search for yaml fragments
+ :param _exists: Custom os.path.exists(); for testing only
: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
:param subset: (index, outof)
"""
mat, first, matlimit = _get_matrix(
- path, _isfile, _isdir, _listdir, subset)
+ path, _exists, _isfile, _isdir, _listdir, subset)
return generate_combinations(path, mat, first, matlimit)
-def _get_matrix(path, _isfile=os.path.isfile,
+def _get_matrix(path, _exists=os.path.exists, _isfile=os.path.isfile,
_isdir=os.path.isdir,
_listdir=os.listdir,
subset=None):
matlimit = None
if subset:
(index, outof) = subset
- mat = _build_matrix(path, _isfile, _isdir, _listdir, mincyclicity=outof)
+ mat = _build_matrix(path, _exists, _isfile, _isdir, _listdir, mincyclicity=outof)
first = (mat.size() / outof) * index
if index == outof or index == outof - 1:
matlimit = mat.size()
matlimit = (mat.size() / outof) * (index + 1)
else:
first = 0
- mat = _build_matrix(path, _isfile, _isdir, _listdir)
+ mat = _build_matrix(path, _exists, _isfile, _isdir, _listdir)
matlimit = mat.size()
return mat, first, matlimit
-def _build_matrix(path, _isfile=os.path.isfile,
+def _build_matrix(path, _exists=os.path.exists, _isfile=os.path.isfile,
_isdir=os.path.isdir, _listdir=os.listdir, mincyclicity=0, item=''):
- if not os.path.exists(path):
+ if not _exists(path):
raise IOError('%s does not exist' % path)
if _isfile(path):
if path.endswith('.yaml'):
for fn in sorted(files):
submat = _build_matrix(
os.path.join(path, fn),
+ _exists,
_isfile,
_isdir,
_listdir,
for fn in sorted(files):
submat = _build_matrix(
os.path.join(path, fn),
+ _exists,
_isfile,
_isdir,
_listdir,
for fn in sorted(files):
submat = _build_matrix(
os.path.join(path, fn),
+ _exists,
_isfile,
_isdir,
_listdir,
class TestDescribeTests(object):
def setup(self):
- self.fake_listdir, self.fake_isfile, self.fake_isdir, self.fake_open = \
- make_fake_fstools(realistic_fs)
+ self.fake_exists, self.fake_listdir, self.fake_isfile,
+ self.fake_isdir, self.fake_open = make_fake_fstools(realistic_fs)
@staticmethod
def assert_expected_combo_headers(headers):
def test_extract_info_dir():
simple_fs = {'a': {'b.yaml': 'meta: [{foo: c}]'}}
- _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
+ _, _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
info = extract_info('a', [], fake_isdir, fake_open)
assert info == {}
def check_parse_error(fs):
- _, _, fake_isdir, fake_open = make_fake_fstools(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_empty_file():
simple_fs = {'a.yaml': ''}
- _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
+ _, _, _, fake_isdir, fake_open = make_fake_fstools(simple_fs)
info = extract_info('a.yaml', [], fake_isdir, fake_open)
assert info == {}
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
fake_listdir)
assert len(result) == 1
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
fake_listdir)
assert len(result) == 4
assert self.fragment_occurences(result, 'd1_1_1.yaml') == 0.5
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
fake_listdir)
assert len(result) == 8
assert self.fragment_occurences(result, 'd1_2_0.yaml') == 0.5
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
fake_listdir)
assert len(result) == 8
assert self.fragment_occurences(result, 'd1_2_2.yaml') == 0.25
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('d0_0', fake_isfile, fake_isdir,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('d0_0', fake_exists, fake_isfile, fake_isdir,
fake_listdir)
assert len(result) == 2
for i in result:
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
fake_isdir, fake_listdir)
assert len(result) == 11
assert self.fragment_occurences(result, 'vps.yaml') == 1 / 11.0
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
fake_isdir, fake_listdir)
fake_fs2 = {
'teuthology': {
},
},
}
- fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
- result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2,
+ fake_exists2, fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
+ result2 = suite.build_matrix('teuthology/no-ceph', fake_exists2, fake_isfile2,
fake_isdir2, fake_listdir2)
assert len(result) == 11
assert len(result2) == len(result)
},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('teuthology/no-ceph', fake_isfile,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('teuthology/no-ceph', fake_exists, fake_isfile,
fake_isdir, fake_listdir)
fake_fs2 = {
'teuthology': {
},
},
}
- fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
- result2 = suite.build_matrix('teuthology/no-ceph', fake_isfile2,
+ fake_exists2, fake_listdir2, fake_isfile2, fake_isdir2, _ = make_fake_fstools(fake_fs2)
+ result2 = suite.build_matrix('teuthology/no-ceph', fake_exists2, fake_isfile2,
fake_isdir2, fake_listdir2)
assert len(result) == 11
assert len(result2) == len(result)
'tasks': {'cfuse_workunit_suites_fsstress.yaml': None},
},
}
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
- result = suite.build_matrix('thrash', fake_isfile,
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(fake_fs)
+ result = suite.build_matrix('thrash', fake_exists, fake_isfile,
fake_isdir, fake_listdir)
assert len(result) == 1
assert self.fragment_occurences(result, 'base.yaml') == 1
@staticmethod
def generate_description_list(tree, subset):
- fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree)
+ fake_exists, fake_listdir, fake_isfile, fake_isdir, _ = make_fake_fstools(tree)
mat, first, matlimit = suite._get_matrix(
- 'root', _isfile=fake_isfile, _isdir=fake_isdir,
+ 'root', _exists=fake_exists, _isfile=fake_isfile, _isdir=fake_isdir,
_listdir=fake_listdir, subset=subset)
return [i[0] for i in suite.generate_combinations(
'root', mat, first, matlimit)], mat, first, matlimit