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

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

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

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