Exemple #1
0
def test_kill_children():
    """Test that child processes are also killed. We don't want any zombies!."""
    cmd = ExternalCommand(['bash', '-c', 'bash -c "sleep 10" & echo -n $!'])
    assert cmd.run(timeout=1) is False
    child_pid = int(cmd.stdout)
    try:
        # All processes in the group should be killed by SIGKILL,
        # but `os.killpg` doesn't wait for them to die...
        time.sleep(3)
        os.kill(child_pid, 0)
    except OSError:
        # there is no process with such pid
        assert True
    else:
        assert False
Exemple #2
0
def test_success():
    """Test success."""
    assert ExternalCommand(['bash', '-c', 'true']).run() is True
Exemple #3
0
def test_magic_str():
    """Test str(ExternalCommand)."""
    assert str(ExternalCommand(['java', '-version'
                                ])) == 'ExternalCommand: java -version'
Exemple #4
0
def test_env():
    """Test replacing environment."""
    cmd = ExternalCommand(['bash', '-c', 'echo -n ${HOME}'])
    assert cmd.run(env={'HOME': '/home/michal'}) is True
    assert cmd.stdout == '/home/michal'
Exemple #5
0
def test_timeout_raise():
    """Test timeout with raise_on_error."""
    with pytest.raises(subprocess.CalledProcessError):
        ExternalCommand(['bash', '-c', 'sleep 10']).run(timeout=1,
                                                        raise_on_error=True)
Exemple #6
0
def test_update_env():
    """Test updating environment."""
    cmd = ExternalCommand(
        ['bash', '-c', 'echo -n "You know nothing, ${NAME}..."'])
    assert cmd.run(update_env={'NAME': 'Jon Snow'}) is True
    assert cmd.stdout == 'You know nothing, Jon Snow...'
Exemple #7
0
def test_timeout():
    """Test timeout."""
    assert ExternalCommand(['bash', '-c', 'sleep 10']).run(timeout=1) is False
Exemple #8
0
def test_failure_raise():
    """Test failure with raise_on_error."""
    with pytest.raises(subprocess.CalledProcessError):
        ExternalCommand(['bash', '-c', 'false']).run(raise_on_error=True)
Exemple #9
0
def test_no_failure_no_raise():
    """Test that no exception is thrown when no failure happens."""
    ExternalCommand(['bash', '-c', 'true']).run(raise_on_error=True)
Exemple #10
0
def test_input_validation():
    """Test input validation."""
    with pytest.raises(ValueError):
        ExternalCommand('bash')
    with pytest.raises(ValueError):
        ExternalCommand(None)
Exemple #11
0
def test_failure():
    """Test failure."""
    assert ExternalCommand(['bash', '-c', 'false']).run() is False