Exemple #1
0
def test_execute_iter_raises_stop_iteration_on_no_output():
    sleep_cmd = ["/bin/sleep", "1s"]
    gen = ext.execute_iter(sleep_cmd)
    try:
        gen.next()
    except StopIteration:
        pass
    else:
        assert False, "Expecting StopIteration to be raised by execute_iter"
Exemple #2
0
def test_execute_iter_raises_on_non_zero_return_code():
    try:
        for _ in ext.execute_iter("/bin/false"):
            pass
        assert False, "Expecting CalledProcessError to be raised by execute_iter"
    except subprocess.CalledProcessError as err:
        assert 0 != err.returncode, "Invalid return code returned in error"
        assert "/bin/false" in err.cmd, "Invalid command returned in error"
        assert [] == err.output, "Invalid output returned in error"
Exemple #3
0
def test_execute_iter_calls_process_terminate_on_generator_close():
    cat_cmd = ["/bin/cat", "/dev/kmsg"]
    gen = ext.execute_iter(cat_cmd)
    try:
        gen.next()
        del gen
    except subprocess.CalledProcessError as err:
        assert 0 != err.returncode, "Invalid return code returned in error"
        assert "/bin/cat" in err.cmd, "Invalid command returned in error"
        assert [] != err.output, "Invalid output returned in error"
Exemple #4
0
def test_execute_iter_skips_calling_process_terminate_on_generator_close():
    echo_cmd = ["/bin/echo", "my mom\nhas fleas\n"]
    gen = ext.execute_iter(echo_cmd)
    try:
        gen.next()
        time.sleep(0.5)  # allow echo process to exit
        del gen
    except subprocess.CalledProcessError as err:
        assert 0 != err.returncode, "Invalid return code returned in error"
        assert "/usr/bin/env" in err.cmd, "Invalid command returned in error"
        assert [] != err.output, "Invalid output returned in error"
Exemple #5
0
def test_execute_iter_calls_process_kill_on_generator_close():
    ignore_sigterm_filepath = os.path.join(os.path.dirname(__file__),
                                           "ignore_sigterm.py")
    ignore_sigterm_cmd = ["python", "-u", ignore_sigterm_filepath]
    gen = ext.execute_iter(ignore_sigterm_cmd, terminate_timeout=0.5)
    try:
        gen.next()
        del gen
    except subprocess.CalledProcessError as err:
        assert 0 != err.returncode, "Invalid return code returned in error"
        assert "python" in err.cmd, "Invalid command returned in error"
        assert [] != err.output, "Invalid output returned in error"
Exemple #6
0
def test_execute_iter_yields_non_empty_lines():
    for line in ext.execute_iter("/usr/bin/env"):
        assert "" != line, "Expecting execute_iter to return non-empty lines"
Exemple #7
0
def test_execute_iter_returns_on_zero_return_code():
    try:
        for _ in ext.execute_iter("/bin/true"):
            pass
    except Exception:
        assert False, "Expecting no error to be raised by execute_iter"