Skip to content

Commit

Permalink
release: 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Aug 24, 2022
1 parent ba1d0ec commit 8d49643
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.17.0 - 2022-08-24

- Update to PyO3 0.17

## 0.16.0 - 2022-03-06

- Update to PyO3 0.16
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pythonize"
version = "0.16.0"
version = "0.17.0"
authors = ["David Hewitt <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -12,10 +12,10 @@ documentation = "https://docs.rs/crate/pythonize/"

[dependencies]
serde = { version = "1.0", default-features = false, features = ["std"] }
pyo3 = { version = "0.16.3", default-features = false }
pyo3 = { version = "0.17.0", default-features = false }

[dev-dependencies]
serde = { version = "1.0", default-features = false, features = ["derive"] }
pyo3 = { version = "0.16.3", default-features = false, features = ["auto-initialize", "macros", "pyproto"] }
pyo3 = { version = "0.17.0", default-features = false, features = ["auto-initialize", "macros"] }
serde_json = "1.0"
maplit = "1.0.2"
60 changes: 30 additions & 30 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,16 @@ mod test {
where
T: de::DeserializeOwned + PartialEq + std::fmt::Debug,
{
let gil = Python::acquire_gil();
let py = gil.python();
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
let actual: T = depythonize(obj).unwrap();
assert_eq!(&actual, expected);
let actual_json: JsonValue = depythonize(obj).unwrap();
assert_eq!(&actual_json, expected_json);
Python::with_gil(|py| {
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
let actual: T = depythonize(obj).unwrap();
assert_eq!(&actual, expected);
let actual_json: JsonValue = depythonize(obj).unwrap();
assert_eq!(&actual_json, expected_json);
});
}

#[test]
Expand Down Expand Up @@ -489,16 +489,16 @@ mod test {

let code = "{'foo': 'Foo'}";

let gil = Python::acquire_gil();
let py = gil.python();
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
assert!(matches!(
*depythonize::<Struct>(obj).unwrap_err().inner,
ErrorImpl::Message(msg) if msg == "missing field `bar`"
));
Python::with_gil(|py| {
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
assert!(matches!(
*depythonize::<Struct>(obj).unwrap_err().inner,
ErrorImpl::Message(msg) if msg == "missing field `bar`"
));
})
}

#[test]
Expand All @@ -519,16 +519,16 @@ mod test {

let code = "('cat', -10.05, 'foo')";

let gil = Python::acquire_gil();
let py = gil.python();
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
assert!(matches!(
*depythonize::<TupleStruct>(obj).unwrap_err().inner,
ErrorImpl::IncorrectSequenceLength { expected, got } if expected == 2 && got == 3
));
Python::with_gil(|py| {
let locals = PyDict::new(py);
py.run(&format!("obj = {}", code), None, Some(locals))
.unwrap();
let obj = locals.get_item("obj").unwrap();
assert!(matches!(
*depythonize::<TupleStruct>(obj).unwrap_err().inner,
ErrorImpl::IncorrectSequenceLength { expected, got } if expected == 2 && got == 3
));
})
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pythonize::{
};
use serde_json::{json, Value};

#[pyclass]
#[pyclass(sequence)]
struct CustomList {
items: Vec<PyObject>,
}
Expand Down Expand Up @@ -62,6 +62,7 @@ impl PythonizeTypes for PythonizeCustomList {
#[test]
fn test_custom_list() {
Python::with_gil(|py| {
PySequence::register::<CustomList>(py).unwrap();
let serialized = pythonize_custom::<PythonizeCustomList, _>(py, &json!([1, 2, 3]))
.unwrap()
.into_ref(py);
Expand Down Expand Up @@ -125,6 +126,7 @@ impl PythonizeTypes for PythonizeCustomDict {
#[test]
fn test_custom_dict() {
Python::with_gil(|py| {
PyMapping::register::<CustomDict>(py).unwrap();
let serialized =
pythonize_custom::<PythonizeCustomDict, _>(py, &json!({ "hello": 1, "world": 2 }))
.unwrap()
Expand Down

0 comments on commit 8d49643

Please sign in to comment.