Beispiel #1
0
def test_execution_error(tmp_path):
    """Test error when the script execution fails."""
    error_msg = "execution failure, see the stdout and stderr files in /"
    script_path = DATA_DIR / "error.sh"
    runner = ScriptRunner(script_path, {}, tmp_path)
    with pytest.raises(ScriptExecutionError, match=error_msg):
        runner.run()

    _assertions(
        tmp_path / script_path.name,
        "ls non-existing-file",
        "",
        "ls: (?:cannot access )?'?non-existing-file'?: No such file or directory",
    )
def test_execution_failure(tmp_path):
    """Test script error."""
    script = "ls non-existing-file"

    error_msg = "execution failure, see the stdout and stderr files in /"
    runner = ScriptRunner(EXE_RUNNER_NAME, script, tmp_path)
    with pytest.raises(ScriptExecutionError, match=error_msg):
        runner.run()

    _assertions(
        tmp_path,
        runner,
        script,
        "",
        "ls: cannot access '?non-existing-file'?: No such file or directory",
    )
Beispiel #3
0
def test_execution_with_timeout(tmp_path):
    """Test script execution with timeout."""
    # with enough time
    script_path = DATA_DIR / "timeout.sh"
    runner = ScriptRunner(script_path, {"timeout": "2s"}, tmp_path)
    runner.run()

    # without enough time
    runner = ScriptRunner(script_path, {"timeout": "0.1s"}, tmp_path)
    error_msg = (
        r"Command '\['/usr/bin/env', 'bash', 'timeout\.sh'\]' timed out after "
        ".* seconds")
    with pytest.raises(subprocess.TimeoutExpired, match=error_msg):
        runner.run()
def test_files_ok(tmp_path):
    """Test that the script execution is OK."""
    script = "echo hello"
    runner = ScriptRunner(EXE_RUNNER_NAME, script, tmp_path)
    runner.run()
    _assertions(tmp_path, runner, script, "hello\n", "")
Beispiel #5
0
def test_execution_with_setting(tmp_path):
    """Test script execution with placeholder replaced."""
    script_path = DATA_DIR / "nproc.sh"
    runner = ScriptRunner(script_path, {"nproc": "100"}, tmp_path)
    runner.run()
    _assertions(tmp_path / script_path.name, "echo 100", "100", "")
Beispiel #6
0
def test_error_with_unreadable_script(tmp_path):
    """Test error when the script is not readable."""
    error_msg = "cannot read the script .*/bin/bash"
    with pytest.raises(TypeError, match=error_msg):
        ScriptRunner(Path("/bin/bash"), {}, tmp_path)
Beispiel #7
0
def test_error_with_missing_setting(tmp_path):
    """Test error when a placeholder cannot be replaced."""
    error_msg = "in .*tests/data/runners/nproc.sh: 'nproc' is undefined"
    with pytest.raises(ValueError, match=error_msg):
        ScriptRunner(DATA_DIR / "nproc.sh", {}, tmp_path)