def test_proxy(): p = Proxy([1, 2, 3, 4, 1]) assert p.count(1) == 2 assert p.denominator == [1] * 5 p1 = Proxy([Diot(), Diot(), Diot()]) p1.x = Values(1, 2) assert p1[0].x == 1 assert p1[1].x == 2 assert 'x' not in p1[2] p1.y = 3 assert p1[0].y == 3 assert p1[1].y == 3 assert p1[2].y == 3 p2 = p1[:2] assert len(p2) == 2 assert p2[0] is p1[0] assert p2[1] is p1[1] assert p1['y'] == [3, 3, 3] p2[0] = Diot(a=1) assert p2[0].a == 1 p2['y'] = 1 assert p2['y'] == [1, 1]
def test_ssh_init_nolive(proc, ssh): proc.sshRunner = Diot(ssh=ssh, servers=['a', 'b', 'c', 'd'], keys=['server1', 'server2', 'server3', 'wrongkey'], checkAlive=True) with pytest.raises(RunnerSshError): RunnerSsh(0, proc)
def slurm(): return Diot( sbatch=str(Path(__file__).parent / 'mocks' / 'sbatch'), srun=str(Path(__file__).parent / 'mocks' / 'srun'), squeue=str(Path(__file__).parent / 'mocks' / 'squeue'), scancel=str(Path(__file__).parent / 'mocks' / 'scancel'), )
def test_ssh_init_nocheck(proc, ssh): proc.sshRunner = Diot(ssh=ssh, servers=['server1', 'server2', 'server3', 'server4'], keys=['server1', 'server2', 'server3', 'wrongkey'], checkAlive=False) r = RunnerSsh(0, proc) assert RunnerSsh.LIVE_SERVERS == [0, 1, 2, 3] assert r.ssh.keywords['t'] == 'server1'
def job0(tmpdir): job = RunnerTest( 0, Proc(workdir=tmpdir, size=1, dirsig=True, echo=Diot(jobs=[0], type=['stderr']), procvars={ 'proc': { 'errhow': 'terminate' }, 'args': {} }, _log=Diot({'shorten': 0}))) fs.mkdir(job.dir) (job.dir / 'job.script').write_text('') return job
def test_ssh_init_checktimeout(proc, ssh): proc.sshRunner = Diot( ssh=ssh, servers=['server1', 'server2', 'server3', 'server4'], keys=['server1', 'server2', 'server3+2.5', 'wrongkey'], checkAlive=2) r = RunnerSsh(0, proc) assert RunnerSsh.LIVE_SERVERS == [0, 1] assert r.ssh.keywords['t'] == 'server1'
def test_ssh_scriptparts(proc): proc.sshRunner = Diot(ssh=ssh, servers=['server1'], checkAlive=False) r = RunnerSsh(0, proc) r.dir.mkdir() (r.dir / 'job.script').write_text('#!/usr/bin/env bash') r.script.write_text('#!/usr/bin/env bash') assert r.scriptParts.header == '#\n# Running job on server: server1\n#' assert r.scriptParts.pre == "\ncd %s" % cmdy._shquote(os.getcwd()) assert r.scriptParts.post == '' assert r.scriptParts.saveoe == True assert r.scriptParts.command == [str(r.dir / 'job.script')]
def __init__(self, *args, **kwargs): kwargs['nthread'] = 10 kwargs['name'] = lambda procset = True: 'pProc' kwargs['errhow'] = 'terminate' kwargs['errntry'] = 3 kwargs['forks'] = 1 kwargs['expect'] = TemplateLiquid('') kwargs['size'] = 1 kwargs['rc'] = [0] kwargs['config'] = Diot(_log = {}) super(Proc, self).__init__(*args, **kwargs)
def defprocs(): ProcTree.NODES.clear() ret = Diot( pAny2Procs1=Proc(), pAny2Procs2=Proc(), pAny2Procs3=Proc(), pAny2Procs4=Proc(), pAny2Procs51=Proc(tag='51', id='pAny2Procs5'), pAny2Procs52=Proc(tag='52', id='pAny2Procs5'), pAny2Procs6=Proc(), pAny2Procs7=Proc(), ) ret.aAggr = ProcSet(ret.pAny2Procs6, ret.pAny2Procs7) ret.aAggr.starts = [ret.aAggr.pAny2Procs6, ret.aAggr.pAny2Procs7] ProcTree.register(ret.pAny2Procs1) ProcTree.register(ret.pAny2Procs2) ProcTree.register(ret.pAny2Procs3) ProcTree.register(ret.pAny2Procs4) ProcTree.register(ret.pAny2Procs51) ProcTree.register(ret.pAny2Procs52) return ret
def test_procset_setattr(ps3_copy): ps3_copy.starts = 'pProc1' assert ps3_copy.starts == [ps3_copy.pProc1] ps3_copy.ends = ps3_copy.pProc3 assert ps3_copy.ends == [ps3_copy.pProc3] ps3_copy.id = 'p3' assert ps3_copy.id == 'p3' ps3_copy.tag = 'sometag' assert ps3_copy.tag == 'sometag' ps3_copy.args = Diot(x=1) assert ps3_copy.pProc1.args.x == 1 assert ps3_copy.pProc2.args.x == 1 assert ps3_copy.pProc3.args.x == 1
def test_ssh_impl(proc, ssh): proc.sshRunner = Diot(ssh=ssh, servers=['server1'], checkAlive=False) r = RunnerSsh(0, proc) assert not r.isRunningImpl() dbox = r.submitImpl() assert dbox.rc == RC_ERROR_SUBMISSION assert dbox.pid == -1 assert 'is not using the same file system as the local machine' in dbox.stderr r.dir.mkdir() r.script.write_text('#!/usr/bin/env bash\nsleep 3') cmd = r.submitImpl() assert cmd.rc == 0 assert r.pid == cmd.pid assert r.isRunningImpl() r.killImpl() assert not r.isRunningImpl()
def set1(): p15 = Proc() p16 = Proc() p17 = Proc() p18 = Proc() p19 = Proc() p20 = Proc() # hide # p15 -> p16 -> p17 -> 19 # \_ p18_/ \_ p20 #p16.hide = True p20.depends = p17 p19.depends = p17 p17.depends = p16, p18 p18.depends = p16 p16.depends = p15 ProcTree.register(p15) return Diot(p15=p15, p16=p16, p17=p17, p18=p18, p19=p19, p20=p20)
def pset(): ProcTree.NODES.clear() p14 = Proc() p15 = Proc() p16 = Proc() p17 = Proc() p18 = Proc() p19 = Proc() p20 = Proc() # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # hide #p18.hide = True p20.depends = p17 p19.depends = p17 p17.depends = p16, p18 p18.depends = p16 p16.depends = p14, p15 return Diot(p15=p15, p16=p16, p17=p17, p18=p18, p19=p19, p20=p20, p14=p14)
def sge(): return Diot( qsub=str(Path(__file__).parent / 'mocks' / 'qsub'), qstat=str(Path(__file__).parent / 'mocks' / 'qstat'), qdel=str(Path(__file__).parent / 'mocks' / 'qdel'), )