@@ -103,3 +103,59 @@ def test_context_manager_from_disk(storage, config, start_storage, tmpdir, tmpfi
103103
104104 del da
105105 del da2
106+
107+
108+ @pytest .mark .parametrize (
109+ 'storage, config' ,
110+ [
111+ ('memory' , None ),
112+ ('weaviate' , {'n_dim' : 3 , 'distance' : 'l2-squared' }),
113+ ('annlite' , {'n_dim' : 3 , 'metric' : 'Euclidean' }),
114+ ('qdrant' , {'n_dim' : 3 , 'distance' : 'euclidean' }),
115+ ('elasticsearch' , {'n_dim' : 3 , 'distance' : 'l2_norm' }),
116+ ('sqlite' , dict ()),
117+ ],
118+ )
119+ @pytest .mark .parametrize (
120+ 'index' , [1 , '1' , slice (1 , 2 ), [1 ], [False , True , False , False , False ]]
121+ )
122+ def test_del_and_append (index , storage , config ):
123+ da = DocumentArray (storage = storage , config = config )
124+
125+ with da :
126+ da .extend ([Document (id = str (i )) for i in range (5 )])
127+ with da :
128+ del da [index ]
129+ da .append (Document (id = 'new' ))
130+
131+ assert da [:, 'id' ] == ['0' , '2' , '3' , '4' , 'new' ]
132+
133+
134+ @pytest .mark .parametrize (
135+ 'index' , [1 , '1' , slice (1 , 2 ), [1 ], [False , True , False , False , False ]]
136+ )
137+ @pytest .mark .parametrize (
138+ 'storage, config' ,
139+ [
140+ ('memory' , None ),
141+ ('weaviate' , {'n_dim' : 3 , 'distance' : 'l2-squared' }),
142+ ('annlite' , {'n_dim' : 3 , 'metric' : 'Euclidean' }),
143+ ('qdrant' , {'n_dim' : 3 , 'distance' : 'euclidean' }),
144+ ('elasticsearch' , {'n_dim' : 3 , 'distance' : 'l2_norm' }),
145+ ('sqlite' , dict ()),
146+ ],
147+ )
148+ def test_set_and_append (index , storage , config ):
149+ da = DocumentArray (storage = storage , config = config )
150+
151+ with da :
152+ da .extend ([Document (id = str (i )) for i in range (5 )])
153+ with da :
154+ da [index ] = (
155+ Document (id = 'new' )
156+ if isinstance (index , int ) or isinstance (index , str )
157+ else [Document (id = 'new' )]
158+ )
159+ da .append (Document (id = 'new_new' ))
160+
161+ assert da [:, 'id' ] == ['0' , 'new' , '2' , '3' , '4' , 'new_new' ]
0 commit comments