@@ -226,3 +226,89 @@ pub fn value_from_py_object<'py>(
226226 } ;
227227 Ok ( result)
228228}
229+
230+
231+ #[ cfg( test) ]
232+ mod tests {
233+ use super :: * ;
234+ use crate :: base:: { schema, value} ;
235+ use pyo3:: Python ;
236+ use std:: sync:: Arc ;
237+
238+ #[ test]
239+ fn test_roundtrip_basic_values ( ) {
240+ Python :: with_gil ( |py| {
241+ // Test Int64
242+ let int_value = value:: Value :: Basic ( value:: BasicValue :: Int64 ( 42 ) ) ;
243+ let int_type = schema:: ValueType :: Basic ( schema:: BasicValueType :: Int64 ) ;
244+ let py_obj = value_to_py_object ( py, & int_value) . unwrap ( ) ;
245+ let roundtrip_value = value_from_py_object ( & int_type, & py_obj) . unwrap ( ) ;
246+ assert_eq ! ( int_value, roundtrip_value, "Int64 roundtrip failed" ) ;
247+
248+ // Test String
249+ let str_value = value:: Value :: Basic ( value:: BasicValue :: Str ( Arc :: from ( "test string" ) ) ) ;
250+ let str_type = schema:: ValueType :: Basic ( schema:: BasicValueType :: Str ) ;
251+ let py_obj = value_to_py_object ( py, & str_value) . unwrap ( ) ;
252+ let roundtrip_value = value_from_py_object ( & str_type, & py_obj) . unwrap ( ) ;
253+ assert_eq ! ( str_value, roundtrip_value, "String roundtrip failed" ) ;
254+
255+ // Test Bool
256+ let bool_value = value:: Value :: Basic ( value:: BasicValue :: Bool ( true ) ) ;
257+ let bool_type = schema:: ValueType :: Basic ( schema:: BasicValueType :: Bool ) ;
258+ let py_obj = value_to_py_object ( py, & bool_value) . unwrap ( ) ;
259+ let roundtrip_value = value_from_py_object ( & bool_type, & py_obj) . unwrap ( ) ;
260+ assert_eq ! ( bool_value, roundtrip_value, "Bool roundtrip failed" ) ;
261+ } ) ;
262+ }
263+
264+ #[ test]
265+ fn test_roundtrip_struct ( ) {
266+ Python :: with_gil ( |py| {
267+ // Create a struct schema with multiple fields
268+ let struct_schema = schema:: StructSchema {
269+ description : Some ( Arc :: from ( "Test struct" ) ) ,
270+ fields : Arc :: new ( vec ! [
271+ schema:: FieldSchema {
272+ name: "id" . into( ) ,
273+ value_type: schema:: EnrichedValueType {
274+ typ: schema:: ValueType :: Basic ( schema:: BasicValueType :: Int64 ) ,
275+ nullable: false ,
276+ attrs: Default :: default ( ) ,
277+ } ,
278+ } ,
279+ schema:: FieldSchema {
280+ name: "name" . into( ) ,
281+ value_type: schema:: EnrichedValueType {
282+ typ: schema:: ValueType :: Basic ( schema:: BasicValueType :: Str ) ,
283+ nullable: false ,
284+ attrs: Default :: default ( ) ,
285+ } ,
286+ } ,
287+ schema:: FieldSchema {
288+ name: "active" . into( ) ,
289+ value_type: schema:: EnrichedValueType {
290+ typ: schema:: ValueType :: Basic ( schema:: BasicValueType :: Bool ) ,
291+ nullable: false ,
292+ attrs: Default :: default ( ) ,
293+ } ,
294+ } ,
295+ ] ) ,
296+ } ;
297+
298+ // Create a struct value matching the schema
299+ let struct_value = value:: Value :: Struct ( value:: FieldValues {
300+ fields : vec ! [
301+ value:: Value :: Basic ( value:: BasicValue :: Int64 ( 1 ) ) ,
302+ value:: Value :: Basic ( value:: BasicValue :: Str ( Arc :: from( "test" ) ) ) ,
303+ value:: Value :: Basic ( value:: BasicValue :: Bool ( true ) ) ,
304+ ] ,
305+ } ) ;
306+
307+ // Perform roundtrip conversion
308+ let struct_type = schema:: ValueType :: Struct ( struct_schema) ;
309+ let py_obj = value_to_py_object ( py, & struct_value) . unwrap ( ) ;
310+ let roundtrip_value = value_from_py_object ( & struct_type, & py_obj) . unwrap ( ) ;
311+ assert_eq ! ( struct_value, roundtrip_value, "Struct roundtrip failed" ) ;
312+ } ) ;
313+ }
314+ }
0 commit comments