@@ -189,20 +189,31 @@ def test_setparams_7_tuple_uses_format(self):
189189 self .addCleanup (unlink , filename )
190190
191191 with wave .open (filename , 'wb' ) as w :
192- w .setparams ((1 , 2 , 22050 , 0 , 'NONE' , 'not compressed' ,
192+ w .setparams ((1 , 4 , 22050 , 0 , 'NONE' , 'not compressed' ,
193193 wave .WAVE_FORMAT_IEEE_FLOAT ))
194194 self .assertEqual (w .getformat (), wave .WAVE_FORMAT_IEEE_FLOAT )
195195
196+ def test_setparams_7_tuple_ieee_64bit_sampwidth (self ):
197+ with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
198+ filename = fp .name
199+ self .addCleanup (unlink , filename )
200+
201+ with wave .open (filename , 'wb' ) as w :
202+ w .setparams ((1 , 8 , 22050 , 0 , 'NONE' , 'not compressed' ,
203+ wave .WAVE_FORMAT_IEEE_FLOAT ))
204+ self .assertEqual (w .getformat (), wave .WAVE_FORMAT_IEEE_FLOAT )
205+ self .assertEqual (w .getsampwidth (), 8 )
206+
196207 def test_getparams_backward_compatible_shape (self ):
197208 with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
198209 filename = fp .name
199210 self .addCleanup (unlink , filename )
200211
201212 with wave .open (filename , 'wb' ) as w :
202- w .setparams ((1 , 2 , 22050 , 0 , 'NONE' , 'not compressed' ,
213+ w .setparams ((1 , 4 , 22050 , 0 , 'NONE' , 'not compressed' ,
203214 wave .WAVE_FORMAT_IEEE_FLOAT ))
204215 params = w .getparams ()
205- self .assertEqual (params , (1 , 2 , 22050 , 0 , 'NONE' , 'not compressed' ))
216+ self .assertEqual (params , (1 , 4 , 22050 , 0 , 'NONE' , 'not compressed' ))
206217
207218 def test_getformat_setformat (self ):
208219 with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
@@ -211,12 +222,51 @@ def test_getformat_setformat(self):
211222
212223 with wave .open (filename , 'wb' ) as w :
213224 w .setnchannels (1 )
214- w .setsampwidth (2 )
225+ w .setsampwidth (4 )
215226 w .setframerate (22050 )
216227 self .assertEqual (w .getformat (), wave .WAVE_FORMAT_PCM )
217228 w .setformat (wave .WAVE_FORMAT_IEEE_FLOAT )
218229 self .assertEqual (w .getformat (), wave .WAVE_FORMAT_IEEE_FLOAT )
219230
231+ def test_setformat_ieee_requires_32_or_64_bit_sampwidth (self ):
232+ with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
233+ filename = fp .name
234+ self .addCleanup (unlink , filename )
235+
236+ with wave .open (filename , 'wb' ) as w :
237+ w .setnchannels (1 )
238+ w .setsampwidth (2 )
239+ w .setframerate (22050 )
240+ with self .assertRaisesRegex (wave .Error ,
241+ 'unsupported sample width for IEEE float format' ):
242+ w .setformat (wave .WAVE_FORMAT_IEEE_FLOAT )
243+
244+ def test_setsampwidth_ieee_requires_32_or_64_bit (self ):
245+ with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
246+ filename = fp .name
247+ self .addCleanup (unlink , filename )
248+
249+ with wave .open (filename , 'wb' ) as w :
250+ w .setnchannels (1 )
251+ w .setframerate (22050 )
252+ w .setformat (wave .WAVE_FORMAT_IEEE_FLOAT )
253+ with self .assertRaisesRegex (wave .Error ,
254+ 'unsupported sample width for IEEE float format' ):
255+ w .setsampwidth (2 )
256+ w .setsampwidth (4 )
257+
258+ def test_setsampwidth_ieee_accepts_64_bit (self ):
259+ with tempfile .NamedTemporaryFile (delete_on_close = False ) as fp :
260+ filename = fp .name
261+ self .addCleanup (unlink , filename )
262+
263+ with wave .open (filename , 'wb' ) as w :
264+ w .setnchannels (1 )
265+ w .setframerate (22050 )
266+ w .setformat (wave .WAVE_FORMAT_IEEE_FLOAT )
267+ w .setsampwidth (8 )
268+ self .assertEqual (w .getsampwidth (), 8 )
269+
220270 def test_read_getformat (self ):
221271 b = b'RIFF' + struct .pack ('<L' , 36 ) + b'WAVE'
222272 b += b'fmt ' + struct .pack ('<LHHLLHH' , 16 , 1 , 1 , 11025 , 11025 , 1 , 8 )
@@ -297,10 +347,10 @@ def test_ieee_float_has_fact_chunk(self):
297347
298348 with wave .open (filename , 'wb' ) as w :
299349 w .setnchannels (1 )
300- w .setsampwidth (2 )
350+ w .setsampwidth (4 )
301351 w .setframerate (22050 )
302352 w .setformat (wave .WAVE_FORMAT_IEEE_FLOAT )
303- w .writeframes (b'\x00 \x00 ' * nframes )
353+ w .writeframes (b'\x00 \x00 \x00 \x00 ' * nframes )
304354
305355 with open (filename , 'rb' ) as f :
306356 f .read (12 )
0 commit comments