Skip to content

Commit

Permalink
clear up test_from_py_with
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-konovalenko committed Feb 18, 2021
1 parent 05f9457 commit c958aad
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions tests/test_frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,13 @@ fn test_err_rename() {
);
}

fn to_string(obj: &PyAny) -> PyResult<String> {
Ok(obj.str()?.to_str()?.to_string())
}

#[derive(Debug, FromPyObject)]
pub struct Zap {
#[pyo3(item)]
name: String,

#[pyo3(from_py_with = "to_string", item("my_object"))]
some_object: String,
#[pyo3(from_py_with = "PyAny::len", item("my_object"))]
some_object_length: usize,
}

#[test]
Expand All @@ -327,6 +323,6 @@ fn test_from_py_with() {
let zap = Zap::extract(py_zap).unwrap();

assert_eq!(zap.name, "whatever");
assert_eq!(zap.some_object, "[1, 2, 3]");
assert_eq!(zap.some_object_length, 3usize);
});
}

0 comments on commit c958aad

Please sign in to comment.