summaryrefslogtreecommitdiffstats
path: root/Lib/test/audiotests.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-11-16 11:04:00 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-11-16 11:04:00 (GMT)
commit7714ebbe0e7556bbfa6b768e434042b55474939c (patch)
treeedfc3e4daeaca4f88a3efb384c1a34bdf7f808b1 /Lib/test/audiotests.py
parenta7a34a83f3f2b9b319cb6f379f6e189066233c76 (diff)
downloadcpython-7714ebbe0e7556bbfa6b768e434042b55474939c.zip
cpython-7714ebbe0e7556bbfa6b768e434042b55474939c.tar.gz
cpython-7714ebbe0e7556bbfa6b768e434042b55474939c.tar.bz2
Issue #5202: Added support for unseekable files in the wave module.
Diffstat (limited to 'Lib/test/audiotests.py')
-rw-r--r--Lib/test/audiotests.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py
index 7b39269..c22f0a1 100644
--- a/Lib/test/audiotests.py
+++ b/Lib/test/audiotests.py
@@ -21,6 +21,13 @@ def byteswap4(data):
a.byteswap()
return a.tobytes()
+class UnseekableIO(io.FileIO):
+ def tell(self):
+ raise io.UnsupportedOperation
+
+ def seek(self, *args, **kwargs):
+ raise io.UnsupportedOperation
+
class AudioTests:
close_fd = False
@@ -177,6 +184,59 @@ class AudioWriteTests(AudioTests):
self.assertEqual(testfile.read(13), b'ababagalamaga')
self.check_file(testfile, self.nframes, self.frames)
+ def test_unseekable_read(self):
+ with self.create_file(TESTFN) as f:
+ f.setnframes(self.nframes)
+ f.writeframes(self.frames)
+
+ 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:
+ with self.create_file(testfile) as f:
+ f.setnframes(self.nframes)
+ f.writeframes(self.frames)
+
+ 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):