diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/audiotests.py | 18 | ||||
| -rw-r--r-- | Lib/test/test_aifc.py | 5 | ||||
| -rw-r--r-- | Lib/test/test_audioop.py | 17 | ||||
| -rw-r--r-- | Lib/test/test_sunau.py | 3 | ||||
| -rw-r--r-- | Lib/test/test_wave.py | 18 |
5 files changed, 26 insertions, 35 deletions
diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py index 7581fe2ed4..b7497ce5b0 100644 --- a/Lib/test/audiotests.py +++ b/Lib/test/audiotests.py @@ -5,24 +5,6 @@ import io import pickle import sys -def byteswap2(data): - a = array.array('h') - a.frombytes(data) - a.byteswap() - return a.tobytes() - -def byteswap3(data): - ba = bytearray(data) - ba[::3] = data[2::3] - ba[2::3] = data[::3] - return bytes(ba) - -def byteswap4(data): - a = array.array('i') - a.frombytes(data) - a.byteswap() - return a.tobytes() - class UnseekableIO(io.FileIO): def tell(self): raise io.UnsupportedOperation diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index b4270bc655..041b23688c 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -1,6 +1,7 @@ from test.support import findfile, TESTFN, unlink import unittest from test import audiotests +from audioop import byteswap import os import io import sys @@ -122,7 +123,7 @@ class AifcULAWTest(AifcTest, unittest.TestCase): E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap2(frames) + frames = byteswap(frames, 2) class AifcALAWTest(AifcTest, unittest.TestCase): @@ -143,7 +144,7 @@ class AifcALAWTest(AifcTest, unittest.TestCase): E4800CC0 62000A40 08C00A40 2B000B40 52000E40 8A001180 B6000EC0 46000A40 \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap2(frames) + frames = byteswap(frames, 2) class AifcMiscTest(audiotests.AudioTests, unittest.TestCase): diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py index fe96b75dfa..d5075450e6 100644 --- a/Lib/test/test_audioop.py +++ b/Lib/test/test_audioop.py @@ -448,6 +448,23 @@ class TestAudioop(unittest.TestCase): self.assertEqual(audioop.getsample(data, w, 3), maxvalues[w]) self.assertEqual(audioop.getsample(data, w, 4), minvalues[w]) + def test_byteswap(self): + swapped_datas = { + 1: datas[1], + 2: packs[2](0, 0x3412, 0x6745, -0x6646, -0x81, 0x80, -1), + 3: packs[3](0, 0x563412, -0x7698bb, 0x7798ba, -0x81, 0x80, -1), + 4: packs[4](0, 0x78563412, -0x547698bb, 0x557698ba, + -0x81, 0x80, -1), + } + for w in 1, 2, 3, 4: + self.assertEqual(audioop.byteswap(b'', w), b'') + self.assertEqual(audioop.byteswap(datas[w], w), swapped_datas[w]) + self.assertEqual(audioop.byteswap(swapped_datas[w], w), datas[w]) + self.assertEqual(audioop.byteswap(bytearray(datas[w]), w), + swapped_datas[w]) + self.assertEqual(audioop.byteswap(memoryview(datas[w]), w), + swapped_datas[w]) + def test_negativelen(self): # from issue 3306, previously it segfaulted self.assertRaises(audioop.error, diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py index 81acd964c2..af9ffec622 100644 --- a/Lib/test/test_sunau.py +++ b/Lib/test/test_sunau.py @@ -1,6 +1,7 @@ from test.support import TESTFN import unittest from test import audiotests +from audioop import byteswap import sys import sunau @@ -124,7 +125,7 @@ class SunauULAWTest(audiotests.AudioWriteTests, E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap2(frames) + frames = byteswap(frames, 2) if __name__ == "__main__": diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py index 5be12519d9..549ca89615 100644 --- a/Lib/test/test_wave.py +++ b/Lib/test/test_wave.py @@ -1,6 +1,7 @@ from test.support import TESTFN import unittest from test import audiotests +from audioop import byteswap import sys import wave @@ -46,13 +47,7 @@ class WavePCM16Test(audiotests.AudioWriteTests, E4B50CEB 63440A5A 08CA0A1F 2BBA0B0B 51460E47 8BCB113C B6F50EEA 44150A59 \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap2(frames) - - if sys.byteorder == 'big': - @unittest.expectedFailure - def test_unseekable_incompleted_write(self): - super().test_unseekable_incompleted_write() - + frames = byteswap(frames, 2) class WavePCM24Test(audiotests.AudioWriteTests, @@ -82,7 +77,7 @@ class WavePCM24Test(audiotests.AudioWriteTests, 51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48 \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap3(frames) + frames = byteswap(frames, 3) class WavePCM32Test(audiotests.AudioWriteTests, @@ -112,12 +107,7 @@ class WavePCM32Test(audiotests.AudioWriteTests, 51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0 \ """) if sys.byteorder != 'big': - frames = audiotests.byteswap4(frames) - - if sys.byteorder == 'big': - @unittest.expectedFailure - def test_unseekable_incompleted_write(self): - super().test_unseekable_incompleted_write() + frames = byteswap(frames, 4) if __name__ == '__main__': |
