()
| 1050 | |
| 1051 | #[test] |
| 1052 | fn test_dataclass() { |
| 1053 | let code = c"\ |
| 1054 | from dataclasses import dataclass |
| 1055 | |
| 1056 | @dataclass |
| 1057 | class Point: |
| 1058 | x: int |
| 1059 | y: int |
| 1060 | |
| 1061 | point = Point(1, 2)"; |
| 1062 | |
| 1063 | #[derive(Debug, Deserialize, PartialEq)] |
| 1064 | struct Point { |
| 1065 | x: i32, |
| 1066 | y: i32, |
| 1067 | } |
| 1068 | |
| 1069 | let expected = Point { x: 1, y: 2 }; |
| 1070 | let expected_json = json!({"x": 1, "y": 2}); |
| 1071 | |
| 1072 | Python::attach(|py| { |
| 1073 | let locals = PyDict::new(py); |
| 1074 | py.run(code, None, Some(&locals)).unwrap(); |
| 1075 | let obj = locals.get_item("point").unwrap().unwrap(); |
| 1076 | test_de_with_obj(&obj, &expected, &expected_json); |
| 1077 | |
| 1078 | let map: HashMap<String, i32> = depythonize(&obj).unwrap(); |
| 1079 | assert_eq!(map.len(), 2); |
| 1080 | assert_eq!(*map.get("x").unwrap(), 1); |
| 1081 | assert_eq!(*map.get("y").unwrap(), 2); |
| 1082 | }); |
| 1083 | } |
| 1084 | |
| 1085 | #[test] |
| 1086 | fn test_dataclass_missing_field() { |
nothing calls this directly
no test coverage detected