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

Side by Side 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
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | Lib/wave.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test.support import TESTFN, run_unittest 1 from test.support import TESTFN, run_unittest
2 import os 2 import os
3 import wave 3 import wave
4 import struct 4 import struct
5 import unittest 5 import unittest
6 6
7 nchannels = 2 7 nchannels = 2
8 sampwidth = 2 8 sampwidth = 2
9 framerate = 8000 9 framerate = 8000
10 nframes = 100 10 nframes = 100
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 self.test_it(test_rounding=True) 50 self.test_it(test_rounding=True)
51 51
52 def test_issue7681(self): 52 def test_issue7681(self):
53 self.f = wave.open(TESTFN, 'wb') 53 self.f = wave.open(TESTFN, 'wb')
54 self.f.setnchannels(nchannels) 54 self.f.setnchannels(nchannels)
55 self.f.setsampwidth(sampwidth) 55 self.f.setsampwidth(sampwidth)
56 self.f.setframerate(framerate) 56 self.f.setframerate(framerate)
57 # Don't call setnframes, make _write_header divide to figure it out 57 # Don't call setnframes, make _write_header divide to figure it out
58 output = b'\0' * nframes * nchannels * sampwidth 58 output = b'\0' * nframes * nchannels * sampwidth
59 self.f.writeframes(output) 59 self.f.writeframes(output)
60
61 def test_context_manager(self):
62 self.f = wave.open(TESTFN, 'wb')
63 self.f.setnchannels(nchannels)
64 self.f.setsampwidth(sampwidth)
65 self.f.setframerate(framerate)
66 self.f.close()
67
68 with wave.open(TESTFN) as f:
69 self.assertFalse(f.getfp().closed)
70 self.assertIs(f.getfp(), None)
71
72 with open(TESTFN, 'wb') as testfile:
73 with self.assertRaises(wave.Error):
74 with wave.open(testfile, 'wb') as fout:
75 pass
76 self.assertEqual(testfile.closed, False)
60 77
61 78
62 def test_main(): 79 def test_main():
63 run_unittest(TestWave) 80 run_unittest(TestWave)
64 81
65 if __name__ == '__main__': 82 if __name__ == '__main__':
66 test_main() 83 test_main()
OLDNEW
« 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+