Beispiel #1
0
def test_multi():
    """TBD"""

    # workflow:
    # b1 needs to be updated, but doing that also updates b2
    # this means c2 (dependent on b2) will also be updated.
    a = artefact('a', attrs=notfile)
    b1 = artefact('b1', attrs=notfile)
    b2 = artefact('b2', attrs=notfile | always)
    c1 = artefact('c1', attrs=notfile)
    c2 = artefact('c2', attrs=notfile)
    d = artefact('d', attrs=notfile)
    rule(pyecho, a)
    rule(pyecho, [b1, b2], a)
    rule(pyecho, c1, b1)
    rule(pyecho, c2, b2)
    rule(pyecho, d, [c1, c2])
    with patch('faber.action.action.__status__') as recipe:
        assert d.update()
        output = [i[0][3].strip() for i in recipe.call_args_list]
        assert output[0] == 'b1 b2 <- a'
        assert 'c2 <- b2' in output
        # sets aren't ordered, so we check for both possibilities
        assert output[-1] in ('d <- c1 c2', 'd <- c2 c1')
Beispiel #2
0
def test_compound():
    """Compound a command and a Python function into a single action."""
    class C(action):

        touch = fileutils.touch

        @staticmethod
        def command(targets, sources):
            f = targets[0]._filename
            if C.touch(targets, sources) and exists(f):
                with open(f, 'w') as out:
                    out.write('something')

    a = rule(C(), 'a')
    a.update()
    with open(a._filename, 'r') as f:
        assert f.readlines() == ['something']
Beispiel #3
0
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'
Beispiel #4
0
def test_installation(stage, prefix):
    """Install a (source) file, directory, as well as a generated
    file, using different stage and prefix settings."""

    srcdir = module.current.srcdir
    filename = 'file'
    with open(join(srcdir, filename), 'w') as o:
        o.write('something')
    dirname = 'directory'
    mkdir(join(srcdir, dirname))

    assert exists(join(srcdir, filename))
    assert exists(join(srcdir, dirname))

    fs = set()
    if prefix is not None:
        fs += install.prefix(prefix, base='')
    if stage is not None:
        stage = join(module.current.builddir, stage)
        fs += install.stage(stage, base='')
    a = install.installed(rule(fileutils.touch, 'empty-file'),
                          'bin',
                          features=fs)
    b = install.installed(filename, 'src', features=fs)
    c = install.installed(dirname, 'src', features=fs)
    i = install.installation('install', [a, b, c], features=fs)
    assert scheduler.update(i)
    manifest = [
        relpath(stage, f.strip())
        for f in open(i.manifest._filename).readlines()
    ]
    print('manifest:', manifest)
    assert len(manifest) == 3
    for f in [a, b, c]:
        print(f._filename)
    for f in manifest:
        assert exists(f)
Beispiel #5
0
 def inject_deps(self, *args, **kwds):
     d = rule(pyecho, 'd', attrs=notfile | always)
     depend(c, d)
     print('ddeps.b')
Beispiel #6
0
 def assemble(targets, sources):
     rule(fileutils.copy,
          obj,
          src,
          attrs=intermediate,
          module=targets[0].module)