def test_composite(): """Test the workflow of faber.artefacts.binary""" src = rule(fileutils.touch, 'src') bin = artefact('bin') def assemble(targets, sources): obj = rule(fileutils.copy, 'obj', src, attrs=intermediate, module=targets[0].module) rule(fileutils.copy, bin, obj, attrs=intermediate, module=targets[0].module) def test(targets, sources): print('testing {}'.format(sources[0].name)) assert exists(sources[0]._filename) # make a dependency graph ass = rule(assemble, 'ass', attrs=notfile | always) # make a binary depend(bin, ass) # and test it test = rule(test, 'test', bin, attrs=notfile) with patch('faber.scheduler._report_recipe') as recipe: scheduler.update([test]) (_, _, status, _, _, output, _), kwds = recipe.call_args_list[-1] assert output == 'testing bin\n' assert status == 0
def test_composite(): """Test the workflow of faber.config.try_compile""" src = rule(fileutils.touch, 'src', attrs=intermediate | always) obj = artefact('obj', attrs=intermediate) check = artefact('check', attrs=notfile) def assemble(targets, sources): rule(fileutils.copy, obj, src, attrs=intermediate, module=targets[0].module) # make a dependency graph ass = rule(assemble, 'ass', attrs=notfile | always) # make a binary depend(obj, dependencies=ass) # and test it check = alias(check, obj) with patch('faber.action.action.__status__') as recipe: scheduler.update([check]) (_, status, _, _, _, _), kwds = recipe.call_args_list[-1] assert recipe.call_count == 3 assert status is True
def test_late(): """Test that a "late" dependency raises an error.""" a = artefact('a', attrs=notfile | always) assert scheduler.update(a) with pytest.raises(scheduler.DependencyError): b = artefact('b', attrs=notfile) depend(a, b)
def test_dynamic_recipe(): """Test whether it's possible to add a recipe while the scheduler is already running.""" c = artefact('c', attrs=notfile) def generate(*args, **kwds): """generate the graph for c.""" a = rule(pyecho, 'a', attrs=notfile | always) a1 = rule(pyecho, 'a1', a, attrs=notfile | always) a2 = rule(pyecho, 'a2', a1, attrs=notfile | always) rule( pyecho, c, a2, ) b = rule(generate, 'b', attrs=notfile | always) depend(c, b) with patch('faber.scheduler._report_recipe') as recipe: assert scheduler.update(c) output = [i[0][5].strip() for i in recipe.call_args_list] assert output[-1] == 'c <- a2'
def inject_deps(self, *args, **kwds): d = rule(pyecho, 'd', attrs=notfile | always) depend(c, d) print('ddeps.b')
def generator(targets, sources): depend(b, c) # create cycle !
def __status__(self, status): artefact.__status__(self, status) self.prereq.features.eval() if self.cond(self.prereq.features): depend(self.dep, [self.prereq])