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 ,
910)
1011import numpy as np
@@ -48,6 +49,7 @@ def test_box_basics():
4849 object .doubles_list = [99.1999 , 88.2888 , 77.3777 , 66.4666 , 55.6597555 ]
4950 object .date = time .time () * 1000 # milliseconds since UNIX epoch
5051 object .date_nano = time .time_ns () # nanoseconds since UNIX epoch
52+ object .flex = dict (a = 1 , b = 2 , c = 3 )
5153 object .transient = "abcd"
5254
5355 id = box .put (object )
@@ -174,3 +176,74 @@ def test_datetime():
174176 box .get (1 )
175177
176178 ob .close ()
179+
180+
181+ def 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+
190+ ob = load_empty_test_objectbox ()
191+ box = objectbox .Box (ob , TestEntity )
192+ object = TestEntity ()
193+
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 )
200+
201+ # Update to int
202+ test_put_get (object , box , 1 )
203+
204+ # Update to float
205+ test_put_get (object , box , 1.2 )
206+
207+ # Update to string
208+ test_put_get (object , box , "foo" )
209+
210+ # Update to int list
211+ test_put_get (object , box , [1 , 2 , 3 ])
212+
213+ # Update to float list
214+ test_put_get (object , box , [1.1 , 2.2 , 3.3 ])
215+
216+ # Update to dict
217+ test_put_get (object , box , {"a" : 1 , "b" : 2 })
218+
219+ # Update to bool
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 ]})
227+
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+ # Put an empty object
237+ id = box .put (object )
238+ assert id == object .id
239+ read = box .get (object .id )
240+ assert read .flex_dict == None
241+ assert read .flex_int == None
242+
243+ object .flex_dict = {"a" : 1 , "b" : 2 }
244+ object .flex_int = 25
245+ id = box .put (object )
246+ assert id == object .id
247+ read = box .get (object .id )
248+ assert read .flex_dict == object .flex_dict
249+ assert read .flex_int == object .flex_int
0 commit comments