Skip to content

Commit

Permalink
Add tests for run_python_script*.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Anderson committed Jan 11, 2022
1 parent e6c92c5 commit 9fee3a6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pyo3-build-config/src/impl_.rs
Expand Up @@ -1787,4 +1787,29 @@ mod tests {
.is_none()
);
}

#[test]
fn test_run_python_script() {
// as above, this should be okay in CI where Python is presumed installed
let interpreter = make_interpreter_config()
.expect("could not get InterpreterConfig from installed interpreter");
let out = interpreter
.run_python_script("print(2 + 2)")
.expect("failed to run Python script");
assert_eq!(out, "4\n");
}

#[test]
fn test_run_python_script_with_envs() {
// as above, this should be okay in CI where Python is presumed installed
let interpreter = make_interpreter_config()
.expect("could not get InterpreterConfig from installed interpreter");
let out = interpreter
.run_python_script_with_envs(
"import os; print(os.getenv('PYO3_TEST'))",
[("PYO3_TEST", "42")],
)
.expect("failed to run Python script");
assert_eq!(out, "42\n");
}
}

0 comments on commit 9fee3a6

Please sign in to comment.