Merged revisions 80026 via svnmerge from
authorBrian Curtin <brian.curtin@gmail.com>
Tue, 13 Apr 2010 02:39:59 +0000 (02:39 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Tue, 13 Apr 2010 02:39:59 +0000 (02:39 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80026 | brian.curtin | 2010-04-12 21:25:20 -0500 (Mon, 12 Apr 2010) | 4 lines

  Fix #7306. Add skips to test_winsound when no default sound is configured.

  These failures occur on a Windows Server 2003 machine I test on.
........

Lib/test/test_winsound.py

index 7858f120e9af52cbb6a6287ea2ee673fd836cbc8..877d03fc0d328c1c42f46525121204a91dd9a485 100644 (file)
@@ -5,8 +5,22 @@ from test import test_support
 import winsound, time
 import os
 import subprocess
+import _winreg
 
 
+def has_sound(sound):
+    """Find out if a particular event is configured with a default sound"""
+    try:
+        key = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
+                "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
+        value = _winreg.EnumValue(key, 0)[1]
+        if value is not u"":
+            return True
+        else:
+            return False
+    except WindowsError:
+        return False
+
 class BeepTest(unittest.TestCase):
     # As with PlaySoundTest, incorporate the _have_soundcard() check
     # into our test methods.  If there's no audio device present,
@@ -81,6 +95,7 @@ class PlaySoundTest(unittest.TestCase):
             "none", winsound.SND_ASYNC | winsound.SND_MEMORY
         )
 
+    @unittest.skipUnless(has_sound("SystemAsterisk"), "No default SystemAsterisk")
     def test_alias_asterisk(self):
         if _have_soundcard():
             winsound.PlaySound('SystemAsterisk', winsound.SND_ALIAS)
@@ -91,6 +106,7 @@ class PlaySoundTest(unittest.TestCase):
                 'SystemAsterisk', winsound.SND_ALIAS
             )
 
+    @unittest.skipUnless(has_sound("SystemExclamation"), "No default SystemExclamation")
     def test_alias_exclamation(self):
         if _have_soundcard():
             winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
@@ -101,6 +117,7 @@ class PlaySoundTest(unittest.TestCase):
                 'SystemExclamation', winsound.SND_ALIAS
             )
 
+    @unittest.skipUnless(has_sound("SystemExit"), "No default SystemExit")
     def test_alias_exit(self):
         if _have_soundcard():
             winsound.PlaySound('SystemExit', winsound.SND_ALIAS)
@@ -111,6 +128,7 @@ class PlaySoundTest(unittest.TestCase):
                 'SystemExit', winsound.SND_ALIAS
             )
 
+    @unittest.skipUnless(has_sound("SystemHand"), "No default SystemHand")
     def test_alias_hand(self):
         if _have_soundcard():
             winsound.PlaySound('SystemHand', winsound.SND_ALIAS)
@@ -121,6 +139,7 @@ class PlaySoundTest(unittest.TestCase):
                 'SystemHand', winsound.SND_ALIAS
             )
 
+    @unittest.skipUnless(has_sound("SystemQuestion"), "No default SystemQuestion")
     def test_alias_question(self):
         if _have_soundcard():
             winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)