1 | n/a | from test.support import findfile, TESTFN, unlink |
---|
2 | n/a | import unittest |
---|
3 | n/a | from test import audiotests |
---|
4 | n/a | from audioop import byteswap |
---|
5 | n/a | import io |
---|
6 | n/a | import sys |
---|
7 | n/a | import struct |
---|
8 | n/a | import aifc |
---|
9 | n/a | |
---|
10 | n/a | |
---|
11 | n/a | class AifcTest(audiotests.AudioWriteTests, |
---|
12 | n/a | audiotests.AudioTestsWithSourceFile): |
---|
13 | n/a | module = aifc |
---|
14 | n/a | close_fd = True |
---|
15 | n/a | test_unseekable_read = None |
---|
16 | n/a | |
---|
17 | n/a | |
---|
18 | n/a | class AifcPCM8Test(AifcTest, unittest.TestCase): |
---|
19 | n/a | sndfilename = 'pluck-pcm8.aiff' |
---|
20 | n/a | sndfilenframes = 3307 |
---|
21 | n/a | nchannels = 2 |
---|
22 | n/a | sampwidth = 1 |
---|
23 | n/a | framerate = 11025 |
---|
24 | n/a | nframes = 48 |
---|
25 | n/a | comptype = b'NONE' |
---|
26 | n/a | compname = b'not compressed' |
---|
27 | n/a | frames = bytes.fromhex("""\ |
---|
28 | n/a | 02FF 4B00 3104 8008 CB06 4803 BF01 03FE B8FA B4F3 29EB 1AE6 \ |
---|
29 | n/a | EDE4 C6E2 0EE0 EFE0 57E2 FBE8 13EF D8F7 97FB F5FC 08FB DFFB \ |
---|
30 | n/a | 11FA 3EFB BCFC 66FF CF04 4309 C10E 5112 EE17 8216 7F14 8012 \ |
---|
31 | n/a | 490E 520D EF0F CE0F E40C 630A 080A 2B0B 510E 8B11 B60E 440A \ |
---|
32 | n/a | """) |
---|
33 | n/a | |
---|
34 | n/a | |
---|
35 | n/a | class AifcPCM16Test(AifcTest, unittest.TestCase): |
---|
36 | n/a | sndfilename = 'pluck-pcm16.aiff' |
---|
37 | n/a | sndfilenframes = 3307 |
---|
38 | n/a | nchannels = 2 |
---|
39 | n/a | sampwidth = 2 |
---|
40 | n/a | framerate = 11025 |
---|
41 | n/a | nframes = 48 |
---|
42 | n/a | comptype = b'NONE' |
---|
43 | n/a | compname = b'not compressed' |
---|
44 | n/a | frames = bytes.fromhex("""\ |
---|
45 | n/a | 022EFFEA 4B5D00F6 311804EA 80E10840 CBE106B1 48A903F5 BFE601B2 036CFE7B \ |
---|
46 | n/a | B858FA3E B4B1F34F 299AEBCA 1A5DE6DA EDFAE491 C628E275 0E09E0B5 EF2AE029 \ |
---|
47 | n/a | 5758E271 FB35E83F 1376EF86 D82BF727 9790FB76 F5FAFC0F 0867FB9C DF30FB43 \ |
---|
48 | n/a | 117EFA36 3EE5FB5B BC79FCB1 66D9FF5D CF150412 431D097C C1BA0EC8 512112A1 \ |
---|
49 | n/a | EEE21753 82071665 7FFF1443 8004128F 49A20EAF 52BB0DBA EFB40F60 CE3C0FBF \ |
---|
50 | n/a | E4B30CEC 63430A5C 08C80A20 2BBB0B08 514A0E43 8BCF1139 B6F60EEB 44120A5E \ |
---|
51 | n/a | """) |
---|
52 | n/a | |
---|
53 | n/a | |
---|
54 | n/a | class AifcPCM24Test(AifcTest, unittest.TestCase): |
---|
55 | n/a | sndfilename = 'pluck-pcm24.aiff' |
---|
56 | n/a | sndfilenframes = 3307 |
---|
57 | n/a | nchannels = 2 |
---|
58 | n/a | sampwidth = 3 |
---|
59 | n/a | framerate = 11025 |
---|
60 | n/a | nframes = 48 |
---|
61 | n/a | comptype = b'NONE' |
---|
62 | n/a | compname = b'not compressed' |
---|
63 | n/a | frames = bytes.fromhex("""\ |
---|
64 | n/a | 022D65FFEB9D 4B5A0F00FA54 3113C304EE2B 80DCD6084303 \ |
---|
65 | n/a | CBDEC006B261 48A99803F2F8 BFE82401B07D 036BFBFE7B5D \ |
---|
66 | n/a | B85756FA3EC9 B4B055F3502B 299830EBCB62 1A5CA7E6D99A \ |
---|
67 | n/a | EDFA3EE491BD C625EBE27884 0E05A9E0B6CF EF2929E02922 \ |
---|
68 | n/a | 5758D8E27067 FB3557E83E16 1377BFEF8402 D82C5BF7272A \ |
---|
69 | n/a | 978F16FB7745 F5F865FC1013 086635FB9C4E DF30FCFB40EE \ |
---|
70 | n/a | 117FE0FA3438 3EE6B8FB5AC3 BC77A3FCB2F4 66D6DAFF5F32 \ |
---|
71 | n/a | CF13B9041275 431D69097A8C C1BB600EC74E 5120B912A2BA \ |
---|
72 | n/a | EEDF641754C0 8207001664B7 7FFFFF14453F 8000001294E6 \ |
---|
73 | n/a | 499C1B0EB3B2 52B73E0DBCA0 EFB2B20F5FD8 CE3CDB0FBE12 \ |
---|
74 | n/a | E4B49C0CEA2D 6344A80A5A7C 08C8FE0A1FFE 2BB9860B0A0E \ |
---|
75 | n/a | 51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48 \ |
---|
76 | n/a | """) |
---|
77 | n/a | |
---|
78 | n/a | |
---|
79 | n/a | class AifcPCM32Test(AifcTest, unittest.TestCase): |
---|
80 | n/a | sndfilename = 'pluck-pcm32.aiff' |
---|
81 | n/a | sndfilenframes = 3307 |
---|
82 | n/a | nchannels = 2 |
---|
83 | n/a | sampwidth = 4 |
---|
84 | n/a | framerate = 11025 |
---|
85 | n/a | nframes = 48 |
---|
86 | n/a | comptype = b'NONE' |
---|
87 | n/a | compname = b'not compressed' |
---|
88 | n/a | frames = bytes.fromhex("""\ |
---|
89 | n/a | 022D65BCFFEB9D92 4B5A0F8000FA549C 3113C34004EE2BC0 80DCD680084303E0 \ |
---|
90 | n/a | CBDEC0C006B26140 48A9980003F2F8FC BFE8248001B07D92 036BFB60FE7B5D34 \ |
---|
91 | n/a | B8575600FA3EC920 B4B05500F3502BC0 29983000EBCB6240 1A5CA7A0E6D99A60 \ |
---|
92 | n/a | EDFA3E80E491BD40 C625EB80E27884A0 0E05A9A0E0B6CFE0 EF292940E0292280 \ |
---|
93 | n/a | 5758D800E2706700 FB3557D8E83E1640 1377BF00EF840280 D82C5B80F7272A80 \ |
---|
94 | n/a | 978F1600FB774560 F5F86510FC101364 086635A0FB9C4E20 DF30FC40FB40EE28 \ |
---|
95 | n/a | 117FE0A0FA3438B0 3EE6B840FB5AC3F0 BC77A380FCB2F454 66D6DA80FF5F32B4 \ |
---|
96 | n/a | CF13B980041275B0 431D6980097A8C00 C1BB60000EC74E00 5120B98012A2BAA0 \ |
---|
97 | n/a | EEDF64C01754C060 820700001664B780 7FFFFFFF14453F40 800000001294E6E0 \ |
---|
98 | n/a | 499C1B000EB3B270 52B73E000DBCA020 EFB2B2E00F5FD880 CE3CDB400FBE1270 \ |
---|
99 | n/a | E4B49CC00CEA2D90 6344A8800A5A7CA0 08C8FE800A1FFEE0 2BB986C00B0A0E00 \ |
---|
100 | n/a | 51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0 \ |
---|
101 | n/a | """) |
---|
102 | n/a | |
---|
103 | n/a | |
---|
104 | n/a | class AifcULAWTest(AifcTest, unittest.TestCase): |
---|
105 | n/a | sndfilename = 'pluck-ulaw.aifc' |
---|
106 | n/a | sndfilenframes = 3307 |
---|
107 | n/a | nchannels = 2 |
---|
108 | n/a | sampwidth = 2 |
---|
109 | n/a | framerate = 11025 |
---|
110 | n/a | nframes = 48 |
---|
111 | n/a | comptype = b'ulaw' |
---|
112 | n/a | compname = b'' |
---|
113 | n/a | frames = bytes.fromhex("""\ |
---|
114 | n/a | 022CFFE8 497C0104 307C04DC 8284083C CB84069C 497C03DC BE8401AC 036CFE74 \ |
---|
115 | n/a | B684FA24 B684F344 2A7CEC04 19FCE704 EE04E504 C584E204 0E3CE104 EF04DF84 \ |
---|
116 | n/a | 557CE204 FB24E804 12FCEF04 D784F744 9684FB64 F5C4FC24 083CFBA4 DF84FB24 \ |
---|
117 | n/a | 11FCFA24 3E7CFB64 BA84FCB4 657CFF5C CF84041C 417C093C C1840EBC 517C12FC \ |
---|
118 | n/a | EF0416FC 828415FC 7D7C13FC 828412FC 497C0EBC 517C0DBC F0040F3C CD840FFC \ |
---|
119 | n/a | E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \ |
---|
120 | n/a | """) |
---|
121 | n/a | if sys.byteorder != 'big': |
---|
122 | n/a | frames = byteswap(frames, 2) |
---|
123 | n/a | |
---|
124 | n/a | |
---|
125 | n/a | class AifcALAWTest(AifcTest, unittest.TestCase): |
---|
126 | n/a | sndfilename = 'pluck-alaw.aifc' |
---|
127 | n/a | sndfilenframes = 3307 |
---|
128 | n/a | nchannels = 2 |
---|
129 | n/a | sampwidth = 2 |
---|
130 | n/a | framerate = 11025 |
---|
131 | n/a | nframes = 48 |
---|
132 | n/a | comptype = b'alaw' |
---|
133 | n/a | compname = b'' |
---|
134 | n/a | frames = bytes.fromhex("""\ |
---|
135 | n/a | 0230FFE8 4A0000F8 310004E0 82000840 CB0006A0 4A0003F0 BE0001A8 0370FE78 \ |
---|
136 | n/a | BA00FA20 B600F340 2900EB80 1A80E680 ED80E480 C700E280 0E40E080 EF80E080 \ |
---|
137 | n/a | 5600E280 FB20E880 1380EF80 D900F740 9600FB60 F5C0FC10 0840FBA0 DF00FB20 \ |
---|
138 | n/a | 1180FA20 3F00FB60 BE00FCB0 6600FF58 CF000420 42000940 C1000EC0 52001280 \ |
---|
139 | n/a | EE801780 82001680 7E001480 82001280 4A000EC0 52000DC0 EF800F40 CF000FC0 \ |
---|
140 | n/a | E4800CC0 62000A40 08C00A40 2B000B40 52000E40 8A001180 B6000EC0 46000A40 \ |
---|
141 | n/a | """) |
---|
142 | n/a | if sys.byteorder != 'big': |
---|
143 | n/a | frames = byteswap(frames, 2) |
---|
144 | n/a | |
---|
145 | n/a | |
---|
146 | n/a | class AifcMiscTest(audiotests.AudioTests, unittest.TestCase): |
---|
147 | n/a | def test_skipunknown(self): |
---|
148 | n/a | #Issue 2245 |
---|
149 | n/a | #This file contains chunk types aifc doesn't recognize. |
---|
150 | n/a | self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif')) |
---|
151 | n/a | |
---|
152 | n/a | def test_params_added(self): |
---|
153 | n/a | f = self.f = aifc.open(TESTFN, 'wb') |
---|
154 | n/a | f.aiff() |
---|
155 | n/a | f.setparams((1, 1, 1, 1, b'NONE', b'')) |
---|
156 | n/a | f.close() |
---|
157 | n/a | |
---|
158 | n/a | f = self.f = aifc.open(TESTFN, 'rb') |
---|
159 | n/a | params = f.getparams() |
---|
160 | n/a | self.assertEqual(params.nchannels, f.getnchannels()) |
---|
161 | n/a | self.assertEqual(params.sampwidth, f.getsampwidth()) |
---|
162 | n/a | self.assertEqual(params.framerate, f.getframerate()) |
---|
163 | n/a | self.assertEqual(params.nframes, f.getnframes()) |
---|
164 | n/a | self.assertEqual(params.comptype, f.getcomptype()) |
---|
165 | n/a | self.assertEqual(params.compname, f.getcompname()) |
---|
166 | n/a | |
---|
167 | n/a | def test_write_header_comptype_sampwidth(self): |
---|
168 | n/a | for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): |
---|
169 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
170 | n/a | fout.setnchannels(1) |
---|
171 | n/a | fout.setframerate(1) |
---|
172 | n/a | fout.setcomptype(comptype, b'') |
---|
173 | n/a | fout.close() |
---|
174 | n/a | self.assertEqual(fout.getsampwidth(), 2) |
---|
175 | n/a | fout.initfp(None) |
---|
176 | n/a | |
---|
177 | n/a | def test_write_markers_values(self): |
---|
178 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
179 | n/a | self.assertEqual(fout.getmarkers(), None) |
---|
180 | n/a | fout.setmark(1, 0, b'foo1') |
---|
181 | n/a | fout.setmark(1, 1, b'foo2') |
---|
182 | n/a | self.assertEqual(fout.getmark(1), (1, 1, b'foo2')) |
---|
183 | n/a | self.assertEqual(fout.getmarkers(), [(1, 1, b'foo2')]) |
---|
184 | n/a | fout.initfp(None) |
---|
185 | n/a | |
---|
186 | n/a | def test_read_markers(self): |
---|
187 | n/a | fout = self.fout = aifc.open(TESTFN, 'wb') |
---|
188 | n/a | fout.aiff() |
---|
189 | n/a | fout.setparams((1, 1, 1, 1, b'NONE', b'')) |
---|
190 | n/a | fout.setmark(1, 0, b'odd') |
---|
191 | n/a | fout.setmark(2, 0, b'even') |
---|
192 | n/a | fout.writeframes(b'\x00') |
---|
193 | n/a | fout.close() |
---|
194 | n/a | f = self.f = aifc.open(TESTFN, 'rb') |
---|
195 | n/a | self.assertEqual(f.getmarkers(), [(1, 0, b'odd'), (2, 0, b'even')]) |
---|
196 | n/a | self.assertEqual(f.getmark(1), (1, 0, b'odd')) |
---|
197 | n/a | self.assertEqual(f.getmark(2), (2, 0, b'even')) |
---|
198 | n/a | self.assertRaises(aifc.Error, f.getmark, 3) |
---|
199 | n/a | |
---|
200 | n/a | |
---|
201 | n/a | class AIFCLowLevelTest(unittest.TestCase): |
---|
202 | n/a | |
---|
203 | n/a | def test_read_written(self): |
---|
204 | n/a | def read_written(self, what): |
---|
205 | n/a | f = io.BytesIO() |
---|
206 | n/a | getattr(aifc, '_write_' + what)(f, x) |
---|
207 | n/a | f.seek(0) |
---|
208 | n/a | return getattr(aifc, '_read_' + what)(f) |
---|
209 | n/a | for x in (-1, 0, 0.1, 1): |
---|
210 | n/a | self.assertEqual(read_written(x, 'float'), x) |
---|
211 | n/a | for x in (float('NaN'), float('Inf')): |
---|
212 | n/a | self.assertEqual(read_written(x, 'float'), aifc._HUGE_VAL) |
---|
213 | n/a | for x in (b'', b'foo', b'a' * 255): |
---|
214 | n/a | self.assertEqual(read_written(x, 'string'), x) |
---|
215 | n/a | for x in (-0x7FFFFFFF, -1, 0, 1, 0x7FFFFFFF): |
---|
216 | n/a | self.assertEqual(read_written(x, 'long'), x) |
---|
217 | n/a | for x in (0, 1, 0xFFFFFFFF): |
---|
218 | n/a | self.assertEqual(read_written(x, 'ulong'), x) |
---|
219 | n/a | for x in (-0x7FFF, -1, 0, 1, 0x7FFF): |
---|
220 | n/a | self.assertEqual(read_written(x, 'short'), x) |
---|
221 | n/a | for x in (0, 1, 0xFFFF): |
---|
222 | n/a | self.assertEqual(read_written(x, 'ushort'), x) |
---|
223 | n/a | |
---|
224 | n/a | def test_read_raises(self): |
---|
225 | n/a | f = io.BytesIO(b'\x00') |
---|
226 | n/a | self.assertRaises(EOFError, aifc._read_ulong, f) |
---|
227 | n/a | self.assertRaises(EOFError, aifc._read_long, f) |
---|
228 | n/a | self.assertRaises(EOFError, aifc._read_ushort, f) |
---|
229 | n/a | self.assertRaises(EOFError, aifc._read_short, f) |
---|
230 | n/a | |
---|
231 | n/a | def test_write_long_string_raises(self): |
---|
232 | n/a | f = io.BytesIO() |
---|
233 | n/a | with self.assertRaises(ValueError): |
---|
234 | n/a | aifc._write_string(f, b'too long' * 255) |
---|
235 | n/a | |
---|
236 | n/a | def test_wrong_open_mode(self): |
---|
237 | n/a | with self.assertRaises(aifc.Error): |
---|
238 | n/a | aifc.open(TESTFN, 'wrong_mode') |
---|
239 | n/a | |
---|
240 | n/a | def test_read_wrong_form(self): |
---|
241 | n/a | b1 = io.BytesIO(b'WRNG' + struct.pack('>L', 0)) |
---|
242 | n/a | b2 = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'WRNG') |
---|
243 | n/a | self.assertRaises(aifc.Error, aifc.open, b1) |
---|
244 | n/a | self.assertRaises(aifc.Error, aifc.open, b2) |
---|
245 | n/a | |
---|
246 | n/a | def test_read_no_comm_chunk(self): |
---|
247 | n/a | b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF') |
---|
248 | n/a | self.assertRaises(aifc.Error, aifc.open, b) |
---|
249 | n/a | |
---|
250 | n/a | def test_read_wrong_compression_type(self): |
---|
251 | n/a | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
---|
252 | n/a | b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0) |
---|
253 | n/a | b += b'WRNG' + struct.pack('B', 0) |
---|
254 | n/a | self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b)) |
---|
255 | n/a | |
---|
256 | n/a | def test_read_wrong_marks(self): |
---|
257 | n/a | b = b'FORM' + struct.pack('>L', 4) + b'AIFF' |
---|
258 | n/a | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
---|
259 | n/a | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
---|
260 | n/a | b += b'MARK' + struct.pack('>LhB', 3, 1, 1) |
---|
261 | n/a | with self.assertWarns(UserWarning) as cm: |
---|
262 | n/a | f = aifc.open(io.BytesIO(b)) |
---|
263 | n/a | self.assertEqual(str(cm.warning), 'Warning: MARK chunk contains ' |
---|
264 | n/a | 'only 0 markers instead of 1') |
---|
265 | n/a | self.assertEqual(f.getmarkers(), None) |
---|
266 | n/a | |
---|
267 | n/a | def test_read_comm_kludge_compname_even(self): |
---|
268 | n/a | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
---|
269 | n/a | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
---|
270 | n/a | b += b'NONE' + struct.pack('B', 4) + b'even' + b'\x00' |
---|
271 | n/a | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
---|
272 | n/a | with self.assertWarns(UserWarning) as cm: |
---|
273 | n/a | f = aifc.open(io.BytesIO(b)) |
---|
274 | n/a | self.assertEqual(str(cm.warning), 'Warning: bad COMM chunk size') |
---|
275 | n/a | self.assertEqual(f.getcompname(), b'even') |
---|
276 | n/a | |
---|
277 | n/a | def test_read_comm_kludge_compname_odd(self): |
---|
278 | n/a | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
---|
279 | n/a | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
---|
280 | n/a | b += b'NONE' + struct.pack('B', 3) + b'odd' |
---|
281 | n/a | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
---|
282 | n/a | with self.assertWarns(UserWarning) as cm: |
---|
283 | n/a | f = aifc.open(io.BytesIO(b)) |
---|
284 | n/a | self.assertEqual(str(cm.warning), 'Warning: bad COMM chunk size') |
---|
285 | n/a | self.assertEqual(f.getcompname(), b'odd') |
---|
286 | n/a | |
---|
287 | n/a | def test_write_params_raises(self): |
---|
288 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
289 | n/a | wrong_params = (0, 0, 0, 0, b'WRNG', '') |
---|
290 | n/a | self.assertRaises(aifc.Error, fout.setparams, wrong_params) |
---|
291 | n/a | self.assertRaises(aifc.Error, fout.getparams) |
---|
292 | n/a | self.assertRaises(aifc.Error, fout.setnchannels, 0) |
---|
293 | n/a | self.assertRaises(aifc.Error, fout.getnchannels) |
---|
294 | n/a | self.assertRaises(aifc.Error, fout.setsampwidth, 0) |
---|
295 | n/a | self.assertRaises(aifc.Error, fout.getsampwidth) |
---|
296 | n/a | self.assertRaises(aifc.Error, fout.setframerate, 0) |
---|
297 | n/a | self.assertRaises(aifc.Error, fout.getframerate) |
---|
298 | n/a | self.assertRaises(aifc.Error, fout.setcomptype, b'WRNG', '') |
---|
299 | n/a | fout.aiff() |
---|
300 | n/a | fout.setnchannels(1) |
---|
301 | n/a | fout.setsampwidth(1) |
---|
302 | n/a | fout.setframerate(1) |
---|
303 | n/a | fout.setnframes(1) |
---|
304 | n/a | fout.writeframes(b'\x00') |
---|
305 | n/a | self.assertRaises(aifc.Error, fout.setparams, (1, 1, 1, 1, 1, 1)) |
---|
306 | n/a | self.assertRaises(aifc.Error, fout.setnchannels, 1) |
---|
307 | n/a | self.assertRaises(aifc.Error, fout.setsampwidth, 1) |
---|
308 | n/a | self.assertRaises(aifc.Error, fout.setframerate, 1) |
---|
309 | n/a | self.assertRaises(aifc.Error, fout.setnframes, 1) |
---|
310 | n/a | self.assertRaises(aifc.Error, fout.setcomptype, b'NONE', '') |
---|
311 | n/a | self.assertRaises(aifc.Error, fout.aiff) |
---|
312 | n/a | self.assertRaises(aifc.Error, fout.aifc) |
---|
313 | n/a | |
---|
314 | n/a | def test_write_params_singles(self): |
---|
315 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
316 | n/a | fout.aifc() |
---|
317 | n/a | fout.setnchannels(1) |
---|
318 | n/a | fout.setsampwidth(2) |
---|
319 | n/a | fout.setframerate(3) |
---|
320 | n/a | fout.setnframes(4) |
---|
321 | n/a | fout.setcomptype(b'NONE', b'name') |
---|
322 | n/a | self.assertEqual(fout.getnchannels(), 1) |
---|
323 | n/a | self.assertEqual(fout.getsampwidth(), 2) |
---|
324 | n/a | self.assertEqual(fout.getframerate(), 3) |
---|
325 | n/a | self.assertEqual(fout.getnframes(), 0) |
---|
326 | n/a | self.assertEqual(fout.tell(), 0) |
---|
327 | n/a | self.assertEqual(fout.getcomptype(), b'NONE') |
---|
328 | n/a | self.assertEqual(fout.getcompname(), b'name') |
---|
329 | n/a | fout.writeframes(b'\x00' * 4 * fout.getsampwidth() * fout.getnchannels()) |
---|
330 | n/a | self.assertEqual(fout.getnframes(), 4) |
---|
331 | n/a | self.assertEqual(fout.tell(), 4) |
---|
332 | n/a | |
---|
333 | n/a | def test_write_params_bunch(self): |
---|
334 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
335 | n/a | fout.aifc() |
---|
336 | n/a | p = (1, 2, 3, 4, b'NONE', b'name') |
---|
337 | n/a | fout.setparams(p) |
---|
338 | n/a | self.assertEqual(fout.getparams(), p) |
---|
339 | n/a | fout.initfp(None) |
---|
340 | n/a | |
---|
341 | n/a | def test_write_header_raises(self): |
---|
342 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
343 | n/a | self.assertRaises(aifc.Error, fout.close) |
---|
344 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
345 | n/a | fout.setnchannels(1) |
---|
346 | n/a | self.assertRaises(aifc.Error, fout.close) |
---|
347 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
348 | n/a | fout.setnchannels(1) |
---|
349 | n/a | fout.setsampwidth(1) |
---|
350 | n/a | self.assertRaises(aifc.Error, fout.close) |
---|
351 | n/a | |
---|
352 | n/a | def test_write_header_comptype_raises(self): |
---|
353 | n/a | for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): |
---|
354 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
355 | n/a | fout.setsampwidth(1) |
---|
356 | n/a | fout.setcomptype(comptype, b'') |
---|
357 | n/a | self.assertRaises(aifc.Error, fout.close) |
---|
358 | n/a | fout.initfp(None) |
---|
359 | n/a | |
---|
360 | n/a | def test_write_markers_raises(self): |
---|
361 | n/a | fout = aifc.open(io.BytesIO(), 'wb') |
---|
362 | n/a | self.assertRaises(aifc.Error, fout.setmark, 0, 0, b'') |
---|
363 | n/a | self.assertRaises(aifc.Error, fout.setmark, 1, -1, b'') |
---|
364 | n/a | self.assertRaises(aifc.Error, fout.setmark, 1, 0, None) |
---|
365 | n/a | self.assertRaises(aifc.Error, fout.getmark, 1) |
---|
366 | n/a | fout.initfp(None) |
---|
367 | n/a | |
---|
368 | n/a | def test_write_aiff_by_extension(self): |
---|
369 | n/a | sampwidth = 2 |
---|
370 | n/a | filename = TESTFN + '.aiff' |
---|
371 | n/a | fout = self.fout = aifc.open(filename, 'wb') |
---|
372 | n/a | self.addCleanup(unlink, filename) |
---|
373 | n/a | fout.setparams((1, sampwidth, 1, 1, b'ULAW', b'')) |
---|
374 | n/a | frames = b'\x00' * fout.getnchannels() * sampwidth |
---|
375 | n/a | fout.writeframes(frames) |
---|
376 | n/a | fout.close() |
---|
377 | n/a | f = self.f = aifc.open(filename, 'rb') |
---|
378 | n/a | self.assertEqual(f.getcomptype(), b'NONE') |
---|
379 | n/a | f.close() |
---|
380 | n/a | |
---|
381 | n/a | |
---|
382 | n/a | if __name__ == "__main__": |
---|
383 | n/a | unittest.main() |
---|