summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_wave.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-07-31 17:46:08 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-07-31 17:46:08 (GMT)
commitc91d5eea106d191e931f953bdbdb1db25e051767 (patch)
tree4ddd0a8c329fc2fb9cc8a78900704829b889a303 /Lib/test/test_wave.py
parent0ce642ebca5f4d0e1b6875b845ad0eb8cb76bbb4 (diff)
downloadcpython-c91d5eea106d191e931f953bdbdb1db25e051767.zip
cpython-c91d5eea106d191e931f953bdbdb1db25e051767.tar.gz
cpython-c91d5eea106d191e931f953bdbdb1db25e051767.tar.bz2
#17616: wave.open now supports the 'with' statement.
Feature and tests by ClClaudiu.Popa, I added the doc changes.
Diffstat (limited to 'Lib/test/test_wave.py')
-rw-r--r--Lib/test/test_wave.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py
index 581d973..e9ee15c 100644
--- a/Lib/test/test_wave.py
+++ b/Lib/test/test_wave.py
@@ -1,7 +1,5 @@
-from test.support import TESTFN, run_unittest
-import os
+from test.support import TESTFN, unlink
import wave
-import struct
import unittest
nchannels = 2
@@ -17,10 +15,7 @@ class TestWave(unittest.TestCase):
def tearDown(self):
if self.f is not None:
self.f.close()
- try:
- os.remove(TESTFN)
- except OSError:
- pass
+ unlink(TESTFN)
def test_it(self, test_rounding=False):
self.f = wave.open(TESTFN, 'wb')
@@ -74,9 +69,23 @@ class TestWave(unittest.TestCase):
self.assertEqual(params.comptype, self.f.getcomptype())
self.assertEqual(params.compname, self.f.getcompname())
+ def test_context_manager(self):
+ self.f = wave.open(TESTFN, 'wb')
+ self.f.setnchannels(nchannels)
+ self.f.setsampwidth(sampwidth)
+ self.f.setframerate(framerate)
+ self.f.close()
+
+ with wave.open(TESTFN) as f:
+ self.assertFalse(f.getfp().closed)
+ self.assertIs(f.getfp(), None)
+
+ with open(TESTFN, 'wb') as testfile:
+ with self.assertRaises(wave.Error):
+ with wave.open(testfile, 'wb'):
+ pass
+ self.assertEqual(testfile.closed, False)
-def test_main():
- run_unittest(TestWave)
if __name__ == '__main__':
- test_main()
+ unittest.main()