def test_fslwrapper_submit(): test_func = wutils.fslwrapper(_test_script_func) with mockFSLDIR() as fsldir, \ mock.patch('fsl.utils.fslsub.submit', mock_submit): test_file = op.join(fsldir, 'bin', 'test_script') with open(test_file, 'wt') as f: f.write(_test_script) os.chmod(test_file, 0o755) jid = test_func(1, 2, submit=True) assert jid == '12345' stdout, stderr = fslsub.output('12345') assert stdout.strip() == 'test_script running: 1 2' assert stderr.strip() == '' kwargs = {'name': 'abcde', 'ram': '4GB'} jid = test_func(1, 2, submit=kwargs) assert jid == '12345' stdout, stderr = fslsub.output('12345') experr = '\n'.join( ['{}: {}'.format(k, kwargs[k]) for k in sorted(kwargs.keys())]) assert stdout.strip() == 'test_script running: 1 2' assert stderr.strip() == experr
def test_run_submit(): def mkexec(path, contents): with open(path, 'wt') as f: f.write(contents) os.chmod(path, 0o755) test_script = textwrap.dedent(""" #!/usr/bin/env bash echo test_script running exit 0 """).strip() with tempdir.tempdir(), \ mockFSLDIR(), \ mock.patch('fsl.utils.fslsub.submit', mock_submit): mkexec(op.expandvars('$FSLDIR/bin/fsltest'), test_script) jid = run.run('fsltest', submit=True) assert jid == '12345' stdout, stderr = fslsub.output(jid) assert stdout == 'test_script running\n' assert stderr == '' # or can pass submit opts as a dict kwargs = {'name': 'abcde', 'ram': '4GB'} jid = run.run('fsltest', submit=kwargs) assert jid == '12345' stdout, stderr = fslsub.output(jid) experr = '\n'.join( ['{}: {}'.format(k, kwargs[k]) for k in sorted(kwargs.keys())]) + '\n' assert stdout == 'test_script running\n' assert stderr == experr # or can pass submit opts as kwargs kwargs = {'name': 'abcde', 'ram': '4GB'} jid = run.run('fsltest', submit=True, **kwargs) assert jid == '12345' stdout, stderr = fslsub.output(jid) experr = '\n'.join( ['{}: {}'.format(k, kwargs[k]) for k in sorted(kwargs.keys())]) + '\n' assert stdout == 'test_script running\n' assert stderr == experr
def test_func_to_cmd(): with fslsub_mockFSLDIR(), tempdir(): cmd = fslsub.func_to_cmd(myfunc, (), {}) jid = fslsub.submit(cmd) stdout, stderr = fslsub.output(jid) assert stdout.strip() == 'standard output' assert stderr.strip() == 'standard error'
def test_submit(): script = tw.dedent("""#!/usr/bin/env bash echo "standard output" echo "standard error" >&2 exit 0 """).strip() with fslsub_mockFSLDIR(), tempdir(): cmd = op.join('.', 'myscript') with open(cmd, 'wt') as f: f.write(script) os.chmod(cmd, 0o755) jid = fslsub.submit(cmd) stdout, stderr = fslsub.output(jid) assert stdout.strip() == 'standard output' assert stderr.strip() == 'standard error'
def test_cmdwrapper_submit(): test_func = wutils.cmdwrapper(_test_script_func) newpath = op.pathsep.join(('.', os.environ['PATH'])) with tempdir.tempdir(), \ mock.patch('fsl.utils.fslsub.submit', mock_submit), \ mock.patch.dict(os.environ, {'PATH' : newpath}): with open('test_script', 'wt') as f: f.write(_test_script) os.chmod('test_script', 0o755) jid = test_func(1, 2, submit=True) assert jid == '12345' stdout, stderr = fslsub.output('12345') assert stdout.strip() == 'test_script running: 1 2' assert stderr.strip() == ''