use std::ffi::CString;
use fidius_python::{ensure_initialized, pyerr_to_plugin_error};
use pyo3::prelude::*;
#[test]
fn interpreter_evaluates_simple_expression() {
ensure_initialized();
let result = Python::with_gil(|py| -> i64 {
let code = CString::new("1 + 1").unwrap();
py.eval(code.as_c_str(), None, None)
.unwrap()
.extract()
.unwrap()
});
assert_eq!(result, 2);
}
#[test]
fn pyerr_to_plugin_error_preserves_class_message_and_traceback() {
ensure_initialized();
let err = Python::with_gil(|py| -> PyErr {
let code = CString::new("raise KeyError('nope')").unwrap();
py.run(code.as_c_str(), None, None).unwrap_err()
});
let pe = pyerr_to_plugin_error(err);
assert_eq!(pe.code, "KeyError");
assert!(pe.message.contains("nope"));
let details = pe.details.expect("traceback should be present");
assert!(details.contains("traceback"));
}