Ejemplo n.º 1
0
def test_run_02(error, info):
    """It handles a timeout error."""
    args = {'assembler': 'my_assembler', 'timeout': 10}

    asm = BaseAssembler(args, 'cxn')
    asm.assemble = MagicMock(side_effect=TimeoutError())

    with pytest.raises(TimeoutError) as timeout_error:
        asm.run()

    error_msg = str(timeout_error.value)
    if error_msg[-1] != '.':
        error_msg += '.'
    assert error_msg == (
        'Time ran out for the assembler after 0:00:10 (HH:MM:SS).')

    expect = 'Assembling shards with {}: iteration {}'.format(
        args['assembler'], asm.state['iteration'])
    info.assert_called_once_with(expect)

    # Python 3.6 formats exceptions differently so we need to do this
    assert error.call_count == 1
    regex = re.compile(
        r'Time ran out for the assembler after 0:00:10 \(HH:MM:SS\)')
    assert regex.match(error.call_args[0][0])
Ejemplo n.º 2
0
def test_run_02(error, info):
    """It handles a timeout error."""
    args = {'assembler': 'my_assembler', 'timeout': 10}

    asm = BaseAssembler(args, 'cxn')
    asm.assemble = MagicMock(side_effect=TimeoutError())

    with pytest.raises(TimeoutError) as timeout_error:
        asm.run()

    error_msg = str(timeout_error.value)
    if error_msg[-1] != '.':
        error_msg += '.'
    assert error_msg == (
        'Time ran out for the assembler after 0:00:10 (HH:MM:SS).')

    expect = 'Assembling shards with {}: iteration {}'.format(
        args['assembler'], asm.state['iteration'])
    info.assert_called_once_with(expect)

    # Python 3.6 formats exceptions differently so we need to do this
    assert error.call_count == 1
    regex = re.compile(
        r'Time ran out for the assembler after 0:00:10 \(HH:MM:SS\)')
    assert regex.match(error.call_args[0][0])
Ejemplo n.º 3
0
    def test_run_ok(self, info):
        args = {'assembler': 'my_assembler', 'timeout': 10}

        assembler = BaseAssembler(args, 'db_conn')
        assembler.set_state('blast_db', 'query_file', 99)

        assembler.assemble = MagicMock()

        assembler.run()

        info.assert_called_once_with('Assembling shards with {}: '
                                     'iteration {}'.format(
                                         args['assembler'],
                                         assembler.state['iteration']))
Ejemplo n.º 4
0
    def test_run_called_process_error(self, error, info):
        args = {'assembler': 'my_assembler', 'timeout': 10}
        error_code = 88
        cmd = 'my command'
        error = subprocess.CalledProcessError(error_code, cmd)

        assembler = BaseAssembler(args, 'db_conn')
        assembler.set_state('blast_db', 'query_file', 99)

        assembler.assemble = MagicMock(side_effect=error)

        with pytest.raises(RuntimeError) as runtime_error:
            assembler.run()

        error_msg = str(runtime_error.value)
        if error_msg[-1] != '.':
            error_msg += '.'
        assert error_msg == (
            "The assembler failed with error: Command 'my command' "
            "returned non-zero exit status 88.")

        expect = 'Assembling shards with {}: iteration {}'.format(
            args['assembler'], assembler.state['iteration'])
        info.assert_called_once_with(expect)