test_aifc.py 18 KB

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