]> granicus.if.org Git - python/commitdiff
Merged revisions 81640 via svnmerge from
authorBrian Curtin <brian.curtin@gmail.com>
Tue, 1 Jun 2010 13:42:48 +0000 (13:42 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Tue, 1 Jun 2010 13:42:48 +0000 (13:42 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81640 | brian.curtin | 2010-06-01 08:29:13 -0500 (Tue, 01 Jun 2010) | 3 lines

  Fix #8618. Ask the Windows mixer API if there are any playback devices
  configured before attempting to test PlaySound.
........

Lib/test/test_winsound.py

index eff7229bd99c12c16e537d17484c0ae27817a0c7..de444220c6e11530a63e1416d6247dcb072158b3 100644 (file)
@@ -2,15 +2,23 @@
 
 import unittest
 from test import test_support
-import winsound, time
+import time
 import os
 import subprocess
+import ctypes
+
+winsound = test_support.import_module('winsound')
 import _winreg
 
 
 def has_sound(sound):
     """Find out if a particular event is configured with a default sound"""
     try:
+        # Ask the mixer API for the number of devices it knows about.
+        # When there are no devices, PlaySound will fail.
+        if ctypes.windll.winmm.mixerGetNumDevs() is 0:
+            return False
+
         key = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
                 "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
         value = _winreg.EnumValue(key, 0)[1]