MCPcopy Create free account
hub / github.com/davidhewitt/pythonize / test_ser

Function test_ser

src/ser.rs:726–750  ·  view source on GitHub ↗
(src: T, expected: &str)

Source from the content-addressed store, hash-verified

724 use serde::Serialize;
725
726 fn test_ser<T>(src: T, expected: &str)
727 where
728 T: Serialize,
729 {
730 Python::attach(|py| -> PyResult<()> {
731 let obj = pythonize(py, &src)?;
732
733 let locals = PyDict::new(py);
734 locals.set_item("obj", obj)?;
735
736 py.run(
737 c"import json; result = json.dumps(obj, separators=(',', ':'))",
738 None,
739 Some(&locals),
740 )?;
741 let result = locals.get_item("result")?.unwrap();
742 let result = result.extract::<PyBackedStr>()?;
743
744 assert_eq!(result, expected);
745 assert_eq!(serde_json::to_string(&src).unwrap(), expected);
746
747 Ok(())
748 })
749 .unwrap();
750 }
751
752 #[test]
753 fn test_empty_struct() {

Callers 15

test_empty_structFunction · 0.85
test_structFunction · 0.85
test_nested_structFunction · 0.85
test_tuple_structFunction · 0.85
test_tupleFunction · 0.85
test_vecFunction · 0.85
test_mapFunction · 0.85
test_enum_unit_variantFunction · 0.85
test_enum_tuple_variantFunction · 0.85
test_enum_struct_variantFunction · 0.85
test_integersFunction · 0.85

Calls 1

pythonizeFunction · 0.85

Tested by

no test coverage detected