def run_all_combos(self, dirs): tests = list(self.generate_tests(dirs)) deepest = max(len(t['relpath'].split(os.sep)) - 1 for t in tests) for depth in range(1, deepest + 1): def num_groups(tests): unique = set() for p in [t['relpath'] for t in tests]: p = p.split(os.sep) p = p[:min(depth, len(p) - 1)] unique.add(os.sep.join(p)) return len(unique) for total in range(1, num_groups(tests) + 1): res = [] for this in range(1, total + 1): f = chunk_by_dir(this, total, depth) res.append(list(f(tests, {}))) lengths = map(num_groups, res) # the chunk with the most dirs should have at most one more # dir than the chunk with the least dirs self.assertLessEqual(max(lengths) - min(lengths), 1) all_chunks = list(chain.from_iterable(res)) # chunk_by_dir will mess up order, but chained chunks should # contain all of the original tests and be the same length self.assertEqual(len(all_chunks), len(tests)) for t in tests: self.assertIn(t, all_chunks)
def test_chunk_by_dir(self): chunk = chunk_by_dir(1, 1, 1) self.assertEqual(list(chunk([], {})), []) dirs = { 'a': 2, } self.run_all_combos(dirs) dirs = { '': 1, 'foo': 1, 'bar': 0, '/foobar': 1, } self.run_all_combos(dirs) dirs = { 'a': 1, 'b': 1, 'a/b': 2, 'a/c': 1, } self.run_all_combos(dirs) dirs = { 'a': 5, 'a/b': 4, 'a/b/c': 7, 'a/b/c/d': 1, 'a/b/c/e': 3, 'b/c': 2, 'b/d': 5, 'b/d/e': 6, 'c': 8, 'c/d/e/f/g/h/i/j/k/l': 5, 'c/d/e/f/g/i/j/k/l/m/n': 2, 'c/e': 1, } self.run_all_combos(dirs)
def test_chunk_by_dir(self): chunk = chunk_by_dir(1, 1, 1) self.assertEqual(list(chunk([], {})), []) dirs = { "a": 2, } self.run_all_combos(dirs) dirs = { "": 1, "foo": 1, "bar": 0, "/foobar": 1, } self.run_all_combos(dirs) dirs = { "a": 1, "b": 1, "a/b": 2, "a/c": 1, } self.run_all_combos(dirs) dirs = { "a": 5, "a/b": 4, "a/b/c": 7, "a/b/c/d": 1, "a/b/c/e": 3, "b/c": 2, "b/d": 5, "b/d/e": 6, "c": 8, "c/d/e/f/g/h/i/j/k/l": 5, "c/d/e/f/g/i/j/k/l/m/n": 2, "c/e": 1, } self.run_all_combos(dirs)