use std::io;
use std::io::Write;
use python_script_runner::python_script_runner::{run_python_script, PythonExecutor};
#[tokio::main]
async fn main() -> io::Result<()> {
dotenvy::dotenv().ok();
println!("Testing python_script_runner...");
let executor = PythonExecutor::new();
println!("Executing script via PythonExecutor (project-relative path)...");
match executor.execute_script("scripts/hello.py").await {
Ok(()) => println!("Script completed successfully"),
Err(e) => println!("Script failed (expected if file absent): {}", e),
}
let mut tmp = tempfile::NamedTempFile::new().map_err(io::Error::other)?;
writeln!(tmp, "print('Hello from run_python_script!')").map_err(io::Error::other)?;
let tmp_path = tmp
.path()
.to_str()
.ok_or_else(|| io::Error::other("non-UTF-8 temp path"))?
.to_string();
println!("Executing inline temp script via run_python_script...");
match run_python_script(&tmp_path).await {
Ok(()) => println!("Temp script completed successfully"),
Err(e) => println!("Temp script failed: {}", e),
}
println!("Executing non-existent script (expect NotFound)...");
let result = run_python_script("/tmp/does_not_exist_abc123.py").await;
match &result {
Err(e) if e.kind() == io::ErrorKind::NotFound => {
println!("Correctly returned NotFound: {}", e);
}
Err(other) => println!("Unexpected error: {:?}", other),
Ok(()) => println!("Unexpected success"),
}
println!("Done — all run_python_script operations completed successfully");
Ok(())
}