Пример #1
0
def test_timeout():
    # this must timeout
    timeout = 1
    sleep = timeout
    cmd = f"sleep {sleep}"
    with pytest.raises(CommandTimedOut):
        run(cmd, timeout=timeout, error_log=lore_log)
Пример #2
0
def test_repeated_execution_fails():
    with pytest.raises(RepeatedExecutionFailed):
        try:
            run("sleep 1", timeout=.9, attempts=3, verbose=True, wait=.5)
        except RepeatedExecutionFailed as e:
            echo('\nRaised ' + type(e).__name__ + ':\n' + str(e), err=True)
            raise
Пример #3
0
def test_repeated_execution_fails():
    with pytest.raises(RepeatedExecutionFailed):
        try:
            run("sleep 1",
                connection=leibniz1,
                attempts=3,
                wait=.5,
                timeout=.9,
                verbose=True,
                error_log=lore_log)
        except RepeatedExecutionFailed as e:
            print(e)
            raise
Пример #4
0
def test_printf_2_lines():
    s = 'hello world\nhow do you do?\n'
    cmd = f"printf '{s}'"
    result = run(cmd)
    assert result.returncode == 0
    assert result.stderr == ''
    assert result.stdout == s
Пример #5
0
def test_echo():
    s = 'hello world'
    cmd = 'echo ' + s
    result = run(cmd)
    assert result.returncode == 0
    assert result.stderr == ''
    assert result.stdout == s + '\n'
Пример #6
0
def test_list_of_non_empty_lines():
    s = 'hello world\n\nhow do you do?\n'
    cmd = f"printf '{s}'"
    result = run(cmd, post_processor=list_of_non_empty_lines)
    assert result.returncode == 0
    assert result.stderr == ''
    expected = s.splitlines(keepends=False)
    expected = [line for line in expected if line]
    assert result.processed == expected
Пример #7
0
def test_no_timeout():
    # this must not timeout
    timeout = 1
    sleep = timeout / 2
    cmd = f"sleep {sleep}"
    result = run(cmd, timeout=timeout)
    assert result.returncode == 0
    assert not bool(result.stdout)
    assert not bool(result.stderr)
Пример #8
0
def test_ls_inexisting():
    # ls on a inexisting directory produces a nonzero return code (1), and a
    # diagnostic message on stderr
    cmd = f"ls {os.path.join(test_data_dir,'inexisting')}"
    with pytest.raises(NonZeroReturnCode):
        try:
            run(cmd)
        except NonZeroReturnCode as e:
            assert e.result.returncode == 1
            assert bool(e.result.stderr)
            raise
    with pytest.raises(Stderr):
        try:
            run(cmd, stderr_is_error=True, check=False)
        except Stderr as e:
            assert e.result.returncode == 1
            assert bool(e.result.stderr)
            raise
Пример #9
0
def test_list_of_lines():
    s = 'hello world\n\nhow do you do?\n'
    cmd = f"printf '{s}'"
    result = run(cmd, post_processor=list_of_lines, connection=leibniz1)
    assert result.returncode == 0
    assert result.stderr == ''
    expected = s.splitlines(keepends=False)
    expected.append('')
    assert result.processed == expected
Пример #10
0
def test_no_timeout():
    # this must not timeout
    timeout = 5
    sleep = timeout / 4
    cmd = f"sleep {sleep}"
    result = run(cmd, connection=leibniz1, timeout=timeout)
    assert result.returncode == 0
    assert not bool(result.stdout)
    assert not bool(result.stderr)
Пример #11
0
def test_repeated_execution_succeeds():
    # setup
    newdir = os.path.join('data', 'newdir')
    try:
        remove(newdir, leibniz1)
    except:
        pass
    assert not exists(newdir, leibniz1)

    src_sh = os.path.join(test_data_dir, 'test_succeeds_the_second_time.sh')
    assert exists('data', leibniz1)
    dst_sh = os.path.join('data', 'test_succeeds_the_second_time.sh')
    remove(dst_sh, leibniz1)
    copy_local_to_remote(leibniz1, src_sh, dst_sh)
    assert exists(dst_sh, leibniz1)
    assert not exists(dst_sh, leibniz1, operator='-x')
    run('chmod +x test_succeeds_the_second_time.sh',
        leibniz1,
        working_directory='data')
    assert exists(dst_sh, leibniz1, operator='-x')

    # test
    # this command should succeeds the second time
    cmd = "./test_succeeds_the_second_time.sh"
    result = run(cmd,
                 leibniz1,
                 working_directory='data',
                 attempts=3,
                 wait=.5,
                 verbose=True)
    assert result.attempts == 2
    assert exists(newdir, leibniz1)

    # clean up
    remove(newdir, leibniz1)
    assert not exists(newdir, leibniz1)
    remove(dst_sh, leibniz1)
    assert not exists(dst_sh, leibniz1)
Пример #12
0
def test_repeated_execution_succeeds():
    newdir = os.path.join(test_data_dir, 'newdir')
    try:
        remove(newdir)
    except:
        pass

    # this command should succeeds the second time
    cmd = "./test_succeeds_the_second_time.sh"
    result = run(cmd,
                 working_directory=test_data_dir,
                 attempts=3,
                 verbose=True,
                 wait=.5)
    assert result.attempts == 2
    assert exists(newdir)

    # clean up
    remove(newdir)
Пример #13
0
def test_timeout():
    # this must timeout
    cmd = 'tree data'
    with pytest.raises(CommandTimedOut):
        run(cmd, connection=leibniz1, timeout=0.1, error_log=lore_log)