@@ -207,38 +207,42 @@ def test_open_in_write_raises(self):
207207 support .gc_collect ()
208208 self .assertIsNone (cm .unraisable )
209209
210- def test_setframerate_rounds_then_validates (self ):
211- """Test that setframerate rounds before validation"""
212- # Test that framerates that round to 0 or negative are rejected
210+ @support .subTests ('arg' , (
211+ # rounds to 0, should raise:
212+ 0.5 ,
213+ 0.4 ,
214+ # Negative values should still raise:
215+ - 1 ,
216+ - 0.5 ,
217+ - 0.4 ,
218+ # 0 should raise:
219+ 0 ,
220+ ))
221+ def test_setframerate_validates_rounded_values (self , arg ):
222+ """Test that setframerate that round to 0 or negative are rejected"""
213223 with wave .open (io .BytesIO (), 'wb' ) as f :
214224 f .setnchannels (1 )
215225 f .setsampwidth (2 )
216- # 0.5 rounds to 0, should raise
217226 with self .assertRaises (wave .Error ):
218- f .setframerate (0.5 )
219- # 0.4 rounds to 0, should raise
227+ f .setframerate (arg )
220228 with self .assertRaises (wave .Error ):
221- f .setframerate (0.4 )
222- # Negative values should still raise
223- with self .assertRaises (wave .Error ):
224- f .setframerate (- 1 )
225- with self .assertRaises (wave .Error ):
226- f .setframerate (- 0.5 )
227- # 0 should raise
228- with self .assertRaises (wave .Error ):
229- f .setframerate (0 )
230-
231- # Valid values that round to positive integers should work
232- f .setframerate (1.4 ) # rounds to 1
233- self .assertEqual (f .getframerate (), 1 )
234- f .setframerate (1.5 ) # rounds to 2
235- self .assertEqual (f .getframerate (), 2 )
236- f .setframerate (1.6 ) # rounds to 2
237- self .assertEqual (f .getframerate (), 2 )
238- f .setframerate (44100.4 ) # rounds to 44100
239- self .assertEqual (f .getframerate (), 44100 )
240- f .setframerate (44100.5 ) # rounds to 44100
241- self .assertEqual (f .getframerate (), 44100 )
229+ f .close ()
230+
231+ @support .subTests (('arg' , 'expected' ), (
232+ (1.4 , 1 ),
233+ (1.5 , 2 ),
234+ (1.6 , 2 ),
235+ (44100.4 , 44100 ),
236+ (44100.5 , 44100 ),
237+ (44100.6 , 44101 ),
238+ ))
239+ def test_setframerate_rounds (self , arg , expected ):
240+ """Test that setframerate is rounded"""
241+ with wave .open (io .BytesIO (), 'wb' ) as f :
242+ f .setnchannels (1 )
243+ f .setsampwidth (2 )
244+ f .setframerate (arg )
245+ self .assertEqual (f .getframerate (), expected )
242246
243247
244248class WaveOpen (unittest .TestCase ):
0 commit comments