Add test to ensure support for from_py_with for enums
This commit is contained in:
parent
10804b0d65
commit
84a763da14
|
@ -501,3 +501,23 @@ fn test_from_py_with_tuple_struct() {
|
|||
assert_eq!(zap.1, 3usize);
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPyObject, PartialEq)]
|
||||
pub enum ZapEnum {
|
||||
Zip(#[pyo3(from_py_with = "PyAny::len")] usize),
|
||||
Zap(String, #[pyo3(from_py_with = "PyAny::len")] usize),
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_py_with_enum() {
|
||||
Python::with_gil(|py| {
|
||||
let py_zap = py
|
||||
.eval(r#"("whatever", [1, 2, 3])"#, None, None)
|
||||
.expect("failed to create dict");
|
||||
|
||||
let zap = ZapEnum::extract(py_zap).unwrap();
|
||||
let expected_zap = ZapEnum::Zap(String::from("whatever"), 3usize);
|
||||
|
||||
assert_eq!(zap, expected_zap);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue