def test_sequential_commands__abort_on_error_3(temp_folder): cmd_1 = AtomicCmd("true") cmd_2 = AtomicCmd("true") cmd_3 = AtomicCmd("false") cmds = SequentialCmds([cmd_1, cmd_2, cmd_3]) cmds.run(temp_folder) assert_equal(cmds.join(), [0, 0, 1])
def test_sequential_commands__abort_on_error_3(temp_folder): cmd_1 = AtomicCmd("true") cmd_2 = AtomicCmd("true") cmd_3 = AtomicCmd("false") cmds = SequentialCmds([cmd_1, cmd_2, cmd_3]) cmds.run(temp_folder) assert_equal(cmds.join(), [0, 0, 1])
def test_sequential_commands__abort_on_error_1(temp_folder): cmd_1 = AtomicCmd("false") cmd_2 = AtomicCmd(("sleep", 10)) cmd_3 = AtomicCmd(("sleep", 10)) cmds = SequentialCmds([cmd_1, cmd_2, cmd_3]) cmds.run(temp_folder) assert_equal(cmds.join(), [1, None, None])
def test_sequential_commands__abort_on_error_1(temp_folder): cmd_1 = AtomicCmd("false") cmd_2 = AtomicCmd(("sleep", 10)) cmd_3 = AtomicCmd(("sleep", 10)) cmds = SequentialCmds([cmd_1, cmd_2, cmd_3]) cmds.run(temp_folder) assert_equal(cmds.join(), [1, None, None])
def __init__(self, config, reference, input_files, output_file, dependencies): cat_cmds, cat_obj = concatenate_input_bams(config, input_files) cmd_map = AtomicCmd([ "mapDamage", "-n", _MAPDAMAGE_MAX_READS, "-i", "-", "-d", "%(TEMP_DIR)s", "-r", reference ], IN_STDIN=cat_obj, CHECK_VERSION=MAPDAMAGE_VERSION) train_cmds = ParallelCmds(cat_cmds + [cmd_map]) cat_cmds, cat_obj = concatenate_input_bams(config, input_files) cmd_scale = AtomicCmd([ "mapDamage", "--rescale-only", "-n", _MAPDAMAGE_MAX_READS, "-i", "-", "-d", "%(TEMP_DIR)s", "-r", reference, "--rescale-out", "%(OUT_BAM)s" ], IN_STDIN=cat_obj, OUT_BAM=output_file, CHECK_VERSION=MAPDAMAGE_VERSION) rescale_cmds = ParallelCmds(cat_cmds + [cmd_scale]) description = "<mapDamageRescale: %i file(s) -> '%s'>" % ( len(input_files), output_file) CommandNode.__init__(self, command=SequentialCmds([train_cmds, rescale_cmds]), description=description, dependencies=dependencies)
def test_sequential_commands__atomiccmds(): mocks = [] for _ in range(3): cmd_mock = flexmock(AtomicCmd(["ls"])) cmd_mock.should_receive('run').with_args("xTMPx").once cmd_mock.should_receive('join').with_args().and_return([0]).twice mocks.append(cmd_mock) cmds = SequentialCmds(mocks) assert not cmds.ready() cmds.run("xTMPx") assert cmds.ready() assert_equal(cmds.join(), [0, 0, 0])
def test_sequential_commands__atomiccmds(): mocks = [] for _ in range(3): cmd_mock = flexmock(AtomicCmd(["ls"])) cmd_mock.should_receive('run').with_args("xTMPx").once cmd_mock.should_receive('join').with_args().and_return([0]).twice mocks.append(cmd_mock) cmds = SequentialCmds(mocks) assert not cmds.ready() cmds.run("xTMPx") assert cmds.ready() assert_equal(cmds.join(), [0, 0, 0])
def test_pformat__sets__nested(): cmd_1 = AtomicCmd(("echo", "foo"), OUT_STDOUT=AtomicCmd.PIPE) cmd_2 = AtomicCmd("gzip", IN_STDIN=cmd_1) cmd_3 = AtomicCmd("sha1sum") set_1 = ParallelCmds((cmd_1, cmd_2)) set_2 = SequentialCmds((set_1, cmd_3)) assert_equal(pformat(set_2), ("<Sequential commands:\n" " - Parallel commands:\n" " - <00> Command = ['echo', 'foo']\n" " STDOUT = <01>\n" " STDERR* = '${{TEMP_DIR}}/pipe_echo_{cmd_1_id}.stderr'\n" " - <01> Command = ['gzip']\n" " STDIN = <00>\n" " STDOUT* = '${{TEMP_DIR}}/pipe_gzip_{cmd_2_id}.stdout'\n" " STDERR* = '${{TEMP_DIR}}/pipe_gzip_{cmd_2_id}.stderr'\n" " - <02> Command = ['sha1sum']\n" " STDOUT* = '${{TEMP_DIR}}/pipe_sha1sum_{cmd_3_id}.stdout'\n" " STDERR* = '${{TEMP_DIR}}/pipe_sha1sum_{cmd_3_id}.stderr'>") \ .format(cmd_1_id = id(cmd_1), cmd_2_id = id(cmd_2), cmd_3_id = id(cmd_3)))
def test_sequential_commands__reject_empty_commandset(): SequentialCmds([])
def test_sequential_commands__reject_noncommand(): SequentialCmds([object()])
def test_sequential_commands__accept_sequential(): command = AtomicCmd(["ls"]) seqcmd = SequentialCmds([command]) SequentialCmds([seqcmd])
def test_sequential_commands__accept_parallel(): command = AtomicCmd(["ls"]) parcmd = ParallelCmds([command]) SequentialCmds([parcmd])
def test_parallel_commands__reject_sequential(): command = AtomicCmd(["ls"]) seqcmd = SequentialCmds([command]) assert_raises(CmdError, ParallelCmds, [seqcmd])