~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_audioop.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import unittest
3
3
from test.support import run_unittest
4
4
 
 
5
endian = 'big' if audioop.getsample(b'\0\1', 2, 0) == 1 else 'little'
5
6
 
6
7
def gendata1():
7
8
    return b'\0\1\2'
8
9
 
9
10
def gendata2():
10
 
    if audioop.getsample(b'\0\1', 2, 0) == 1:
 
11
    if endian == 'big':
11
12
        return b'\0\0\0\1\0\2'
12
13
    else:
13
14
        return b'\0\0\1\0\2\0'
14
15
 
15
16
def gendata4():
16
 
    if audioop.getsample(b'\0\0\0\1', 4, 0) == 1:
 
17
    if endian == 'big':
17
18
        return b'\0\0\0\0\0\0\0\1\0\0\0\2'
18
19
    else:
19
20
        return b'\0\0\0\0\1\0\0\0\2\0\0\0'
21
22
data = [gendata1(), gendata2(), gendata4()]
22
23
 
23
24
INVALID_DATA = [
24
 
    ('abc', 0),
25
 
    ('abc', 2),
26
 
    ('abc', 4),
 
25
    (b'abc', 0),
 
26
    (b'abc', 2),
 
27
    (b'abc', 4),
27
28
]
28
29
 
29
30
 
94
95
 
95
96
    def test_adpcm2lin(self):
96
97
        # Very cursory test
97
 
        self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0\0\0\0', (0,0)))
 
98
        self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0' * 4, (0,0)))
 
99
        self.assertEqual(audioop.adpcm2lin(b'\0\0', 2, None), (b'\0' * 8, (0,0)))
 
100
        self.assertEqual(audioop.adpcm2lin(b'\0\0', 4, None), (b'\0' * 16, (0,0)))
98
101
 
99
102
    def test_lin2adpcm(self):
100
103
        # Very cursory test
109
112
        # Cursory
110
113
        d = audioop.lin2alaw(data[0], 1)
111
114
        self.assertEqual(audioop.alaw2lin(d, 1), data[0])
 
115
        if endian == 'big':
 
116
            self.assertEqual(audioop.alaw2lin(d, 2),
 
117
                             b'\x00\x08\x01\x08\x02\x10')
 
118
            self.assertEqual(audioop.alaw2lin(d, 4),
 
119
                             b'\x00\x08\x00\x00\x01\x08\x00\x00\x02\x10\x00\x00')
 
120
        else:
 
121
            self.assertEqual(audioop.alaw2lin(d, 2),
 
122
                             b'\x08\x00\x08\x01\x10\x02')
 
123
            self.assertEqual(audioop.alaw2lin(d, 4),
 
124
                             b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
112
125
 
113
126
    def test_lin2ulaw(self):
114
127
        self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
119
132
        # Cursory
120
133
        d = audioop.lin2ulaw(data[0], 1)
121
134
        self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
 
135
        if endian == 'big':
 
136
            self.assertEqual(audioop.ulaw2lin(d, 2),
 
137
                             b'\x00\x00\x01\x04\x02\x0c')
 
138
            self.assertEqual(audioop.ulaw2lin(d, 4),
 
139
                             b'\x00\x00\x00\x00\x01\x04\x00\x00\x02\x0c\x00\x00')
 
140
        else:
 
141
            self.assertEqual(audioop.ulaw2lin(d, 2),
 
142
                             b'\x00\x00\x04\x01\x0c\x02')
 
143
            self.assertEqual(audioop.ulaw2lin(d, 4),
 
144
                             b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
122
145
 
123
146
    def test_mul(self):
124
147
        data2 = []
195
218
            self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
196
219
            self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
197
220
            self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
 
221
            self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
 
222
            self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
 
223
 
 
224
    def test_wrongsize(self):
 
225
        data = b'abc'
 
226
        state = None
 
227
        for size in (-1, 3, 5):
198
228
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
199
 
            self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
200
229
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
201
 
            self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
202
230
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
203
231
 
204
232
def test_main():