@@ -570,48 +570,61 @@ def open_writer(self):
570570 self .addCleanup (self ._close , w )
571571 return w
572572
573- def test_setnchannels_rejects_nonpositive (self ):
573+ def test_get (self ):
574574 w = self .open_writer ()
575- with self .assertRaisesRegex (wave .Error , 'bad # of channels' ):
576- w .setnchannels (0 )
575+ self .assertEqual (w .getformat (), wave .WAVE_FORMAT_PCM )
576+ self .assertEqual (w .getnframes (), 0 )
577+ # getcomptype() and getcompname() raise AttributeError
578+ # until setcomptype() is called
577579
578- def test_getnchannels_not_set (self ):
579- w = self .open_writer ()
580580 with self .assertRaisesRegex (wave .Error , 'number of channels not set' ):
581581 w .getnchannels ()
582+ with self .assertRaisesRegex (wave .Error , 'sample width not set' ):
583+ w .getsampwidth ()
584+ with self .assertRaisesRegex (wave .Error , 'frame rate not set' ):
585+ w .getframerate ()
586+ with self .assertRaisesRegex (wave .Error , 'not all parameters set' ):
587+ w .getparams ()
588+
589+ def test_set (self ):
590+ w = self .open_writer ()
591+
592+ w .setnchannels (1 )
593+ self .assertEqual (w .getnchannels (), 1 )
594+ with self .assertRaisesRegex (wave .Error , 'bad # of channels' ):
595+ w .setnchannels (0 )
582596
583- def test_setsampwidth_rejects_out_of_range (self ):
597+ w .setsampwidth (2 )
598+ self .assertEqual (w .getsampwidth (), 2 )
584599 for width in (0 , 5 ):
585600 with self .subTest (width = width ):
586- w = self .open_writer ()
587601 with self .assertRaisesRegex (wave .Error , 'bad sample width' ):
588602 w .setsampwidth (width )
589603
590- def test_getsampwidth_not_set ( self ):
591- w = self .open_writer ( )
592- with self .assertRaisesRegex (wave .Error , 'sample width not set ' ):
593- w .getsampwidth ( )
604+ w . setframerate ( 44100 )
605+ self .assertEqual ( w . getframerate (), 44100 )
606+ with self .assertRaisesRegex (wave .Error , 'bad frame rate ' ):
607+ w .setframerate ( 0 )
594608
595- def test_getframerate_not_set (self ):
596- w = self .open_writer ()
597- with self .assertRaisesRegex (wave .Error , 'frame rate not set' ):
598- w .getframerate ()
609+ w .setnframes (10 )
610+ self .assertEqual (w .getnframes (), 0 )
599611
600- def test_setcomptype_rejects_unknown (self ):
601- w = self .open_writer ()
612+ w .setcomptype ('NONE' , 'not compressed' )
613+ self .assertEqual (w .getcomptype (), 'NONE' )
614+ self .assertEqual (w .getcompname (), 'not compressed' )
602615 with self .assertRaisesRegex (wave .Error , 'unsupported compression type' ):
603616 w .setcomptype ('ADPCM' , 'unsupported' )
604617
605- def test_setformat_rejects_unknown ( self ):
606- w = self .open_writer ( )
618+ w . setformat ( wave . WAVE_FORMAT_PCM )
619+ self .assertEqual ( w . getformat (), wave . WAVE_FORMAT_PCM )
607620 with self .assertRaisesRegex (wave .Error , 'unsupported wave format' ):
608621 w .setformat (0x1234 )
609622
610- def test_getparams_incomplete ( self ):
611- w = self .open_writer ()
612- w . setnchannels ( 1 )
613- with self .assertRaisesRegex (wave .Error , 'not all parameters set ' ):
614- w .getparams ( )
623+ w . setparams (( 1 , 2 , 44100 , 0 , 'NONE' , 'not compressed' ))
624+ self .assertEqual ( w . getparams (),
625+ ( 1 , 2 , 44100 , 0 , 'NONE' , 'not compressed' ) )
626+ with self .assertRaisesRegex (wave .Error , 'bad # of channels ' ):
627+ w .setparams (( 0 , 2 , 44100 , 0 , 'NONE' , 'not compressed' ) )
615628
616629 def test_tell (self ):
617630 def check_nframes (nframes ):
0 commit comments