summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_winsound.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2003-05-18 00:47:47 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2003-05-18 00:47:47 (GMT)
commit7fd9424230f51bda20507a85deda7be80c4cb507 (patch)
tree7ed7749655b980f70113d19526de4533176e5eb0 /Lib/test/test_winsound.py
parenta2792bec1ddfc3f5e38f202de8bc5ca9db4bb869 (diff)
downloadcpython-7fd9424230f51bda20507a85deda7be80c4cb507.zip
cpython-7fd9424230f51bda20507a85deda7be80c4cb507.tar.gz
cpython-7fd9424230f51bda20507a85deda7be80c4cb507.tar.bz2
Port test_array and test_winsound to PyUnit. Enhance tests for array
(code coverage for Modules/arraymodule.c is at 91%) From SF patch #736962.
Diffstat (limited to 'Lib/test/test_winsound.py')
-rw-r--r--Lib/test/test_winsound.py114
1 files changed, 99 insertions, 15 deletions
diff --git a/Lib/test/test_winsound.py b/Lib/test/test_winsound.py
index be0b471..def8c87 100644
--- a/Lib/test/test_winsound.py
+++ b/Lib/test/test_winsound.py
@@ -1,18 +1,102 @@
# Ridiculously simple test of the winsound module for Windows.
+import unittest
+from test import test_support
import winsound, time
-for i in range(100, 2000, 100):
- winsound.Beep(i, 75)
-print "Hopefully you heard some sounds increasing in frequency!"
-winsound.MessageBeep()
-time.sleep(0.5)
-winsound.MessageBeep(winsound.MB_OK)
-time.sleep(0.5)
-winsound.MessageBeep(winsound.MB_ICONASTERISK)
-time.sleep(0.5)
-winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
-time.sleep(0.5)
-winsound.MessageBeep(winsound.MB_ICONHAND)
-time.sleep(0.5)
-winsound.MessageBeep(winsound.MB_ICONQUESTION)
-time.sleep(0.5)
+
+class BeepTest(unittest.TestCase):
+
+ def test_errors(self):
+ self.assertRaises(TypeError, winsound.Beep)
+ self.assertRaises(ValueError, winsound.Beep, 36, 75)
+ self.assertRaises(ValueError, winsound.Beep, 32768, 75)
+
+ def test_extremes(self):
+ winsound.Beep(37, 75)
+ winsound.Beep(32767, 75)
+
+ def test_increasingfrequency(self):
+ for i in xrange(100, 2000, 100):
+ winsound.Beep(i, 75)
+
+class MessageBeepTest(unittest.TestCase):
+
+ def tearDown(self):
+ time.sleep(0.5)
+
+ def test_default(self):
+ self.assertRaises(TypeError, winsound.MessageBeep, "bad")
+ self.assertRaises(TypeError, winsound.MessageBeep, 42, 42)
+ winsound.MessageBeep()
+
+ def test_ok(self):
+ winsound.MessageBeep(winsound.MB_OK)
+
+ def test_asterisk(self):
+ winsound.MessageBeep(winsound.MB_ICONASTERISK)
+
+ def test_exclamation(self):
+ winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
+
+ def test_hand(self):
+ winsound.MessageBeep(winsound.MB_ICONHAND)
+
+ def test_question(self):
+ winsound.MessageBeep(winsound.MB_ICONQUESTION)
+
+class PlaySoundTest(unittest.TestCase):
+
+ def test_errors(self):
+ self.assertRaises(TypeError, winsound.PlaySound)
+ self.assertRaises(TypeError, winsound.PlaySound, "bad", "bad")
+ self.assertRaises(
+ RuntimeError,
+ winsound.PlaySound,
+ "none", winsound.SND_ASYNC | winsound.SND_MEMORY
+ )
+
+ def test_alias_asterisk(self):
+ winsound.PlaySound('SystemAsterisk', winsound.SND_ALIAS)
+
+ def test_alias_exclamation(self):
+ winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
+
+ def test_alias_exit(self):
+ winsound.PlaySound('SystemExit', winsound.SND_ALIAS)
+
+ def test_alias_hand(self):
+ winsound.PlaySound('SystemHand', winsound.SND_ALIAS)
+
+ def test_alias_question(self):
+ winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)
+
+ def test_alias_fallback(self):
+ winsound.PlaySound('!"$%&/(#+*', winsound.SND_ALIAS)
+
+ def test_alias_nofallback(self):
+ try:
+ winsound.PlaySound(
+ '!"$%&/(#+*',
+ winsound.SND_ALIAS | winsound.SND_NODEFAULT
+ )
+ except RuntimeError:
+ pass
+
+ def test_stopasync(self):
+ winsound.PlaySound(
+ 'SystemQuestion',
+ winsound.SND_ALIAS | winsound.SND_ASYNC | winsound.SND_LOOP
+ )
+ time.sleep(0.5)
+ self.assertRaises(
+ RuntimeError,
+ winsound.PlaySound,
+ 'SystemQuestion', winsound.SND_ALIAS | winsound.SND_NOSTOP
+ )
+ winsound.PlaySound(None, winsound.SND_PURGE)
+
+def test_main():
+ test_support.run_unittest(BeepTest, MessageBeepTest, PlaySoundTest)
+
+if __name__=="__main__":
+ test_main()