summaryrefslogtreecommitdiffstats
path: root/Lib/test/audiotests.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-12-14 18:35:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-12-14 18:35:04 (GMT)
commit84d28b4ee5983bcb048323a0e56ea4c5498a0652 (patch)
tree95fdd650d031350b1dc3723764a46a12eb917059 /Lib/test/audiotests.py
parent5da107ac7261d8359cd6e1a9a8e57f85176d1180 (diff)
downloadcpython-84d28b4ee5983bcb048323a0e56ea4c5498a0652.zip
cpython-84d28b4ee5983bcb048323a0e56ea4c5498a0652.tar.gz
cpython-84d28b4ee5983bcb048323a0e56ea4c5498a0652.tar.bz2
Issue #19623: Fixed writing to unseekable files in the aifc module.
Diffstat (limited to 'Lib/test/audiotests.py')
-rw-r--r--Lib/test/audiotests.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py
index 008281f..6ff5bb8 100644
--- a/Lib/test/audiotests.py
+++ b/Lib/test/audiotests.py
@@ -5,6 +5,13 @@ import io
import pickle
import sys
+class UnseekableIO(io.FileIO):
+ def tell(self):
+ raise io.UnsupportedOperation
+
+ def seek(self, *args, **kwargs):
+ raise io.UnsupportedOperation
+
def byteswap2(data):
a = array.array('h')
a.frombytes(data)
@@ -129,6 +136,61 @@ class AudioWriteTests(AudioTests):
self.assertEqual(testfile.read(13), b'ababagalamaga')
self.check_file(testfile, self.nframes, self.frames)
+ def test_unseekable_read(self):
+ f = self.create_file(TESTFN)
+ f.setnframes(self.nframes)
+ f.writeframes(self.frames)
+ f.close()
+
+ with UnseekableIO(TESTFN, 'rb') as testfile:
+ self.check_file(testfile, self.nframes, self.frames)
+
+ def test_unseekable_write(self):
+ with UnseekableIO(TESTFN, 'wb') as testfile:
+ f = self.create_file(testfile)
+ f.setnframes(self.nframes)
+ f.writeframes(self.frames)
+ f.close()
+
+ self.check_file(TESTFN, self.nframes, self.frames)
+
+ def test_unseekable_incompleted_write(self):
+ with UnseekableIO(TESTFN, 'wb') as testfile:
+ testfile.write(b'ababagalamaga')
+ f = self.create_file(testfile)
+ f.setnframes(self.nframes + 1)
+ try:
+ f.writeframes(self.frames)
+ except OSError:
+ pass
+ try:
+ f.close()
+ except OSError:
+ pass
+
+ with open(TESTFN, 'rb') as testfile:
+ self.assertEqual(testfile.read(13), b'ababagalamaga')
+ self.check_file(testfile, self.nframes + 1, self.frames)
+
+ def test_unseekable_overflowed_write(self):
+ with UnseekableIO(TESTFN, 'wb') as testfile:
+ testfile.write(b'ababagalamaga')
+ f = self.create_file(testfile)
+ f.setnframes(self.nframes - 1)
+ try:
+ f.writeframes(self.frames)
+ except OSError:
+ pass
+ try:
+ f.close()
+ except OSError:
+ pass
+
+ with open(TESTFN, 'rb') as testfile:
+ self.assertEqual(testfile.read(13), b'ababagalamaga')
+ framesize = self.nchannels * self.sampwidth
+ self.check_file(testfile, self.nframes - 1, self.frames[:-framesize])
+
class AudioTestsWithSourceFile(AudioTests):