Skip to content

Commit dade974

Browse files
committed
Add test for PythonizeListType impl for PyTuple
1 parent aa8f2ab commit dade974

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/test_custom_types.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use pyo3::{
44
exceptions::{PyIndexError, PyKeyError},
55
prelude::*,
6-
types::{PyDict, PyList, PyMapping, PySequence},
6+
types::{PyDict, PyMapping, PySequence, PyTuple},
77
};
88
use pythonize::{
99
depythonize, pythonize_custom, PythonizeListType, PythonizeMappingType, PythonizeTypes,
@@ -134,7 +134,7 @@ struct PythonizeCustomDict;
134134
impl PythonizeTypes for PythonizeCustomDict {
135135
type Map = CustomDict;
136136
type NamedMap = PythonizeUnnamedMappingWrapper<CustomDict>;
137-
type List = PyList;
137+
type List = PyTuple;
138138
}
139139

140140
#[test]
@@ -151,6 +151,19 @@ fn test_custom_dict() {
151151
})
152152
}
153153

154+
#[test]
155+
fn test_tuple() {
156+
Python::with_gil(|py| {
157+
PyMapping::register::<CustomDict>(py).unwrap();
158+
let serialized =
159+
pythonize_custom::<PythonizeCustomDict, _>(py, &json!([1, 2, 3, 4])).unwrap();
160+
assert!(serialized.is_instance_of::<PyTuple>());
161+
162+
let deserialized: Value = depythonize(&serialized).unwrap();
163+
assert_eq!(deserialized, json!([1, 2, 3, 4]));
164+
})
165+
}
166+
154167
#[test]
155168
fn test_pythonizer_can_be_created() {
156169
// https://github.com/davidhewitt/pythonize/pull/56

0 commit comments

Comments
 (0)