Beispiel #1
0
def test_preruntidy(tmpdir, caplog):
    p20 = Proc()
    p20.input = 'a, b'
    p20.input = [(1, 2), (3, 4), (5, 6)]
    p20.callfront = lambda p: setattr(p, 'forks', 20)
    p20._preRunTidy()
    assert 'Calling callfront ...' in caplog.text
    assert p20.forks == 20
    assert p20.size == 3
Beispiel #2
0
def test_suffix_input(tmpdir):
    p82 = Proc()
    p82.input = 'a'
    p82.input = [1]
    sigs = OBox()
    sigs.argv0 = str(Path(sys.argv[0]).resolve())
    sigs.id = 'p82'
    sigs.tag = 'notag'
    assert p82.config.input == {'a': [1]}
    sigs.input = {'a': "[1]"}
    assert p82.suffix == uid(sigs.to_json())
Beispiel #3
0
def test_runjobs(tmpdir):
    p21 = Proc()
    p21.forks = 3
    p21.input = 'a, b'
    p21.input = [(1, 2), (3, 4), (5, 6)]
    p21.output = 'a:{{i.a}}, b:{{i.b}}'
    p21.script = 'echo Hello world!'
    p21._preRunTidy()
    p21._runJobs()
    assert p21.channel == [('1', '2'), ('3', '4'), ('5', '6')]
    assert p21.channel.a.flatten() == ['1', '3', '5']
    assert p21.channel.b.flatten() == ['2', '4', '6']
Beispiel #4
0
def test_proc_setattr(tmpdir, caplog):
    p3 = Proc()
    with pytest.raises(ProcAttributeError):
        p3.x = 1
    p3.preCmd = 'ls'
    assert 'beforeCmd' in p3.sets

    p4 = Proc()
    ps = ProcSet(p4)
    p3.depends = p4
    assert p3.depends == [p4]
    p3.depends = [p4], ps
    assert p3.depends == [p4, ps.p4]
    assert p4.tag == 'notag'
    assert ps.p4.tag == 'notag@ps'

    with pytest.raises(ProcAttributeError):
        p3.depends = p3

    with pytest.raises(ProcAttributeError):
        p3.depends = object()

    p3.script = 'file:%s' % Path(__file__).name
    assert p3.config.script == 'file:%s' % Path(__file__).resolve()

    p31 = Proc(script='file:%s' % Path(__file__).name)
    assert p31.config.script == 'file:%s' % Path(__file__).resolve()

    with pytest.raises(ProcAttributeError):
        p3.script = 'file:nosuchfile'

    p3.args = {'a': 1}
    assert p3.args.a == 1

    p3.input = 'a, b'
    p3.input = [1, 2]
    assert p3.config.input == {'a, b': [1, 2]}

    p3.input = {'a': [1], 'b': [2]}
    caplog.clear()
    p3.input = [3, 4]
    assert 'Previous input is a dict with multiple keys and key order may be changed.' in caplog.text
    assert 'Now the key order is:' in caplog.text

    p3.runner = 'sge'
    assert p3.config.runner == 'sge'
    assert p3.props.runner == 'sge'

    with pytest.raises(ProcAttributeError):
        p3.tag = 'a@b'
Beispiel #5
0
def test_buildinput(tmpdir, caplog):
    p10 = Proc()
    p10.input = 'a, b:file, '
    p10.input = ('1', 'infile')
    p10._buildInput()
    assert len(p10.input) == 2
    assert p10.input['a'] == ('var', ['1'])
    assert p10.input['b'] == ('file', ['infile'])
    assert p10.size == 1

    p10.input = 'a:x:y'
    with pytest.raises(ProcInputError):
        p10._buildInput()

    p101 = Proc()
    p101.props.channel = Channel.create([(1, 3), (2, 4)])
    p10.depends = p101
    p10.input = 'a, b, c'
    p10.input = lambda ch: ch.cbind(1).cbind(2)
    caplog.clear()
    p10._buildInput()
    assert 'Not all data are used as input' in caplog.text
    assert len(p10.input) == 3
    assert p10.size == 2
    assert p10.input['a'] == ('var', [1, 2])
    assert p10.input['b'] == ('var', [3, 4])
    assert p10.input['c'] == ('var', [1, 1])

    p10.input = 'a:files, b:files, c'
    p10.input = Channel.create([['infile1'], ['infile2']])
    p10._buildInput()
    assert 'No data found for input key "b"' in caplog.text
    assert 'No data found for input key "c"' in caplog.text
    caplog.clear()
    assert len(p10.input) == 3
    assert p10.size == 2
    assert p10.input['a'] == ('files', [['infile1'], ['infile2']])
    assert p10.input['b'] == ('files', [[], []])
    assert p10.input['c'] == ('var', ['', ''])

    p10.props.template = TemplateLiquid
    p10.props.workdir = tmpdir / 'test_buildinput_p10'
    p10.resume = 'resume'
    fs.remove(Path(p10.workdir) / 'proc.settings.yaml')
    with pytest.raises(ProcInputError):
        p10._buildInput()
    fs.mkdir(p10.workdir)

    p10.props.input = OBox()
    p10.input['a'] = ('files', [['infile1'], ['infile2']])
    p10.input['b'] = ('files', [[], []])
    p10.input['c'] = ('var', ['', ''])
    p10._saveSettings()
    p10.props.input = None
    p10._buildInput()
    assert len(p10.input) == 3
    assert p10.size == 2
    assert p10.input['a'] == ('files', [['infile1'], ['infile2']])
    assert p10.input['b'] == ('files', [[], []])
    assert p10.input['c'] == ('var', ['', ''])
Beispiel #6
0
def test_suffix_compute(tmpdir):
    p76 = Proc()
    p81 = Proc()
    p81.depends = p76
    p81.input = 'a'
    sigs = OBox()
    sigs.argv0 = str(Path(sys.argv[0]).resolve())
    sigs.id = 'p81'
    sigs.tag = 'notag'
    sigs.input = 'a'
    sigs.depends = ['p76#' + p76.suffix]
    assert p81.suffix == uid(sigs.to_json())
Beispiel #7
0
def test_postruntidy(tmpdir, caplog):
    p22 = Proc()
    p22.resume = 'skip+'
    p22.callback = lambda p: p.props.update({'channel': p.channel.cbind(1, 2)})
    p22._postRunTidy()
    assert p22.channel == [(1, 2)]

    p23 = Proc()
    p23.forks = 5
    p23.input = 'a, b'
    p23.input = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
    p23.output = 'a:{{i.a}}, b:{{i.b}}'
    p23.script = 'echo Hello world!'
    p23.errhow = 'ignore'
    p23.callback = lambda p: setattr(p, 'forks', 10)
    p23._preRunTidy()
    p23._runJobs()
    p23.jobs[0].state = STATES.BUILTFAILED
    p23.jobs[1].state = STATES.SUBMITFAILED
    p23.jobs[2].state = STATES.DONE
    p23.jobs[3].state = STATES.DONECACHED
    p23.jobs[4].state = STATES.ENDFAILED
    p23._postRunTidy()
    assert ' Jobs (Cached: 1, Succ: 1, B.Fail: 1, S.Fail: 1, R.Fail: 1)' in caplog.text
    assert 'Failed but ignored (totally 3).' in caplog.text
    assert p23.forks == 10

    p23.errhow = 'terminate'
    caplog.clear()
    with pytest.raises(SystemExit):
        p23._postRunTidy()
    assert 'Cached: 4' in caplog.text
    assert 'Succeeded: 3' in caplog.text
    assert 'Building failed: 1' in caplog.text
    assert 'Submission failed: 2' in caplog.text
    assert 'Running failed: 5' in caplog.text