def test__build(self): """ _build should - get the results of findBuilds, - set the version attribute of each Build, - call run() on each Build, - pass each Build.toDict through emit - wait on the Build's completion to send the finished build.toDict through emit. """ b = FileBuilder('foo') r = [Build()] # fake out Build.run() run_called = [] def fakerun(): run_called.append(True) r[0].run = fakerun # fake out findBuilds() b.findBuilds = lambda *ign: r # fake out emit() emit_called = [] b.emit = emit_called.append b._build(dict(version='version', project='foo', test_path='bar')) # version should be set on the Build self.assertEqual(r[0].version, 'version', "Should have set the version on the Build") self.assertEqual(run_called, [True], "Build.run() should have been called") self.assertEqual(emit_called, [r[0].toDict()], "Builder.emit() should have been called") # reset the fake emit_called.pop() # finish the build manually. r[0].done.callback(r[0]) self.assertEqual(emit_called, [r[0].toDict()], "When the build finishes, Builder.emit should be called")
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)