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

Delta Between Two Patch Sets: Lib/test/test_sunau.py

Issue 18878: Add support of the 'with' statement to sunau.open.
Left Patch Set: Created 6 years, 9 months ago
Right Patch Set: Created 6 years, 9 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/sunau.py ('k') | Misc/NEWS » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from test.support import TESTFN, unlink 1 from test.support import TESTFN, unlink
2 import unittest 2 import unittest
3 import pickle
3 import os 4 import os
4 5
5 import sunau 6 import sunau
6 7
7 nchannels = 2 8 nchannels = 2
8 sampwidth = 2 9 sampwidth = 2
9 framerate = 8000 10 framerate = 8000
10 nframes = 100 11 nframes = 100
11 12
12 class SunAUTest(unittest.TestCase): 13 class SunAUTest(unittest.TestCase):
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 53
53 self.f = sunau.open(TESTFN, 'rb') 54 self.f = sunau.open(TESTFN, 'rb')
54 self.assertEqual(nchannels, self.f.getnchannels()) 55 self.assertEqual(nchannels, self.f.getnchannels())
55 self.assertEqual(sampwidth, self.f.getsampwidth()) 56 self.assertEqual(sampwidth, self.f.getsampwidth())
56 self.assertEqual(framerate, self.f.getframerate()) 57 self.assertEqual(framerate, self.f.getframerate())
57 self.assertEqual(nframes, self.f.getnframes()) 58 self.assertEqual(nframes, self.f.getnframes())
58 self.assertEqual('ULAW', self.f.getcomptype()) 59 self.assertEqual('ULAW', self.f.getcomptype())
59 self.assertEqual(self.f.readframes(nframes), output) 60 self.assertEqual(self.f.readframes(nframes), output)
60 self.f.close() 61 self.f.close()
61 62
63 def test_getparams(self):
64 self.f = sunau.open(TESTFN, 'w')
65 self.f.setnchannels(nchannels)
66 self.f.setsampwidth(sampwidth)
67 self.f.setframerate(framerate)
68 self.f.setcomptype('ULAW', '')
69 output = b'\0' * nframes * nchannels * sampwidth
70 self.f.writeframes(output)
71 self.f.close()
72
73 self.f = sunau.open(TESTFN, 'rb')
74 params = self.f.getparams()
75 self.assertEqual(params.nchannels, nchannels)
76 self.assertEqual(params.sampwidth, sampwidth)
77 self.assertEqual(params.framerate, framerate)
78 self.assertEqual(params.nframes, nframes)
79 self.assertEqual(params.comptype, 'ULAW')
80
81 dump = pickle.dumps(params)
82 self.assertEqual(pickle.loads(dump), params)
83
62 def test_write_context_manager_calls_close(self): 84 def test_write_context_manager_calls_close(self):
63 # Close checks for a minimum header and will raise an error 85 # Close checks for a minimum header and will raise an error
64 # if it is not set, so this proves that close is called. 86 # if it is not set, so this proves that close is called.
65 with self.assertRaises(sunau.Error): 87 with self.assertRaises(sunau.Error):
66 with sunau.open(TESTFN, 'wb') as f: 88 with sunau.open(TESTFN, 'wb') as f:
67 pass 89 pass
68 with self.assertRaises(sunau.Error): 90 with self.assertRaises(sunau.Error):
69 with open(TESTFN, 'wb') as testfile: 91 with open(TESTFN, 'wb') as testfile:
70 with sunau.open(testfile): 92 with sunau.open(testfile):
71 pass 93 pass
(...skipping 24 matching lines...) Expand all
96 f.setframerate(framerate) 118 f.setframerate(framerate)
97 with sunau.open(TESTFN) as f: 119 with sunau.open(TESTFN) as f:
98 self.assertFalse(f.getfp().closed) 120 self.assertFalse(f.getfp().closed)
99 params = f.getparams() 121 params = f.getparams()
100 self.assertEqual(params[0], nchannels) 122 self.assertEqual(params[0], nchannels)
101 self.assertEqual(params[1], sampwidth) 123 self.assertEqual(params[1], sampwidth)
102 self.assertEqual(params[2], framerate) 124 self.assertEqual(params[2], framerate)
103 self.assertIsNone(f.getfp()) 125 self.assertIsNone(f.getfp())
104 126
105 127
106 if __name__ == '__main__': 128 if __name__ == "__main__":
107 unittest.main() 129 unittest.main()
LEFTRIGHT

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