11import pytest
22import objectbox
3- from tests .model import TestEntity , TestEntityDatetime
3+ from tests .model import TestEntity , TestEntityDatetime , TestEntityFlex
44from tests .common import (
55 autocleanup ,
66 load_empty_test_objectbox ,
77 load_empty_test_datetime ,
8+ load_empty_test_flex ,
89 assert_equal ,
9- put_flex ,
1010)
1111import numpy as np
1212from datetime import datetime
@@ -179,32 +179,64 @@ def test_datetime():
179179
180180
181181def test_flex ():
182+
183+ def test_put_get (object : TestEntity , box : objectbox .Box , property ):
184+ object .flex = property
185+ id = box .put (object )
186+ assert id == object .id
187+ read = box .get (object .id )
188+ assert read .flex == object .flex
189+
182190 ob = load_empty_test_objectbox ()
183191 box = objectbox .Box (ob , TestEntity )
184192 object = TestEntity ()
185193
186- # Put a None type first
187- put_flex (object , box , None )
194+ # Put an empty object
195+ id = box .put (object )
196+ assert id == object .id
197+
198+ # Put a None type object
199+ test_put_get (object , box , None )
188200
189201 # Update to int
190- put_flex (object , box , 1 )
202+ test_put_get (object , box , 1 )
191203
192204 # Update to float
193- put_flex (object , box , 1.2 )
205+ test_put_get (object , box , 1.2 )
194206
195207 # Update to string
196- put_flex (object , box , "foo" )
208+ test_put_get (object , box , "foo" )
197209
198210 # Update to int list
199- put_flex (object , box , [1 , 2 , 3 ])
211+ test_put_get (object , box , [1 , 2 , 3 ])
200212
201213 # Update to float list
202- put_flex (object , box , [1.1 , 2.2 , 3.3 ])
214+ test_put_get (object , box , [1.1 , 2.2 , 3.3 ])
203215
204216 # Update to dict
205- put_flex (object , box , {"a" : 1 , "b" : 2 })
217+ test_put_get (object , box , {"a" : 1 , "b" : 2 })
206218
207219 # Update to bool
208- put_flex (object , box , True )
220+ test_put_get (object , box , True )
221+
222+ # Update to dict inside dict
223+ test_put_get (object , box , {"a" : 1 , "b" : {"c" : 2 }})
224+
225+ # Update to list inside dict
226+ test_put_get (object , box , {"a" : 1 , "b" : [1 , 2 , 3 ]})
209227
210- ob .close ()
228+ ob .close ()
229+
230+
231+ def test_flex_dict ():
232+ ob = load_empty_test_flex ()
233+ box = objectbox .Box (ob , TestEntityFlex )
234+ object = TestEntityFlex ()
235+
236+ object .flex_dict = {"a" : 1 , "b" : 2 }
237+ object .flex_int = 25
238+ id = box .put (object )
239+ assert id == object .id
240+ read = box .get (object .id )
241+ assert read .flex_dict == object .flex_dict
242+ assert read .flex_int == object .flex_int
0 commit comments