litellm/litellm-rust/crates/python-interop/tests/interop.rs
Yujong Lee 2ca2d106f7 wip
2026-09-07 19:49:37 -07:00

30 lines
979 B
Rust

use rstest::rstest;
use serde_json::{Value, json};
use litellm_python_interop::{from_py, release_count, release_gil, to_py};
#[path = "support/mod.rs"]
mod support;
use support::python::{InitializedPython, initialized_python};
#[rstest]
fn serde_values_round_trip_through_python(#[from(initialized_python)] python: &InitializedPython) {
python.attach(|py| {
let expected = json!({"model": "test", "items": [1, true, null]});
let python_value = to_py(py, &expected).expect("value should convert to Python");
let actual: Value =
from_py(python_value.bind(py)).expect("Python value should convert to serde");
assert_eq!(actual, expected);
});
}
#[rstest]
fn release_gil_runs_work_and_records_it(#[from(initialized_python)] python: &InitializedPython) {
let before = release_count();
let result = python.attach(|py| release_gil(py, || 42));
assert_eq!(result, 42);
assert_eq!(release_count(), before + 1);
}