def test_getChildFiles_dir(self): """ Given a directory, return all children files. """ root = FilePath(self.mktemp()) dir1 = root.child('dir1') dir2 = dir1.child('dir2') dir2.makedirs() f1 = root.child('f1') f2 = dir1.child('f2') f3 = dir2.child('f3') f1.setContent('foo') f2.setContent('foo') f3.setContent('foo') b = FileBuilder() r = b._getChildFiles(root) self.assertEqual(set(r), set([f1, f2, f3]), "Should find all files that are descendants") r = b._getChildFiles(dir1) self.assertEqual(set(r), set([f2, f3]))
def test_getChildFiles_file(self): """ Given a file, return the file """ root = FilePath(self.mktemp()) root.setContent('something') b = FileBuilder() r = list(b._getChildFiles(root)) self.assertEqual(r, [root])
def test_findBuilds(self): """ It should call a few functions, passing their results around, ending up with FileBuild instances with the correct properties set. """ root = FilePath(self.mktemp()) # project/ project = root.child('project') project.makedirs() # project/foo foo = project.child('foo') # project/bar bar = project.child('bar') foo.setContent('foo') bar.setContent('bar') b = FileBuilder(root) class Spy: def __init__(self, func): self.func = func self.called = [] def __call__(self, *args): self.called.append(args) return self.func(*args) b._findHeads = Spy(b._findHeads) b._getChildFiles = Spy(b._getChildFiles) r = list(b.findBuilds('project', '*')) self.assertTrue(b._findHeads.called) self.assertTrue(('project', '*') in b._findHeads.called) self.assertEqual(len(b._getChildFiles.called), 2) expected = set([ ('project', 'foo', b, foo), ('project', 'bar', b, bar), ]) actual = [(x.project, x.test_path, x.builder, x._filepath) for x in r] self.assertEqual(expected, set(actual)) self.assertEqual(len(r), 2)