Example #1
0
def test_iter_print():
    for ip_address in ip_addresses:
        nanny = Nanny()
        command = ["python","-u", get_test_functions_path(ip_address), "--callback=iter_print"]
        pyc = PythonChildProcess(name="P1",ip_address=ip_address,command=command)
        nanny.register_child_process(pyc)
        with captured_output() as (out, err):
            nanny.execute_all_child_processes(time_out=1)
        if pyc.is_local():
            assert str(out.getvalue().strip()) == "\n".join(["P1: %i"%i for i in [0,2,4,6,8]])
            assert str(err.getvalue().strip()) == "\n".join(["P1: %i"%i for i in [1,3,5,7,9]])
        else:
            assert "\r\n".join(["P1: %i" % i for i in range(10)]) == str(out.getvalue().strip())
Example #2
0
def test_interrupt_process_gently():
    for ip_address in ip_addresses:
        command = ["python", get_test_functions_path(ip_address), "--callback=count_high"]

        cp = PythonChildProcess(ip_address, command)
        stdin , stdout, stderr = cp.execute_child_process()
        time.sleep(5)
        cp.kill()
        time.sleep(1)
        stdout_out = stdout.readlines()
        stderr_out = stderr.readlines()
        if cp.is_local():
            assert stderr_out[-1].strip() == "KeyboardInterrupt"
        else:
            assert stdout_out[-1].strip() == "KeyboardInterrupt"
        assert not cp.is_alive(), "Process is still alive, killing it did not work"
def test_interrupt_process_gently():
    for ip_address in ip_addresses:
        command = ["python", get_test_functions_path(ip_address), "--callback=count_high"]

        cp = PythonChildProcess(ip_address, command)
        stdin , stdout, stderr = cp.execute_child_process()
        time.sleep(5)
        cp.kill()
        time.sleep(1)
        stdout_out = stdout.readlines()
        stderr_out = stderr.readlines()
        if cp.is_local():
            assert stderr_out[-1].strip() == "KeyboardInterrupt"
        else:
            assert stdout_out[-1].strip() == "KeyboardInterrupt"
        assert not cp.is_alive(), "Process is still alive, killing it did not work"
Example #4
0
def test_iter_print():
    for ip_address in ip_addresses:
        nanny = Nanny()
        command = [
            "python", "-u",
            get_test_functions_path(ip_address), "--callback=iter_print"
        ]
        pyc = PythonChildProcess(name="P1",
                                 ip_address=ip_address,
                                 command=command)
        nanny.register_child_process(pyc)
        with captured_output() as (out, err):
            nanny.execute_all_child_processes(time_out=1)
        if pyc.is_local():
            assert str(out.getvalue().strip()) == "\n".join(
                ["P1: %i" % i for i in [0, 2, 4, 6, 8]])
            assert str(err.getvalue().strip()) == "\n".join(
                ["P1: %i" % i for i in [1, 3, 5, 7, 9]])
        else:
            assert "\r\n".join(["P1: %i" % i for i in range(10)
                                ]) == str(out.getvalue().strip())