[Python-checkins] r61242 - python/trunk/Lib/test/test_winsound.py

neal.norwitz python-checkins at python.org
Wed Mar 5 06:14:18 CET 2008


Author: neal.norwitz
Date: Wed Mar  5 06:14:18 2008
New Revision: 61242

Modified:
   python/trunk/Lib/test/test_winsound.py
Log:
Get this test to pass even when there is no sound card in the system.
Patch from Trent Nelson.  (I can't test this.)


Modified: python/trunk/Lib/test/test_winsound.py
==============================================================================
--- python/trunk/Lib/test/test_winsound.py	(original)
+++ python/trunk/Lib/test/test_winsound.py	Wed Mar  5 06:14:18 2008
@@ -8,6 +8,13 @@
 
 
 class BeepTest(unittest.TestCase):
+    # As with PlaySoundTest, incorporate the _have_soundcard() check
+    # into our test methods.  If there's no audio device present,
+    # winsound.Beep returns 0 and GetLastError() returns 127, which
+    # is: ERROR_PROC_NOT_FOUND ("The specified procedure could not
+    # be found").  (FWIW, virtual/Hyper-V systems fall under this
+    # scenario as they have no sound devices whatsoever  (not even
+    # a legacy Beep device).)
 
     def test_errors(self):
         self.assertRaises(TypeError, winsound.Beep)
@@ -15,12 +22,17 @@
         self.assertRaises(ValueError, winsound.Beep, 32768, 75)
 
     def test_extremes(self):
-        winsound.Beep(37, 75)
-        winsound.Beep(32767, 75)
+        if _have_soundcard():
+            winsound.Beep(37, 75)
+            winsound.Beep(32767, 75)
+        else:
+            self.assertRaises(RuntimeError, winsound.Beep, 37, 75)
+            self.assertRaises(RuntimeError, winsound.Beep, 32767, 75)
 
     def test_increasingfrequency(self):
-        for i in xrange(100, 2000, 100):
-            winsound.Beep(i, 75)
+        if _have_soundcard():
+            for i in xrange(100, 2000, 100):
+                winsound.Beep(i, 75)
 
 class MessageBeepTest(unittest.TestCase):
 


More information about the Python-checkins mailing list