Skip to content

Commit

Permalink
adding first pyo3 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rickfast committed Oct 8, 2023
1 parent 2fd735c commit 22594af
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 50 additions & 0 deletions ferrix-model-api/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,53 @@ fn data_to_py(datatype: String, contents: TensorData, py: pyo3::Python<'_>) -> P
_ => todo!(),
}
}

#[cfg(test)]
mod tests {
use pyo3::{prepare_freethreaded_python, Py, Python, ToPyObject};

use crate::python::PyParameter;

use super::Parameter;

fn setup() {
prepare_freethreaded_python();
}

#[test]
fn test_parameter_to_py() {
setup();

Python::with_gil(|py| {
let result = Parameter {
bool_param: None,
str_param: Some("blah".to_string()),
float_param: None,
int_param: None,
}
.to_object(py);

assert_eq!(
result
.getattr(py, "str_param")
.unwrap()
.extract::<Option<String>>(py)
.unwrap(),
Some("blah".to_string())
)
})
}

#[test]
fn test_parameter_from_py() {
setup();

Python::with_gil(|py| {
let py_parameter = Py::new(py, PyParameter::new(None, None, None, Some(true))).unwrap();
let extracted = py_parameter.extract::<Parameter>(py);

assert!(extracted.is_ok());
assert!(extracted.unwrap().bool_param.unwrap());
});
}
}
2 changes: 0 additions & 2 deletions ferrix-python-hooks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ pub fn postprocess(input: InferResponse) -> InferResponse {
mod tests {
use std::collections::HashMap;

use ferrix_protos::model_infer_request::InferInputTensor;

use super::*;

#[test]
Expand Down

0 comments on commit 22594af

Please sign in to comment.