From 9fee3a6ed9da695cdc0d10e4de4fb9c7cfdc24de Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Tue, 11 Jan 2022 13:31:17 -0500 Subject: [PATCH] Add tests for run_python_script*. --- pyo3-build-config/src/impl_.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 2e0e9072d75..0b7cc5f5631 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -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"); + } }