Example #1
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'
Example #2
0
def test_buildscript(tmpdir, caplog):
    p13 = Proc()
    p13.props.template = TemplateLiquid
    p13._buildScript()
    assert 'No script specified' in caplog.text

    scriptfile = tmpdir / 'test_buildscript.txt'
    scriptfile.write_text('# script')
    p13.script = 'file:%s' % scriptfile
    fs.remove(scriptfile)
    with pytest.raises(ProcScriptError):
        p13._buildScript()

    scriptfile.write_text('''# script
	# PYPPL INDENT REMOVE
	abs
	bin
	# PYPPL INDENT KEEP
	callable
	def''')
    caplog.clear()
    p13.lang = 'python'
    p13._buildScript()
    assert 'Using template file: ' in caplog.text
    assert p13.script.render() == '''#!/usr/bin/env python
Example #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']
Example #4
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