Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85798)

Unified Diff: Lib/test/test_wave.py

Issue 17616: wave.Wave_read and wave.Wave_write can be context managers
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/wave.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_wave.py Mon Apr 01 17:43:30 2013 -0400
+++ b/Lib/test/test_wave.py Tue Apr 02 12:10:40 2013 +0300
@@ -58,6 +58,23 @@
output = b'\0' * nframes * nchannels * sampwidth
self.f.writeframes(output)
+ 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') as fout:
+ pass
+ self.assertEqual(testfile.closed, False)
+
def test_main():
run_unittest(TestWave)
« no previous file with comments | « no previous file | Lib/wave.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+