Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
def test_full_execution(executable, tmpdir, comm):
    from pylada.process.call import CallProcess
    functional = FakeFunctional(executable, [50])
    program = CallProcess(functional, outdir=str(tmpdir), dompi=False)
    program.start(comm)
    program.wait()
    assert True
Ejemplo n.º 4
0
def test_fail_midway(executable, tmpdir, comm):
    from pytest import raises
    from pylada.process.call import CallProcess
    from pylada.process import Fail

    functional = FakeFunctional(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()
Ejemplo n.º 5
0
def test_call():
  """ Tests CallProcess. Includes failure modes.  """
  from tempfile import mkdtemp
  from os.path import join, abspath, dirname
  from shutil import rmtree
  from numpy import all, arange, abs, array
  from pylada.process.call import CallProcess
  from pylada.process import Fail, NotStarted
  from pylada import default_comm
  from pylada.process.tests.functional import Functional
  from pylada.process.tests.pifunctional import __file__ as executable
  executable = join(dirname(executable), "pifunctional.py")

  comm = default_comm.copy()
  dir = mkdtemp()
  try: 
    functional = Functional(executable, range(8))
    program = CallProcess(functional, outdir=dir, dompi=False )
    # program not started. should fail.
    try: program.poll()
    except NotStarted: pass
    else: raise Exception()
    try: program.wait()
    except NotStarted: pass
    else: raise Exception()

    # now starting for real.
    assert program.start(comm) == False
    assert program.process is not None
    while not program.poll():  continue
    extract = functional.Extract(dir)
    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.start(comm)
    assert program.process is None
    # true restart
    program = CallProcess(functional, outdir=dir, dompi=False )
    assert program.start(comm)
    assert program.process is None
    assert program.poll()
    extract = functional.Extract(dir)
    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)
  finally:
    try: rmtree(dir)
    except: pass

  try: 
    functional = Functional(executable, [50], fail='midway')
    program = CallProcess(functional, outdir=dir, stderr=join(dir, 'error'),
            dompi=False)
    program.start(comm)
    program.wait()
  except Fail: pass
  else: raise Exception
  finally:
    try: rmtree(dir)
    except: pass
  try: 
    functional = Functional(executable, [50])
    program = CallProcess(functional, outdir=dir, dompi=False )
    program.start(comm)
    program.wait()
  finally:
    try: rmtree(dir)
    except: pass
Ejemplo n.º 6
0
def test_process_functional(executable, comm, tmpdir):
    """Tests CallProcess.

    Includes failure modes.
    """
    from pytest import raises
    from numpy import all, arange, abs, array
    from pylada.process.call import CallProcess
    from pylada.process import NotStarted
    from pylada.process.tests.functional import Functional

    functional = Functional(executable, list(range(8)))
    program = CallProcess(functional, outdir=str(tmpdir), dompi=False)
    # program not started. should fail.
    with raises(NotStarted):
        program.poll()

    with raises(NotStarted):
        program.wait()

    # now starting for real.
    assert program.start(comm) == False
    assert program.process is not None
    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.start(comm)
    assert program.process is None
    # true restart
    program = CallProcess(functional, outdir=str(tmpdir), dompi=False)
    assert 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)
Ejemplo n.º 7
0
def test_process_functional(executable, comm, tmpdir):
    """Tests CallProcess.

    Includes failure modes.
    """
    from pytest import raises
    from numpy import all, arange, abs, array
    from pylada.process.call import CallProcess
    from pylada.process import NotStarted
    from pylada.process.tests.functional import Functional

    functional = Functional(executable, list(range(8)))
    program = CallProcess(functional, outdir=str(tmpdir), dompi=False)
    # program not started. should fail.
    with raises(NotStarted):
        program.poll()

    with raises(NotStarted):
        program.wait()

    # now starting for real.
    assert program.start(comm) == False
    assert program.process is not None
    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.start(comm)
    assert program.process is None
    # true restart
    program = CallProcess(functional, outdir=str(tmpdir), dompi=False)
    assert 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)
Ejemplo n.º 8
0
def test(executable):
    """ Tests CallProcess. Includes failure modes.  """
    from tempfile import mkdtemp
    from os.path import join
    from shutil import rmtree
    from numpy import all, arange, abs, array
    from pylada.process.call import CallProcess
    from pylada.process import Fail, NotStarted
    from pylada import default_comm
    from functional import Functional
    comm = default_comm.copy()
    dir = mkdtemp()
    try:
        functional = Functional(executable, range(8))
        program = CallProcess(functional, outdir=dir, dompi=False)
        # program not started. should fail.
        try:
            program.poll()
        except NotStarted:
            pass
        else:
            raise Exception()
        try:
            program.wait()
        except NotStarted:
            pass
        else:
            raise Exception()

        # now starting for real.
        assert program.start(comm) == False
        assert program.process is not None
        while not program.poll():
            continue
        extract = functional.Extract(dir)
        assert extract.success
        assert all(arange(8) - extract.order == 0)
        assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                           3.146801, 3.144926, 3.143907, 3.143293]))\
                    < 1e-5 )
        assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                              0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                    < 1e-5 )
        assert all(n['n'] == comm['n'] for n in extract.comm)
        # restart
        assert program.start(comm)
        assert program.process is None
        # true restart
        program = CallProcess(functional, outdir=dir, dompi=False)
        assert program.start(comm)
        assert program.process is None
        assert program.poll()
        extract = functional.Extract(dir)
        assert extract.success
        assert all(arange(8) - extract.order == 0)
        assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                           3.146801, 3.144926, 3.143907, 3.143293]))\
                    < 1e-5 )
        assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                              0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                    < 1e-5 )
    finally:
        try:
            rmtree(dir)
        except:
            pass

    try:
        functional = Functional(executable, [666])
        program = CallProcess(functional,
                              outdir=dir,
                              stderr=join(dir, 'shit'),
                              dompi=False)
        program.start(comm)
        program.wait()
    except Fail:
        pass
    else:
        raise Exception
    finally:
        try:
            rmtree(dir)
        except:
            pass
    try:
        functional = Functional(executable, [667])
        program = CallProcess(functional, outdir=dir, dompi=False)
        program.start(comm)
        program.wait()
    finally:
        try:
            rmtree(dir)
        except:
            pass