mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix failing test on big-endian machines (issue #13806).
This commit is contained in:
commit
672b3ac2f0
1 changed files with 23 additions and 8 deletions
|
@ -2,18 +2,19 @@ import audioop
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import run_unittest
|
from test.support import run_unittest
|
||||||
|
|
||||||
|
endian = 'big' if audioop.getsample(b'\0\1', 2, 0) == 1 else 'little'
|
||||||
|
|
||||||
def gendata1():
|
def gendata1():
|
||||||
return b'\0\1\2'
|
return b'\0\1\2'
|
||||||
|
|
||||||
def gendata2():
|
def gendata2():
|
||||||
if audioop.getsample(b'\0\1', 2, 0) == 1:
|
if endian == 'big':
|
||||||
return b'\0\0\0\1\0\2'
|
return b'\0\0\0\1\0\2'
|
||||||
else:
|
else:
|
||||||
return b'\0\0\1\0\2\0'
|
return b'\0\0\1\0\2\0'
|
||||||
|
|
||||||
def gendata4():
|
def gendata4():
|
||||||
if audioop.getsample(b'\0\0\0\1', 4, 0) == 1:
|
if endian == 'big':
|
||||||
return b'\0\0\0\0\0\0\0\1\0\0\0\2'
|
return b'\0\0\0\0\0\0\0\1\0\0\0\2'
|
||||||
else:
|
else:
|
||||||
return b'\0\0\0\0\1\0\0\0\2\0\0\0'
|
return b'\0\0\0\0\1\0\0\0\2\0\0\0'
|
||||||
|
@ -111,7 +112,14 @@ class TestAudioop(unittest.TestCase):
|
||||||
# Cursory
|
# Cursory
|
||||||
d = audioop.lin2alaw(data[0], 1)
|
d = audioop.lin2alaw(data[0], 1)
|
||||||
self.assertEqual(audioop.alaw2lin(d, 1), data[0])
|
self.assertEqual(audioop.alaw2lin(d, 1), data[0])
|
||||||
self.assertEqual(audioop.alaw2lin(d, 2), b'\x08\x00\x08\x01\x10\x02')
|
if endian == 'big':
|
||||||
|
self.assertEqual(audioop.alaw2lin(d, 2),
|
||||||
|
b'\x00\x08\x01\x08\x02\x10')
|
||||||
|
self.assertEqual(audioop.alaw2lin(d, 4),
|
||||||
|
b'\x00\x08\x00\x00\x01\x08\x00\x00\x02\x10\x00\x00')
|
||||||
|
else:
|
||||||
|
self.assertEqual(audioop.alaw2lin(d, 2),
|
||||||
|
b'\x08\x00\x08\x01\x10\x02')
|
||||||
self.assertEqual(audioop.alaw2lin(d, 4),
|
self.assertEqual(audioop.alaw2lin(d, 4),
|
||||||
b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
|
b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
|
||||||
|
|
||||||
|
@ -124,7 +132,14 @@ class TestAudioop(unittest.TestCase):
|
||||||
# Cursory
|
# Cursory
|
||||||
d = audioop.lin2ulaw(data[0], 1)
|
d = audioop.lin2ulaw(data[0], 1)
|
||||||
self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
|
self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
|
||||||
self.assertEqual(audioop.ulaw2lin(d, 2), b'\x00\x00\x04\x01\x0c\x02')
|
if endian == 'big':
|
||||||
|
self.assertEqual(audioop.ulaw2lin(d, 2),
|
||||||
|
b'\x00\x00\x01\x04\x02\x0c')
|
||||||
|
self.assertEqual(audioop.ulaw2lin(d, 4),
|
||||||
|
b'\x00\x00\x00\x00\x01\x04\x00\x00\x02\x0c\x00\x00')
|
||||||
|
else:
|
||||||
|
self.assertEqual(audioop.ulaw2lin(d, 2),
|
||||||
|
b'\x00\x00\x04\x01\x0c\x02')
|
||||||
self.assertEqual(audioop.ulaw2lin(d, 4),
|
self.assertEqual(audioop.ulaw2lin(d, 4),
|
||||||
b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
|
b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue