Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 1 | from test.support import findfile, TESTFN, unlink |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 2 | import unittest |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 3 | from test import audiotests |
R. David Murray | eb01a6c | 2009-04-29 20:40:42 +0000 | [diff] [blame] | 4 | import os |
Sandro Tosi | bdd5354 | 2012-01-01 18:04:37 +0100 | [diff] [blame] | 5 | import io |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 6 | import sys |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 7 | import struct |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 8 | import aifc |
| 9 | |
| 10 | |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 11 | class AifcPCM8Test(audiotests.AudioWriteTests, |
| 12 | audiotests.AudioTestsWithSourceFile, |
| 13 | unittest.TestCase): |
| 14 | module = aifc |
| 15 | sndfilename = 'pluck-pcm8.aiff' |
| 16 | sndfilenframes = 3307 |
| 17 | nchannels = 2 |
| 18 | sampwidth = 1 |
| 19 | framerate = 11025 |
| 20 | nframes = 48 |
| 21 | comptype = b'NONE' |
| 22 | compname = b'not compressed' |
| 23 | frames = bytes.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 |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 30 | |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 31 | |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 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 = b'NONE' |
| 43 | compname = b'not compressed' |
| 44 | frames = bytes.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 |
R. David Murray | eb01a6c | 2009-04-29 20:40:42 +0000 | [diff] [blame] | 53 | |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 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 = b'NONE' |
| 66 | compname = b'not compressed' |
| 67 | frames = bytes.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 = b'NONE' |
| 95 | compname = b'not compressed' |
| 96 | frames = bytes.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 = b'ulaw' |
| 124 | compname = b'' |
| 125 | frames = bytes.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 AifcALAWTest(audiotests.AudioWriteTests, |
| 139 | audiotests.AudioTestsWithSourceFile, |
| 140 | unittest.TestCase): |
| 141 | module = aifc |
| 142 | sndfilename = 'pluck-alaw.aifc' |
| 143 | sndfilenframes = 3307 |
| 144 | nchannels = 2 |
| 145 | sampwidth = 2 |
| 146 | framerate = 11025 |
| 147 | nframes = 48 |
| 148 | comptype = b'alaw' |
| 149 | compname = b'' |
| 150 | frames = bytes.fromhex("""\ |
| 151 | 0230FFE8 4A0000F8 310004E0 82000840 CB0006A0 4A0003F0 BE0001A8 0370FE78 \ |
| 152 | BA00FA20 B600F340 2900EB80 1A80E680 ED80E480 C700E280 0E40E080 EF80E080 \ |
| 153 | 5600E280 FB20E880 1380EF80 D900F740 9600FB60 F5C0FC10 0840FBA0 DF00FB20 \ |
| 154 | 1180FA20 3F00FB60 BE00FCB0 6600FF58 CF000420 42000940 C1000EC0 52001280 \ |
| 155 | EE801780 82001680 7E001480 82001280 4A000EC0 52000DC0 EF800F40 CF000FC0 \ |
| 156 | E4800CC0 62000A40 08C00A40 2B000B40 52000E40 8A001180 B6000EC0 46000A40 \ |
| 157 | """) |
| 158 | if sys.byteorder != 'big': |
| 159 | frames = audiotests.byteswap2(frames) |
| 160 | close_fd = True |
| 161 | |
| 162 | |
| 163 | class AifcMiscTest(audiotests.AudioTests, unittest.TestCase): |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 164 | def test_skipunknown(self): |
| 165 | #Issue 2245 |
| 166 | #This file contains chunk types aifc doesn't recognize. |
Serhiy Storchaka | 1b80e63 | 2013-10-13 17:55:07 +0300 | [diff] [blame^] | 167 | self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif')) |
R. David Murray | 9935274 | 2009-05-07 18:24:38 +0000 | [diff] [blame] | 168 | |
Sandro Tosi | bdd5354 | 2012-01-01 18:04:37 +0100 | [diff] [blame] | 169 | def test_write_header_comptype_sampwidth(self): |
| 170 | for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 171 | fout = aifc.open(io.BytesIO(), 'wb') |
Sandro Tosi | bdd5354 | 2012-01-01 18:04:37 +0100 | [diff] [blame] | 172 | fout.setnchannels(1) |
| 173 | fout.setframerate(1) |
| 174 | fout.setcomptype(comptype, b'') |
| 175 | fout.close() |
| 176 | self.assertEqual(fout.getsampwidth(), 2) |
| 177 | fout.initfp(None) |
| 178 | |
Sandro Tosi | 70efbef | 2012-01-01 22:53:08 +0100 | [diff] [blame] | 179 | def test_write_markers_values(self): |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 180 | fout = aifc.open(io.BytesIO(), 'wb') |
Sandro Tosi | 70efbef | 2012-01-01 22:53:08 +0100 | [diff] [blame] | 181 | self.assertEqual(fout.getmarkers(), None) |
| 182 | fout.setmark(1, 0, b'foo1') |
| 183 | fout.setmark(1, 1, b'foo2') |
| 184 | self.assertEqual(fout.getmark(1), (1, 1, b'foo2')) |
| 185 | self.assertEqual(fout.getmarkers(), [(1, 1, b'foo2')]) |
| 186 | fout.initfp(None) |
| 187 | |
| 188 | def test_read_markers(self): |
| 189 | fout = self.fout = aifc.open(TESTFN, 'wb') |
| 190 | fout.aiff() |
| 191 | fout.setparams((1, 1, 1, 1, b'NONE', b'')) |
| 192 | fout.setmark(1, 0, b'odd') |
| 193 | fout.setmark(2, 0, b'even') |
| 194 | fout.writeframes(b'\x00') |
| 195 | fout.close() |
| 196 | f = self.f = aifc.open(TESTFN, 'rb') |
| 197 | self.assertEqual(f.getmarkers(), [(1, 0, b'odd'), (2, 0, b'even')]) |
| 198 | self.assertEqual(f.getmark(1), (1, 0, b'odd')) |
| 199 | self.assertEqual(f.getmark(2), (2, 0, b'even')) |
| 200 | self.assertRaises(aifc.Error, f.getmark, 3) |
| 201 | |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 202 | |
Antoine Pitrou | 03757ec | 2012-01-17 17:13:04 +0100 | [diff] [blame] | 203 | class AIFCLowLevelTest(unittest.TestCase): |
| 204 | |
| 205 | def test_read_written(self): |
| 206 | def read_written(self, what): |
| 207 | f = io.BytesIO() |
| 208 | getattr(aifc, '_write_' + what)(f, x) |
| 209 | f.seek(0) |
| 210 | return getattr(aifc, '_read_' + what)(f) |
| 211 | for x in (-1, 0, 0.1, 1): |
| 212 | self.assertEqual(read_written(x, 'float'), x) |
| 213 | for x in (float('NaN'), float('Inf')): |
| 214 | self.assertEqual(read_written(x, 'float'), aifc._HUGE_VAL) |
| 215 | for x in (b'', b'foo', b'a' * 255): |
| 216 | self.assertEqual(read_written(x, 'string'), x) |
| 217 | for x in (-0x7FFFFFFF, -1, 0, 1, 0x7FFFFFFF): |
| 218 | self.assertEqual(read_written(x, 'long'), x) |
| 219 | for x in (0, 1, 0xFFFFFFFF): |
| 220 | self.assertEqual(read_written(x, 'ulong'), x) |
| 221 | for x in (-0x7FFF, -1, 0, 1, 0x7FFF): |
| 222 | self.assertEqual(read_written(x, 'short'), x) |
| 223 | for x in (0, 1, 0xFFFF): |
| 224 | self.assertEqual(read_written(x, 'ushort'), x) |
| 225 | |
| 226 | def test_read_raises(self): |
| 227 | f = io.BytesIO(b'\x00') |
| 228 | self.assertRaises(EOFError, aifc._read_ulong, f) |
| 229 | self.assertRaises(EOFError, aifc._read_long, f) |
| 230 | self.assertRaises(EOFError, aifc._read_ushort, f) |
| 231 | self.assertRaises(EOFError, aifc._read_short, f) |
| 232 | |
| 233 | def test_write_long_string_raises(self): |
| 234 | f = io.BytesIO() |
| 235 | with self.assertRaises(ValueError): |
| 236 | aifc._write_string(f, b'too long' * 255) |
| 237 | |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 238 | def test_wrong_open_mode(self): |
| 239 | with self.assertRaises(aifc.Error): |
| 240 | aifc.open(TESTFN, 'wrong_mode') |
| 241 | |
| 242 | def test_read_wrong_form(self): |
| 243 | b1 = io.BytesIO(b'WRNG' + struct.pack('>L', 0)) |
| 244 | b2 = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'WRNG') |
| 245 | self.assertRaises(aifc.Error, aifc.open, b1) |
| 246 | self.assertRaises(aifc.Error, aifc.open, b2) |
| 247 | |
| 248 | def test_read_no_comm_chunk(self): |
| 249 | b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF') |
| 250 | self.assertRaises(aifc.Error, aifc.open, b) |
| 251 | |
| 252 | def test_read_wrong_compression_type(self): |
| 253 | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
| 254 | b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0) |
| 255 | b += b'WRNG' + struct.pack('B', 0) |
| 256 | self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b)) |
| 257 | |
| 258 | def test_read_wrong_marks(self): |
| 259 | b = b'FORM' + struct.pack('>L', 4) + b'AIFF' |
| 260 | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
| 261 | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
| 262 | b += b'MARK' + struct.pack('>LhB', 3, 1, 1) |
Ezio Melotti | 48d578c | 2012-03-12 23:57:18 +0200 | [diff] [blame] | 263 | with self.assertWarns(UserWarning): |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 264 | f = aifc.open(io.BytesIO(b)) |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 265 | self.assertEqual(f.getmarkers(), None) |
| 266 | |
| 267 | def test_read_comm_kludge_compname_even(self): |
| 268 | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
| 269 | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
| 270 | b += b'NONE' + struct.pack('B', 4) + b'even' + b'\x00' |
| 271 | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
Ezio Melotti | 48d578c | 2012-03-12 23:57:18 +0200 | [diff] [blame] | 272 | with self.assertWarns(UserWarning): |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 273 | f = aifc.open(io.BytesIO(b)) |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 274 | self.assertEqual(f.getcompname(), b'even') |
| 275 | |
| 276 | def test_read_comm_kludge_compname_odd(self): |
| 277 | b = b'FORM' + struct.pack('>L', 4) + b'AIFC' |
| 278 | b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) |
| 279 | b += b'NONE' + struct.pack('B', 3) + b'odd' |
| 280 | b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8 |
Ezio Melotti | 48d578c | 2012-03-12 23:57:18 +0200 | [diff] [blame] | 281 | with self.assertWarns(UserWarning): |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 282 | f = aifc.open(io.BytesIO(b)) |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 283 | self.assertEqual(f.getcompname(), b'odd') |
| 284 | |
| 285 | def test_write_params_raises(self): |
| 286 | fout = aifc.open(io.BytesIO(), 'wb') |
| 287 | wrong_params = (0, 0, 0, 0, b'WRNG', '') |
| 288 | self.assertRaises(aifc.Error, fout.setparams, wrong_params) |
| 289 | self.assertRaises(aifc.Error, fout.getparams) |
| 290 | self.assertRaises(aifc.Error, fout.setnchannels, 0) |
| 291 | self.assertRaises(aifc.Error, fout.getnchannels) |
| 292 | self.assertRaises(aifc.Error, fout.setsampwidth, 0) |
| 293 | self.assertRaises(aifc.Error, fout.getsampwidth) |
| 294 | self.assertRaises(aifc.Error, fout.setframerate, 0) |
| 295 | self.assertRaises(aifc.Error, fout.getframerate) |
| 296 | self.assertRaises(aifc.Error, fout.setcomptype, b'WRNG', '') |
| 297 | fout.aiff() |
| 298 | fout.setnchannels(1) |
| 299 | fout.setsampwidth(1) |
| 300 | fout.setframerate(1) |
| 301 | fout.setnframes(1) |
| 302 | fout.writeframes(b'\x00') |
| 303 | self.assertRaises(aifc.Error, fout.setparams, (1, 1, 1, 1, 1, 1)) |
| 304 | self.assertRaises(aifc.Error, fout.setnchannels, 1) |
| 305 | self.assertRaises(aifc.Error, fout.setsampwidth, 1) |
| 306 | self.assertRaises(aifc.Error, fout.setframerate, 1) |
| 307 | self.assertRaises(aifc.Error, fout.setnframes, 1) |
| 308 | self.assertRaises(aifc.Error, fout.setcomptype, b'NONE', '') |
| 309 | self.assertRaises(aifc.Error, fout.aiff) |
| 310 | self.assertRaises(aifc.Error, fout.aifc) |
| 311 | |
| 312 | def test_write_params_singles(self): |
| 313 | fout = aifc.open(io.BytesIO(), 'wb') |
| 314 | fout.aifc() |
| 315 | fout.setnchannels(1) |
| 316 | fout.setsampwidth(2) |
| 317 | fout.setframerate(3) |
| 318 | fout.setnframes(4) |
| 319 | fout.setcomptype(b'NONE', b'name') |
| 320 | self.assertEqual(fout.getnchannels(), 1) |
| 321 | self.assertEqual(fout.getsampwidth(), 2) |
| 322 | self.assertEqual(fout.getframerate(), 3) |
| 323 | self.assertEqual(fout.getnframes(), 0) |
| 324 | self.assertEqual(fout.tell(), 0) |
| 325 | self.assertEqual(fout.getcomptype(), b'NONE') |
| 326 | self.assertEqual(fout.getcompname(), b'name') |
| 327 | fout.writeframes(b'\x00' * 4 * fout.getsampwidth() * fout.getnchannels()) |
| 328 | self.assertEqual(fout.getnframes(), 4) |
| 329 | self.assertEqual(fout.tell(), 4) |
| 330 | |
| 331 | def test_write_params_bunch(self): |
| 332 | fout = aifc.open(io.BytesIO(), 'wb') |
| 333 | fout.aifc() |
| 334 | p = (1, 2, 3, 4, b'NONE', b'name') |
| 335 | fout.setparams(p) |
| 336 | self.assertEqual(fout.getparams(), p) |
| 337 | fout.initfp(None) |
| 338 | |
| 339 | def test_write_header_raises(self): |
| 340 | fout = aifc.open(io.BytesIO(), 'wb') |
| 341 | self.assertRaises(aifc.Error, fout.close) |
Serhiy Storchaka | 051722d | 2012-12-29 22:30:56 +0200 | [diff] [blame] | 342 | fout = aifc.open(io.BytesIO(), 'wb') |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 343 | fout.setnchannels(1) |
| 344 | self.assertRaises(aifc.Error, fout.close) |
Serhiy Storchaka | 051722d | 2012-12-29 22:30:56 +0200 | [diff] [blame] | 345 | fout = aifc.open(io.BytesIO(), 'wb') |
| 346 | fout.setnchannels(1) |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 347 | fout.setsampwidth(1) |
| 348 | self.assertRaises(aifc.Error, fout.close) |
Ezio Melotti | 8576953 | 2012-03-12 23:52:40 +0200 | [diff] [blame] | 349 | |
| 350 | def test_write_header_comptype_raises(self): |
| 351 | for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): |
| 352 | fout = aifc.open(io.BytesIO(), 'wb') |
| 353 | fout.setsampwidth(1) |
| 354 | fout.setcomptype(comptype, b'') |
| 355 | self.assertRaises(aifc.Error, fout.close) |
| 356 | fout.initfp(None) |
| 357 | |
| 358 | def test_write_markers_raises(self): |
| 359 | fout = aifc.open(io.BytesIO(), 'wb') |
| 360 | self.assertRaises(aifc.Error, fout.setmark, 0, 0, b'') |
| 361 | self.assertRaises(aifc.Error, fout.setmark, 1, -1, b'') |
| 362 | self.assertRaises(aifc.Error, fout.setmark, 1, 0, None) |
| 363 | self.assertRaises(aifc.Error, fout.getmark, 1) |
| 364 | fout.initfp(None) |
| 365 | |
| 366 | def test_write_aiff_by_extension(self): |
| 367 | sampwidth = 2 |
| 368 | fout = self.fout = aifc.open(TESTFN + '.aiff', 'wb') |
| 369 | fout.setparams((1, sampwidth, 1, 1, b'ULAW', b'')) |
| 370 | frames = b'\x00' * fout.getnchannels() * sampwidth |
| 371 | fout.writeframes(frames) |
| 372 | fout.close() |
| 373 | f = self.f = aifc.open(TESTFN + '.aiff', 'rb') |
| 374 | self.assertEqual(f.getcomptype(), b'NONE') |
| 375 | f.close() |
| 376 | |
Antoine Pitrou | 03757ec | 2012-01-17 17:13:04 +0100 | [diff] [blame] | 377 | |
R. David Murray | b507d2e | 2009-04-29 15:34:32 +0000 | [diff] [blame] | 378 | if __name__ == "__main__": |
| 379 | unittest.main() |