Exemplo n.º 1
0
def test_hashing(tmpdir):
    def run(calcs, fmngr=None):
        with Session([fmngr] if fmngr else []) as sess:
            sess.run_task(calcs())
            fut = calcs().future_result()
            sess.eval(calcs())
            task = fut.resolve()[0][1].task
            output = task.resolve().resolve()['STDOUT']
            return task, output

    fmngr = FileManager(tmpdir)
    without_fmngr = run(calcs)
    with_fmngr = run(calcs, fmngr)
    with Session([fmngr]) as sess:
        task = dir_task(
            File.from_str('script', '#!/bin/bash\nexpr $(cat input) "*" 2; true'),
            [File.from_str('data', str(0)), [Path('input'), 'data']],
        )
        sess.run_task(task)
        alt_input = task, task.resolve().resolve()['STDOUT']
    alt_input = run(calcs2, fmngr)
    assert len(fmngr._cache) == 12
    assert len(list(Path(tmpdir).glob('*/*'))) == 12
    assert isinstance(without_fmngr[1], HashedFile)
    assert isinstance(with_fmngr[1], HashedFile)
    assert isinstance(alt_input[1], HashedFile)
    assert without_fmngr[0].hashid == with_fmngr[0].hashid
    assert without_fmngr[0].hashid == alt_input[0].hashid
    assert without_fmngr[1].hashid == with_fmngr[1].hashid
    assert without_fmngr[1].hashid == alt_input[1].hashid
Exemplo n.º 2
0
def test_alt_input2(datafile, tmpdir):
    with Session([FileManager(tmpdir)]) as sess:
        task = dir_task(
            File.from_str('script', '#!/bin/bash\nexpr $(cat input) "*" 2; true'),
            [File.from_path('data'), [Path('input'), 'data']],
        )
        assert int(sess.run_task(task).value['STDOUT'].read_text()) == 4
Exemplo n.º 3
0
def test_error(tmpdir):
    with Session([TmpdirManager(tmpdir)]) as sess:
        try:
            sess.eval(dir_task(File.from_str('script', '#!/bin/bash\nxxx'), []))
        except subprocess.CalledProcessError:
            pass
    assert len(list(Path(tmpdir).glob('*/*'))) == 3
Exemplo n.º 4
0
def python():
    return dir_task(
        File.from_str(
            'script',
            '#!/usr/bin/env python\nimport coverage\nprint(coverage.__name__)'
        ),
        [],
    )['STDOUT']
Exemplo n.º 5
0
def calcs():
    return [[
        dist,
        dir_task(
            File.from_str('script',
                          '#!/bin/bash\nexpr $(cat input) "*" 2; true'),
            [File.from_str('data', str(dist)), [Path('input'), 'data']],
            label=f'/calcs/dist={dist}',
        )['STDOUT'],
    ] for dist in range(5)]
Exemplo n.º 6
0
def calcs(n):
    return [[
        dist,
        dir_task(
            File.from_str('script',
                          f'#!/bin/bash\nexpr $(cat data) "*" 2; sleep {n}'),
            [File.from_str('data', str(dist))],
            label=f'/calcs/dist={dist}',
        )['STDOUT'],
    ] for dist in range(5)]
Exemplo n.º 7
0
def test_invalid_file():
    with pytest.raises(InvalidInput):
        with Session() as sess:
            sess.eval(dir_task('', {}))
Exemplo n.º 8
0
 def create_task():
     return dir_task(
         File.from_str('script', '#!/bin/bash\nexpr $(cat input) "*" 2; true'),
         [File.from_path('data'), [Path('input'), 'data']],
     )