@@ -53,6 +53,16 @@ def test_vlarray_roundtrip(contiguous, urlpath):
5353 expected [- 1 ] = "tiny"
5454 vlarray [1 ] = expected [1 ]
5555 vlarray [- 1 ] = expected [- 1 ]
56+ assert vlarray .insert (0 , "head" ) == len (expected ) + 1
57+ expected .insert (0 , "head" )
58+ assert vlarray .insert (- 1 , {"between" : 5 }) == len (expected ) + 1
59+ expected .insert (- 1 , {"between" : 5 })
60+ assert vlarray .insert (999 , "tail" ) == len (expected ) + 1
61+ expected .insert (999 , "tail" )
62+ assert vlarray .delete (2 ) == len (expected ) - 1
63+ del expected [2 ]
64+ del vlarray [- 2 ]
65+ del expected [- 2 ]
5666 assert list (vlarray ) == expected
5767
5868 if urlpath is not None :
@@ -63,6 +73,18 @@ def test_vlarray_roundtrip(contiguous, urlpath):
6373 reopened .append ("nope" )
6474 with pytest .raises (ValueError ):
6575 reopened [0 ] = "nope"
76+ with pytest .raises (ValueError ):
77+ reopened .insert (0 , "nope" )
78+ with pytest .raises (ValueError ):
79+ reopened .delete (0 )
80+ with pytest .raises (ValueError ):
81+ del reopened [0 ]
82+ with pytest .raises (ValueError ):
83+ reopened .extend (["nope" ])
84+ with pytest .raises (ValueError ):
85+ reopened .pop ()
86+ with pytest .raises (ValueError ):
87+ reopened .clear ()
6688
6789 reopened_rw = blosc2 .open (urlpath , mode = "a" )
6890 reopened_rw [0 ] = "changed"
@@ -79,28 +101,32 @@ def test_vlarray_roundtrip(contiguous, urlpath):
79101
80102def test_vlarray_from_cframe ():
81103 vlarray = blosc2 .VLArray ()
82- for value in VALUES [:4 ]:
83- vlarray .append (value )
104+ vlarray .extend (VALUES )
105+ vlarray .insert (1 , {"inserted" : True })
106+ del vlarray [3 ]
107+ expected = list (VALUES )
108+ expected .insert (1 , {"inserted" : True })
109+ del expected [3 ]
84110
85111 restored = blosc2 .from_cframe (vlarray .to_cframe ())
86112 assert isinstance (restored , blosc2 .VLArray )
87- assert list (restored ) == VALUES [: 4 ]
113+ assert list (restored ) == expected
88114
89115 restored2 = blosc2 .vlarray_from_cframe (vlarray .to_cframe ())
90116 assert isinstance (restored2 , blosc2 .VLArray )
91- assert list (restored2 ) == VALUES [: 4 ]
117+ assert list (restored2 ) == expected
92118
93119
94120def test_vlarray_constructor_kwargs ():
95121 urlpath = "test_vlarray_kwargs.b2frame"
96122 blosc2 .remove_urlpath (urlpath )
97123
98124 vlarray = blosc2 .VLArray (urlpath = urlpath , mode = "w" , contiguous = True )
99- for value in VALUES [: 3 ] :
125+ for value in VALUES :
100126 vlarray .append (value )
101127
102128 reopened = blosc2 .VLArray (urlpath = urlpath , mode = "r" , contiguous = True , mmap_mode = "r" )
103- assert list (reopened ) == VALUES [: 3 ]
129+ assert list (reopened ) == VALUES
104130
105131 blosc2 .remove_urlpath (urlpath )
106132
@@ -110,3 +136,52 @@ def test_vlarray_size_guard(monkeypatch):
110136 monkeypatch .setattr (blosc2 , "MAX_BUFFERSIZE" , 4 )
111137 with pytest .raises (ValueError , match = "Serialized objects cannot be larger" ):
112138 vlarray .append ("payload" )
139+
140+
141+ @pytest .mark .parametrize (
142+ ("contiguous" , "urlpath" ),
143+ [
144+ (False , None ),
145+ (True , None ),
146+ (True , "test_vlarray_list_ops.b2frame" ),
147+ (False , "test_vlarray_list_ops_s.b2frame" ),
148+ ],
149+ )
150+ def test_vlarray_list_like_ops (contiguous , urlpath ):
151+ blosc2 .remove_urlpath (urlpath )
152+
153+ vlarray = blosc2 .VLArray (storage = _storage (contiguous , urlpath ))
154+ vlarray .extend ([1 , 2 , 3 ])
155+ assert list (vlarray ) == [1 , 2 , 3 ]
156+ assert vlarray .pop () == 3
157+ assert vlarray .pop (0 ) == 1
158+ assert list (vlarray ) == [2 ]
159+
160+ vlarray .clear ()
161+ assert len (vlarray ) == 0
162+ assert list (vlarray ) == []
163+
164+ vlarray .extend (["a" , "b" ])
165+ assert list (vlarray ) == ["a" , "b" ]
166+
167+ if urlpath is not None :
168+ reopened = blosc2 .open (urlpath , mode = "r" )
169+ assert list (reopened ) == ["a" , "b" ]
170+
171+ blosc2 .remove_urlpath (urlpath )
172+
173+
174+ def test_vlarray_insert_delete_errors ():
175+ vlarray = blosc2 .VLArray ()
176+ vlarray .append ("value" )
177+
178+ with pytest .raises (TypeError ):
179+ vlarray .insert ("0" , "bad" )
180+ with pytest .raises (IndexError ):
181+ vlarray .delete (3 )
182+ with pytest .raises (NotImplementedError ):
183+ vlarray .delete (slice (0 , 1 ))
184+ with pytest .raises (IndexError ):
185+ blosc2 .VLArray ().pop ()
186+ with pytest .raises (NotImplementedError ):
187+ vlarray .pop (slice (0 , 1 ))
0 commit comments