def test_iterator(executable, tmpdir, comm): """Tests IteratorProcess. Includes failure modes. """ from pytest import raises from numpy import all, arange, abs, array from pylada.process.iterator import IteratorProcess from pylada.process import Fail, NotStarted from pylada.process.tests.functional import Functional functional = Functional(executable, list(range(8))) program = IteratorProcess(functional, outdir=str(tmpdir)) # program not started. should fail. with raises(NotStarted): program.poll() with raises(NotStarted): program.wait() # now starting for real. program.start(comm) while not program.poll(): continue extract = functional.Extract(str(tmpdir)) assert extract.success assert all(arange(8) - extract.order == 0) expected = [ 0.0, 3.2, 3.162353, 3.150849, 3.146801, 3.144926, 3.143907, 3.143293 ] assert all(abs(extract.pi - array(expected)) < 1e-5) expected = [ 3.141593, 0.05840735, 0.02076029, 0.009256556, 0.005207865, 0.00333321, 0.002314774, 0.001700664 ] assert all(abs(extract.error - array(expected)) < 1e-5) assert all(n['n'] == comm['n'] for n in extract.comm) # restart assert program.poll() program.start(comm) assert program.process is None assert program.poll() # true restart program = IteratorProcess(functional, outdir=str(tmpdir)) program.start(comm) assert program.process is None assert program.poll() extract = functional.Extract(str(tmpdir)) assert extract.success assert all(arange(8) - extract.order == 0) expected = [ 0.0, 3.2, 3.162353, 3.150849, 3.146801, 3.144926, 3.143907, 3.143293 ] assert all(abs(extract.pi - array(expected)) < 1e-5) expected = [ 3.141593, 0.05840735, 0.02076029, 0.009256556, 0.005207865, 0.00333321, 0.002314774, 0.001700664 ] assert all(abs(extract.error - array(expected)) < 1e-5)
def test_full_execution(executable, tmpdir, comm): from pylada.process.iterator import IteratorProcess from pylada.process.tests.functional import Functional functional = Functional(executable, [50]) program = IteratorProcess(functional, outdir=str(tmpdir)) program.start(comm) program.wait() assert True
def test_full_execution(executable, tmpdir, comm): from pylada.process.call import CallProcess from pylada.process.tests.functional import Functional functional = Functional(executable, [50]) program = CallProcess(functional, outdir=str(tmpdir), dompi=False) program.start(comm) program.wait() assert True
def jobfolders(executable, start=0, end=8): from pylada.process.tests.functional import Functional from pylada.jobfolder.jobfolder import JobFolder root = JobFolder() for n in range(start, end): job = root / str(n) job.functional = Functional(executable, [n]) job.params['sleep'] = 0.01 return root
def test_fail_midway(executable, tmpdir, comm): from pytest import raises from pylada.process.iterator import IteratorProcess from pylada.process import Fail from pylada.process.tests.functional import Functional functional = Functional(executable, [50], fail='midway') program = IteratorProcess(functional, outdir=str(tmpdir)) with raises(Fail): program.start(comm) program.wait()
def test_fail_midway(executable, tmpdir, comm): from pytest import raises from pylada.process.call import CallProcess from pylada.process import Fail from pylada.process.tests.functional import Functional functional = Functional(executable, [50], fail='midway') program = CallProcess(functional, outdir=str(tmpdir), stderr=str(tmpdir.join('error')), dompi=False) with raises(Fail): program.start(comm) program.wait()
def test_failed_job_discovery(tmpdir, comm, root, executable, Process): """ Tests JobFolderProcess. Includes failure modes. """ from pytest import raises from pylada.process import Fail from pylada.process.tests.functional import Functional with raises(Fail): job = root / str(666) job.functional = Functional(executable, [50], fail='end') program = Process(tmpdir, root) assert program.nbjobsleft > 0 program.start(comm) program.wait() assert program.nbjobsleft == 0 assert len(program.errors.keys()) == 1 assert '666' in program.errors assert len(program._finished) == 8
def test_restart_failed_job(tmpdir, comm, root, executable, Process): from pytest import raises from pylada.process import Fail from pylada.process.tests.functional import Functional with raises(Fail): job = root / str(666) job.functional = Functional(executable, [50], fail='end') program = Process(tmpdir, root) program.start(comm) program.wait() job.functional.order = [45] job.functional.fail = None program = Process(tmpdir, root) assert program.nbjobsleft > 0 program.start(comm) program.wait() assert program.nbjobsleft == 0