@@ -516,34 +516,77 @@ def test_nested_return_specific_properties(
516516 assert out .properties ["nested" ] == expected
517517
518518
519- def test_nested_return_generic_properties (collection_factory : CollectionFactory ) -> None :
520- class Child (TypedDict ):
521- name : str
522- age : int
519+ class Child (TypedDict ):
520+ name : str
521+ age : int
523522
524- class Parent (TypedDict ):
525- child : Nested [Child ]
526523
527- collection = collection_factory (
528- properties = [
529- Property (
530- name = "child" ,
531- data_type = DataType .OBJECT ,
532- nested_properties = [
533- Property (
534- name = "name" ,
535- data_type = DataType .TEXT ,
536- ),
537- Property (
538- name = "age" ,
539- data_type = DataType .INT ,
540- ),
524+ @pytest .mark .parametrize (
525+ "data_model_cls,data_object,properties" ,
526+ [
527+ (
528+ Child ,
529+ {"name" : "Timmy" , "age" : 10 },
530+ [
531+ Property (name = "name" , data_type = DataType .TEXT ),
532+ Property (name = "age" , data_type = DataType .INT ),
533+ ],
534+ ),
535+ (
536+ TypedDict ("ParentWithChild" , {"name" : str , "age" : int , "child" : Nested [Child ]}),
537+ {
538+ "name" : "Bob" ,
539+ "age" : 39 ,
540+ "child" : {"name" : "Timmy" , "age" : 10 },
541+ },
542+ [
543+ Property (name = "name" , data_type = DataType .TEXT ),
544+ Property (name = "age" , data_type = DataType .INT ),
545+ Property (
546+ name = "child" ,
547+ data_type = DataType .OBJECT ,
548+ nested_properties = [
549+ Property (name = "name" , data_type = DataType .TEXT ),
550+ Property (name = "age" , data_type = DataType .INT ),
551+ ],
552+ ),
553+ ],
554+ ),
555+ (
556+ TypedDict (
557+ "ParentWithChildList" , {"name" : str , "age" : int , "children" : Nested [list [Child ]]}
558+ ),
559+ {
560+ "name" : "Bob" ,
561+ "age" : 39 ,
562+ "children" : [
563+ {"name" : "Timmy" , "age" : 10 },
564+ {"name" : "Daisy" , "age" : 8 },
541565 ],
542- )
543- ],
544- data_model_properties = Parent ,
566+ },
567+ [
568+ Property (name = "name" , data_type = DataType .TEXT ),
569+ Property (name = "age" , data_type = DataType .INT ),
570+ Property (
571+ name = "children" ,
572+ data_type = DataType .OBJECT_ARRAY ,
573+ nested_properties = [
574+ Property (name = "name" , data_type = DataType .TEXT ),
575+ Property (name = "age" , data_type = DataType .INT ),
576+ ],
577+ ),
578+ ],
579+ ),
580+ ],
581+ )
582+ def test_nested_return_generic_properties (
583+ collection_factory , data_model_cls , data_object , properties
584+ ):
585+ collection = collection_factory (
586+ properties = properties ,
587+ data_model_properties = data_model_cls ,
545588 )
589+ collection .data .insert (data_object )
590+ results = collection .query .fetch_objects (return_properties = data_model_cls )
546591
547- collection .data .insert (Parent (child = Child (name = "Timmy" , age = 10 )))
548- results = collection .query .fetch_objects (return_properties = Parent )
549- assert results .objects [0 ].properties ["child" ] == {"name" : "Timmy" , "age" : 10 }
592+ assert results .objects [0 ].properties == data_object
0 commit comments