@@ -433,30 +433,30 @@ def test_setframerate_rounds(self, arg, expected):
433433
434434 @support .subTests ('nchannels' , (0 , - 1 ))
435435 def test_setnchannels_error_includes_value (self , nchannels ):
436+ msg = re .escape (f'bad # of channels: { nchannels !r} ' )
436437 with wave .open (io .BytesIO (), 'wb' ) as f :
437- with self .assertRaisesRegex (wave .Error ,
438- re .escape (f'bad # of channels: { nchannels !r} ' )):
438+ with self .assertRaisesRegex (wave .Error , msg ):
439439 f .setnchannels (nchannels )
440440 with self .assertRaises (wave .Error ):
441441 f .close ()
442442
443443 @support .subTests ('sampwidth' , (0 , 5 ))
444444 def test_setsampwidth_error_includes_value (self , sampwidth ):
445+ msg = re .escape (f'bad sample width: { sampwidth !r} ' )
445446 with wave .open (io .BytesIO (), 'wb' ) as f :
446447 f .setnchannels (1 )
447- with self .assertRaisesRegex (wave .Error ,
448- re .escape (f'bad sample width: { sampwidth !r} ' )):
448+ with self .assertRaisesRegex (wave .Error , msg ):
449449 f .setsampwidth (sampwidth )
450450 with self .assertRaises (wave .Error ):
451451 f .close ()
452452
453453 @support .subTests ('arg' , (- 1 , 0 , 0.4 ))
454454 def test_setframerate_error_includes_value (self , arg ):
455+ msg = re .escape (f'bad frame rate: { arg !r} ' )
455456 with wave .open (io .BytesIO (), 'wb' ) as f :
456457 f .setnchannels (1 )
457458 f .setsampwidth (2 )
458- with self .assertRaisesRegex (wave .Error ,
459- re .escape (f'bad frame rate: { arg !r} ' )):
459+ with self .assertRaisesRegex (wave .Error , msg ):
460460 f .setframerate (arg )
461461 with self .assertRaises (wave .Error ):
462462 f .close ()
0 commit comments