diff options
Diffstat (limited to 'Lib/test/test_aifc.py')
-rw-r--r-- | Lib/test/test_aifc.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index 9c0e7b9..05e4ca0 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -3,6 +3,7 @@ import unittest import os import io import struct +import pickle import aifc @@ -31,6 +32,7 @@ class AIFCTest(unittest.TestCase): def test_params(self): f = self.f = aifc.open(self.sndfilepath) + params = f.getparams() self.assertEqual(f.getfp().name, self.sndfilepath) self.assertEqual(f.getnchannels(), 2) self.assertEqual(f.getsampwidth(), 2) @@ -43,6 +45,48 @@ class AIFCTest(unittest.TestCase): (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) + params = f.getparams() + self.assertEqual(params.nchannels, 2) + self.assertEqual(params.sampwidth, 2) + self.assertEqual(params.framerate, 48000) + self.assertEqual(params.nframes, 14400) + self.assertEqual(params.comptype, b'NONE') + self.assertEqual(params.compname, b'not compressed') + + def test_params_added(self): + f = self.f = aifc.open(TESTFN, 'wb') + f.aiff() + f.setparams((1, 1, 1, 1, b'NONE', b'')) + f.close() + + f = self.f = aifc.open(TESTFN, 'rb') + params = f.getparams() + self.assertEqual(params.nchannels, f.getnchannels()) + self.assertEqual(params.sampwidth, f.getsampwidth()) + self.assertEqual(params.framerate, f.getframerate()) + self.assertEqual(params.nframes, f.getnframes()) + self.assertEqual(params.comptype, f.getcomptype()) + self.assertEqual(params.compname, f.getcompname()) + + def test_getparams_picklable(self): + self.f = aifc.open(self.sndfilepath) + params = self.f.getparams() + dump = pickle.dumps(params) + self.assertEqual(pickle.loads(dump), params) + self.f.close() + + def test_context_manager(self): + with open(self.sndfilepath, 'rb') as testfile: + with aifc.open(testfile) as f: + pass + self.assertEqual(testfile.closed, True) + with open(TESTFN, 'wb') as testfile: + with self.assertRaises(aifc.Error): + with aifc.open(testfile, 'wb') as fout: + pass + self.assertEqual(testfile.closed, True) + fout.close() # do nothing + def test_read(self): f = self.f = aifc.open(self.sndfilepath) self.assertEqual(f.readframes(0), b'') @@ -319,12 +363,14 @@ class AIFCLowLevelTest(unittest.TestCase): def test_write_aiff_by_extension(self): sampwidth = 2 - fout = self.fout = aifc.open(TESTFN + '.aiff', 'wb') + filename = TESTFN + '.aiff' + fout = self.fout = aifc.open(filename, 'wb') + self.addCleanup(unlink, filename) fout.setparams((1, sampwidth, 1, 1, b'ULAW', b'')) frames = b'\x00' * fout.getnchannels() * sampwidth fout.writeframes(frames) fout.close() - f = self.f = aifc.open(TESTFN + '.aiff', 'rb') + f = self.f = aifc.open(filename, 'rb') self.assertEqual(f.getcomptype(), b'NONE') f.close() |