diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-04 00:43:03 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-04 00:43:03 +0300 |
commit | e06a89655a460e7d6571ffea0b72aefef4c0a1cc (patch) | |
tree | cebcd54e56cedeba54a399e9abdc48eab401e4d5 /Lib | |
parent | 4c6a020a2d1a6d2bee1bbe4e426cbc8f7ca2cf9a (diff) | |
download | cpython-git-e06a89655a460e7d6571ffea0b72aefef4c0a1cc.tar.gz |
Issue #18901: The sunau getparams method now returns a namedtuple rather than
a plain tuple. Patch by Claudiu Popa.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sunau.py | 19 | ||||
-rw-r--r-- | Lib/test/test_sunau.py | 22 |
2 files changed, 34 insertions, 7 deletions
diff --git a/Lib/sunau.py b/Lib/sunau.py index 6775a53cf7..7d7cd6c688 100644 --- a/Lib/sunau.py +++ b/Lib/sunau.py @@ -51,7 +51,7 @@ This returns an instance of a class with the following public methods: getcomptype() -- returns compression type ('NONE' or 'ULAW') getcompname() -- returns human-readable version of compression type ('not compressed' matches 'NONE') - getparams() -- returns a tuple consisting of all of the + getparams() -- returns a namedtuple consisting of all of the above in the above order getmarkers() -- returns None (for compatibility with the aifc module) @@ -103,6 +103,11 @@ The close() method is called automatically when the class instance is destroyed. """ +from collections import namedtuple + +_sunau_params = namedtuple('_sunau_params', + 'nchannels sampwidth framerate nframes comptype compname') + # from <multimedia/audio_filehdr.h> AUDIO_FILE_MAGIC = 0x2e736e64 AUDIO_FILE_ENCODING_MULAW_8 = 1 @@ -242,9 +247,9 @@ class Au_read: return 'not compressed' def getparams(self): - return self.getnchannels(), self.getsampwidth(), \ - self.getframerate(), self.getnframes(), \ - self.getcomptype(), self.getcompname() + return _sunau_params(self.getnchannels(), self.getsampwidth(), + self.getframerate(), self.getnframes(), + self.getcomptype(), self.getcompname()) def getmarkers(self): return None @@ -381,9 +386,9 @@ class Au_write: self.setcomptype(comptype, compname) def getparams(self): - return self.getnchannels(), self.getsampwidth(), \ - self.getframerate(), self.getnframes(), \ - self.getcomptype(), self.getcompname() + return _sunau_getparams(self.getnchannels(), self.getsampwidth(), + self.getframerate(), self.getnframes(), + self.getcomptype(), self.getcompname()) def tell(self): return self._nframeswritten diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py index 339ab576d5..c381d07a31 100644 --- a/Lib/test/test_sunau.py +++ b/Lib/test/test_sunau.py @@ -1,5 +1,6 @@ from test.support import run_unittest, TESTFN import unittest +import pickle import os import sunau @@ -62,6 +63,27 @@ class SunAUTest(unittest.TestCase): self.assertEqual(self.f.readframes(nframes), output) self.f.close() + def test_getparams(self): + self.f = sunau.open(TESTFN, 'w') + self.f.setnchannels(nchannels) + self.f.setsampwidth(sampwidth) + self.f.setframerate(framerate) + self.f.setcomptype('ULAW', '') + output = b'\0' * nframes * nchannels * sampwidth + self.f.writeframes(output) + self.f.close() + + self.f = sunau.open(TESTFN, 'rb') + params = self.f.getparams() + self.assertEqual(params.nchannels, nchannels) + self.assertEqual(params.sampwidth, sampwidth) + self.assertEqual(params.framerate, framerate) + self.assertEqual(params.nframes, nframes) + self.assertEqual(params.comptype, 'ULAW') + + dump = pickle.dumps(params) + self.assertEqual(pickle.loads(dump), params) + def test_main(): run_unittest(SunAUTest) |