summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_aifc.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-29 20:40:42 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-04-29 20:40:42 (GMT)
commiteb01a6cdb375aa7ac342e385c9b76dd6810504e3 (patch)
tree814df8d5c19926ed8d6a7083a73b04db2ac9c09a /Lib/test/test_aifc.py
parentd3ca55715028ac22981dadd3e4d9e61180f6e8bf (diff)
downloadcpython-eb01a6cdb375aa7ac342e385c9b76dd6810504e3.zip
cpython-eb01a6cdb375aa7ac342e385c9b76dd6810504e3.tar.gz
cpython-eb01a6cdb375aa7ac342e385c9b76dd6810504e3.tar.bz2
Merged revisions 72115 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72115 | r.david.murray | 2009-04-29 16:15:18 -0400 (Wed, 29 Apr 2009) | 2 lines More aifc tests. ........
Diffstat (limited to 'Lib/test/test_aifc.py')
-rw-r--r--Lib/test/test_aifc.py60
1 files changed, 53 insertions, 7 deletions
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
index fd41126..e97647c 100644
--- a/Lib/test/test_aifc.py
+++ b/Lib/test/test_aifc.py
@@ -1,5 +1,6 @@
-from test.support import findfile, run_unittest
+from test.support import findfile, run_unittest, TESTFN
import unittest
+import os
import aifc
@@ -7,16 +8,29 @@ import aifc
class AIFCTest(unittest.TestCase):
def setUp(self):
+ self.f = self.fout = None
self.sndfilepath = findfile('Sine-1000Hz-300ms.aif')
+ def tearDown(self):
+ if self.f is not None:
+ self.f.close()
+ if self.fout is not None:
+ try:
+ self.fout.close()
+ except (aifc.Error, AttributeError):
+ pass
+ try:
+ os.remove(TESTFN)
+ except OSError:
+ pass
+
def test_skipunknown(self):
#Issue 2245
#This file contains chunk types aifc doesn't recognize.
f = aifc.open(self.sndfilepath)
- f.close()
def test_params(self):
- f = aifc.open(self.sndfilepath)
+ f = self.f = aifc.open(self.sndfilepath)
self.assertEqual(f.getnchannels(), 2)
self.assertEqual(f.getsampwidth(), 2)
self.assertEqual(f.getframerate(), 48000)
@@ -29,10 +43,9 @@ class AIFCTest(unittest.TestCase):
f.getparams(),
(2, 2, 48000, 14400, b'NONE', b'not compressed'),
)
- f.close()
def test_read(self):
- f = aifc.open(self.sndfilepath)
+ f = self.f = aifc.open(self.sndfilepath)
self.assertEqual(f.tell(), 0)
self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
f.rewind()
@@ -46,9 +59,42 @@ class AIFCTest(unittest.TestCase):
self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad')
f.setpos(pos0)
self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
- f.close()
- #XXX Need more tests!
+ def test_write(self):
+ f = self.f = aifc.open(self.sndfilepath)
+ fout = self.fout = aifc.open(TESTFN, 'wb')
+ fout.aifc()
+ fout.setparams(f.getparams())
+ for frame in range(f.getnframes()):
+ fout.writeframes(f.readframes(1))
+ fout.close()
+ fout = self.fout = aifc.open(TESTFN, 'rb')
+ f.rewind()
+ self.assertEqual(f.getparams(), fout.getparams())
+ self.assertEqual(f.readframes(5), fout.readframes(5))
+
+ def test_compress(self):
+ f = self.f = aifc.open(self.sndfilepath)
+ fout = self.fout = aifc.open(TESTFN, 'wb')
+ fout.aifc()
+ fout.setnchannels(f.getnchannels())
+ fout.setsampwidth(f.getsampwidth())
+ fout.setframerate(f.getframerate())
+ fout.setcomptype(b'ULAW', b'foo')
+ for frame in range(f.getnframes()):
+ fout.writeframes(f.readframes(1))
+ fout.close()
+ self.assertLess(
+ os.stat(TESTFN).st_size,
+ os.stat(self.sndfilepath).st_size*0.75,
+ )
+ fout = self.fout = aifc.open(TESTFN, 'rb')
+ f.rewind()
+ self.assertEqual(f.getparams()[0:3], fout.getparams()[0:3])
+ self.assertEqual(fout.getcomptype(), b'ULAW')
+ self.assertEqual(fout.getcompname(), b'foo')
+ # XXX: this test fails, not sure if it should succeed or not
+ # self.assertEqual(f.readframes(5), fout.readframes(5))
def test_main():