<s> import unittest <EOL> from test import test_support <EOL> import winsound , time <EOL> import os <EOL> import subprocess <EOL> class BeepTest ( unittest . TestCase ) : <EOL> def test_errors ( self ) : <EOL> self . assertRaises ( TypeError , winsound . Beep ) <EOL> self . assertRaises ( ValueError , winsound . Beep , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertRaises ( ValueError , winsound . Beep , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_extremes ( self ) : <EOL> winsound . Beep ( <NUM_LIT> , <NUM_LIT> ) <EOL> winsound . Beep ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_increasingfrequency ( self ) : <EOL> for i in xrange ( <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT:100> ) : <EOL> winsound . Beep ( i , <NUM_LIT> ) <EOL> class MessageBeepTest ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> def test_default ( self ) : <EOL> self . assertRaises ( TypeError , winsound . MessageBeep , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , winsound . MessageBeep , <NUM_LIT> , <NUM_LIT> ) <EOL> winsound . MessageBeep ( ) <EOL> def test_ok ( self ) : <EOL> winsound . MessageBeep ( winsound . MB_OK ) <EOL> def test_asterisk ( self ) : <EOL> winsound . MessageBeep ( winsound . MB_ICONASTERISK ) <EOL> def test_exclamation ( self ) : <EOL> winsound . MessageBeep ( winsound . MB_ICONEXCLAMATION ) <EOL> def test_hand ( self ) : <EOL> winsound . MessageBeep ( winsound . MB_ICONHAND ) <EOL> def test_question ( self ) : <EOL> winsound . MessageBeep ( winsound . MB_ICONQUESTION ) <EOL> class PlaySoundTest ( unittest . TestCase ) : <EOL> def test_errors ( self ) : <EOL> self . assertRaises ( TypeError , winsound . PlaySound ) <EOL> self . assertRaises ( TypeError , winsound . PlaySound , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> "<STR_LIT:none>" , winsound . SND_ASYNC | winsound . SND_MEMORY <EOL> ) <EOL> def test_alias_asterisk ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( '<STR_LIT>' , winsound . SND_ALIAS ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS <EOL> ) <EOL> def test_alias_exclamation ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( '<STR_LIT>' , winsound . SND_ALIAS ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS <EOL> ) <EOL> def test_alias_exit ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( '<STR_LIT>' , winsound . SND_ALIAS ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS <EOL> ) <EOL> def test_alias_hand ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( '<STR_LIT>' , winsound . SND_ALIAS ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS <EOL> ) <EOL> def test_alias_question ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( '<STR_LIT>' , winsound . SND_ALIAS ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS <EOL> ) <EOL> def test_alias_fallback ( self ) : <EOL> return <EOL> def test_alias_nofallback ( self ) : <EOL> if _have_soundcard ( ) : <EOL> try : <EOL> winsound . PlaySound ( <EOL> '<STR_LIT>' , <EOL> winsound . SND_ALIAS | winsound . SND_NODEFAULT <EOL> ) <EOL> except RuntimeError : <EOL> pass <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> '<STR_LIT>' , winsound . SND_ALIAS | winsound . SND_NODEFAULT <EOL> ) <EOL> def test_stopasync ( self ) : <EOL> if _have_soundcard ( ) : <EOL> winsound . PlaySound ( <EOL> '<STR_LIT>' , <EOL> winsound . SND_ALIAS | winsound . SND_ASYNC | winsound . SND_LOOP <EOL> ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> try : <EOL> winsound . PlaySound ( <EOL> '<STR_LIT>' , <EOL> winsound . SND_ALIAS | winsound . SND_NOSTOP <EOL> ) <EOL> except RuntimeError : <EOL> pass <EOL> else : <EOL> pass <EOL> winsound . PlaySound ( None , winsound . SND_PURGE ) <EOL> else : <EOL> self . assertRaises ( <EOL> RuntimeError , <EOL> winsound . PlaySound , <EOL> None , winsound . SND_PURGE <EOL> ) <EOL> def _get_cscript_path ( ) : <EOL> """<STR_LIT>""" <EOL> for dir in os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) . split ( os . pathsep ) : <EOL> cscript_path = os . path . join ( dir , "<STR_LIT>" ) <EOL> if os . path . exists ( cscript_path ) : <EOL> return cscript_path <EOL> __have_soundcard_cache = None <EOL> def _have_soundcard ( ) : <EOL> """<STR_LIT>""" <EOL> global __have_soundcard_cache <EOL> if __have_soundcard_cache is None : <EOL> cscript_path = _get_cscript_path ( ) <EOL> if cscript_path is None : <EOL> return True <EOL> check_script = os . path . join ( os . path . dirname ( __file__ ) , <EOL> "<STR_LIT>" ) <EOL> p = subprocess . Popen ( [ cscript_path , check_script ] , <EOL> stdout = subprocess . PIPE ) <EOL> __have_soundcard_cache = not p . wait ( ) <EOL> return __have_soundcard_cache <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( BeepTest , MessageBeepTest , PlaySoundTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
