Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7416a4cd
Kaydet (Commit)
7416a4cd
authored
Haz 28, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
convert test_audioop to unittest. Thanks to Giampaolo Rodola.
üst
de34d91e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
223 deletions
+106
-223
test_audioop.py
Lib/test/test_audioop.py
+106
-223
No files found.
Lib/test/test_audioop.py
Dosyayı görüntüle @
7416a4cd
# Test audioop.
import
audioop
import
audioop
from
test.test_support
import
verbose
import
unittest
from
test.test_support
import
run_unittest
def
gendata1
():
def
gendata1
():
return
'
\0\1\2
'
return
'
\0\1\2
'
def
gendata2
():
def
gendata2
():
if
verbose
:
print
'getsample'
if
audioop
.
getsample
(
'
\0\1
'
,
2
,
0
)
==
1
:
if
audioop
.
getsample
(
'
\0\1
'
,
2
,
0
)
==
1
:
return
'
\0\0\0\1\0\2
'
return
'
\0\0\0\1\0\2
'
else
:
else
:
return
'
\0\0\1\0\2\0
'
return
'
\0\0\1\0\2\0
'
def
gendata4
():
def
gendata4
():
if
verbose
:
print
'getsample'
if
audioop
.
getsample
(
'
\0\0\0\1
'
,
4
,
0
)
==
1
:
if
audioop
.
getsample
(
'
\0\0\0\1
'
,
4
,
0
)
==
1
:
return
'
\0\0\0\0\0\0\0\1\0\0\0\2
'
return
'
\0\0\0\0\0\0\0\1\0\0\0\2
'
else
:
else
:
return
'
\0\0\0\0\1\0\0\0\2\0\0\0
'
return
'
\0\0\0\0\1\0\0\0\2\0\0\0
'
def
testmax
(
data
):
data
=
[
gendata1
(),
gendata2
(),
gendata4
()]
if
verbose
:
print
'max'
if
audioop
.
max
(
data
[
0
],
1
)
!=
2
or
\
class
TestAudioop
(
unittest
.
TestCase
):
audioop
.
max
(
data
[
1
],
2
)
!=
2
or
\
audioop
.
max
(
data
[
2
],
4
)
!=
2
:
def
test_max
(
self
):
return
0
self
.
assertEqual
(
audioop
.
max
(
data
[
0
],
1
),
2
)
return
1
self
.
assertEqual
(
audioop
.
max
(
data
[
1
],
2
),
2
)
self
.
assertEqual
(
audioop
.
max
(
data
[
2
],
4
),
2
)
def
testminmax
(
data
):
if
verbose
:
def
test_minmax
(
self
):
print
'minmax'
self
.
assertEqual
(
audioop
.
minmax
(
data
[
0
],
1
),
(
0
,
2
))
if
audioop
.
minmax
(
data
[
0
],
1
)
!=
(
0
,
2
)
or
\
Self
.
assertEqual
(
audioop
.
minmax
(
data
[
1
],
2
),
(
0
,
2
))
audioop
.
minmax
(
data
[
1
],
2
)
!=
(
0
,
2
)
or
\
self
.
assertEqual
(
audioop
.
minmax
(
data
[
2
],
4
),
(
0
,
2
))
audioop
.
minmax
(
data
[
2
],
4
)
!=
(
0
,
2
):
return
0
def
test_maxpp
(
self
):
return
1
self
.
assertEqual
(
audioop
.
maxpp
(
data
[
0
],
1
),
0
)
self
.
assertEqual
(
audioop
.
maxpp
(
data
[
1
],
2
),
0
)
def
testmaxpp
(
data
):
self
.
assertEqual
(
audioop
.
maxpp
(
data
[
2
],
4
),
0
)
if
verbose
:
print
'maxpp'
def
test_avg
(
self
):
if
audioop
.
maxpp
(
data
[
0
],
1
)
!=
0
or
\
self
.
assertEqual
(
audioop
.
avg
(
data
[
0
],
1
),
1
)
audioop
.
maxpp
(
data
[
1
],
2
)
!=
0
or
\
self
.
assertEqual
(
audioop
.
avg
(
data
[
1
],
2
),
1
)
audioop
.
maxpp
(
data
[
2
],
4
)
!=
0
:
self
.
assertEqual
(
audioop
.
avg
(
data
[
2
],
4
),
1
)
return
0
return
1
def
test_avgpp
(
self
):
self
.
assertEqual
(
audioop
.
avgpp
(
data
[
0
],
1
),
0
)
def
testavg
(
data
):
self
.
assertEqual
(
audioop
.
avgpp
(
data
[
1
],
2
),
0
)
if
verbose
:
self
.
assertEqual
(
audioop
.
avgpp
(
data
[
2
],
4
),
0
)
print
'avg'
if
audioop
.
avg
(
data
[
0
],
1
)
!=
1
or
\
def
test_rms
(
self
):
audioop
.
avg
(
data
[
1
],
2
)
!=
1
or
\
self
.
assertEqual
(
audioop
.
rms
(
data
[
0
],
1
),
1
)
audioop
.
avg
(
data
[
2
],
4
)
!=
1
:
self
.
assertEqual
(
audioop
.
rms
(
data
[
1
],
2
),
1
)
return
0
self
.
assertEqual
(
audioop
.
rms
(
data
[
2
],
4
),
1
)
return
1
def
test_cross
(
self
):
def
testavgpp
(
data
):
self
.
assertEqual
(
audioop
.
cross
(
data
[
0
],
1
),
0
)
if
verbose
:
self
.
assertEqual
(
audioop
.
cross
(
data
[
1
],
2
),
0
)
print
'avgpp'
self
.
assertEqual
(
audioop
.
cross
(
data
[
2
],
4
),
0
)
if
audioop
.
avgpp
(
data
[
0
],
1
)
!=
0
or
\
audioop
.
avgpp
(
data
[
1
],
2
)
!=
0
or
\
def
test_add
(
self
):
audioop
.
avgpp
(
data
[
2
],
4
)
!=
0
:
return
0
return
1
def
testrms
(
data
):
if
audioop
.
rms
(
data
[
0
],
1
)
!=
1
or
\
audioop
.
rms
(
data
[
1
],
2
)
!=
1
or
\
audioop
.
rms
(
data
[
2
],
4
)
!=
1
:
return
0
return
1
def
testcross
(
data
):
if
verbose
:
print
'cross'
if
audioop
.
cross
(
data
[
0
],
1
)
!=
0
or
\
audioop
.
cross
(
data
[
1
],
2
)
!=
0
or
\
audioop
.
cross
(
data
[
2
],
4
)
!=
0
:
return
0
return
1
def
testadd
(
data
):
if
verbose
:
print
'add'
data2
=
[]
data2
=
[]
for
d
in
data
:
for
d
in
data
:
str
=
''
str
=
''
for
s
in
d
:
for
s
in
d
:
str
=
str
+
chr
(
ord
(
s
)
*
2
)
str
=
str
+
chr
(
ord
(
s
)
*
2
)
data2
.
append
(
str
)
data2
.
append
(
str
)
if
audioop
.
add
(
data
[
0
],
data
[
0
],
1
)
!=
data2
[
0
]
or
\
self
.
assertEqual
(
audioop
.
add
(
data
[
0
],
data
[
0
],
1
),
data2
[
0
])
audioop
.
add
(
data
[
1
],
data
[
1
],
2
)
!=
data2
[
1
]
or
\
self
.
assertEqual
(
audioop
.
add
(
data
[
1
],
data
[
1
],
2
),
data2
[
1
])
audioop
.
add
(
data
[
2
],
data
[
2
],
4
)
!=
data2
[
2
]:
self
.
assertEqual
(
audioop
.
add
(
data
[
2
],
data
[
2
],
4
),
data2
[
2
])
return
0
return
1
def
test_bias
(
self
):
def
testbias
(
data
):
if
verbose
:
print
'bias'
# Note: this test assumes that avg() works
# Note: this test assumes that avg() works
d1
=
audioop
.
bias
(
data
[
0
],
1
,
100
)
d1
=
audioop
.
bias
(
data
[
0
],
1
,
100
)
d2
=
audioop
.
bias
(
data
[
1
],
2
,
100
)
d2
=
audioop
.
bias
(
data
[
1
],
2
,
100
)
d4
=
audioop
.
bias
(
data
[
2
],
4
,
100
)
d4
=
audioop
.
bias
(
data
[
2
],
4
,
100
)
if
audioop
.
avg
(
d1
,
1
)
!=
101
or
\
self
.
assertEqual
(
audioop
.
avg
(
d1
,
1
),
101
)
audioop
.
avg
(
d2
,
2
)
!=
101
or
\
self
.
assertEqual
(
audioop
.
avg
(
d2
,
2
),
101
)
audioop
.
avg
(
d4
,
4
)
!=
101
:
self
.
assertEqual
(
audioop
.
avg
(
d4
,
4
),
101
)
return
0
return
1
def
test_lin2lin
(
self
):
def
testlin2lin
(
data
):
if
verbose
:
print
'lin2lin'
# too simple: we test only the size
# too simple: we test only the size
for
d1
in
data
:
for
d1
in
data
:
for
d2
in
data
:
for
d2
in
data
:
got
=
len
(
d1
)
//
3
got
=
len
(
d1
)
//
3
wtd
=
len
(
d2
)
//
3
wtd
=
len
(
d2
)
//
3
if
len
(
audioop
.
lin2lin
(
d1
,
got
,
wtd
))
!=
len
(
d2
):
self
.
assertEqual
(
len
(
audioop
.
lin2lin
(
d1
,
got
,
wtd
)),
len
(
d2
))
return
0
return
1
def
testadpcm2lin
(
data
):
def
test_adpcm2lin
(
self
):
# Very cursory test
# Very cursory test
if
audioop
.
adpcm2lin
(
'
\0\0
'
,
1
,
None
)
!=
(
'
\0\0\0\0
'
,
(
0
,
0
)):
self
.
assertEqual
(
audioop
.
adpcm2lin
(
'
\0\0
'
,
1
,
None
),
(
'
\0\0\0\0
'
,
(
0
,
0
)))
return
0
return
1
def
testlin2adpcm
(
data
):
def
test_lin2adpcm
(
self
):
if
verbose
:
print
'lin2adpcm'
# Very cursory test
# Very cursory test
if
audioop
.
lin2adpcm
(
'
\0\0\0\0
'
,
1
,
None
)
!=
(
'
\0\0
'
,
(
0
,
0
)):
self
.
assertEqual
(
audioop
.
lin2adpcm
(
'
\0\0\0\0
'
,
1
,
None
),
(
'
\0\0
'
,
(
0
,
0
)))
return
0
return
1
def
test_lin2alaw
(
self
):
self
.
assertEqual
(
audioop
.
lin2alaw
(
data
[
0
],
1
),
'
\xd5\xc5\xf5
'
)
def
testlin2alaw
(
data
):
self
.
assertEqual
(
audioop
.
lin2alaw
(
data
[
1
],
2
),
'
\xd5\xd5\xd5
'
)
if
verbose
:
self
.
assertEqual
(
audioop
.
lin2alaw
(
data
[
2
],
4
),
'
\xd5\xd5\xd5
'
)
print
'lin2alaw'
if
audioop
.
lin2alaw
(
data
[
0
],
1
)
!=
'
\xd5\xc5\xf5
'
or
\
def
test_alaw2lin
(
self
):
audioop
.
lin2alaw
(
data
[
1
],
2
)
!=
'
\xd5\xd5\xd5
'
or
\
audioop
.
lin2alaw
(
data
[
2
],
4
)
!=
'
\xd5\xd5\xd5
'
:
return
0
return
1
def
testalaw2lin
(
data
):
if
verbose
:
print
'alaw2lin'
# Cursory
# Cursory
d
=
audioop
.
lin2alaw
(
data
[
0
],
1
)
d
=
audioop
.
lin2alaw
(
data
[
0
],
1
)
if
audioop
.
alaw2lin
(
d
,
1
)
!=
data
[
0
]:
self
.
assertEqual
(
audioop
.
alaw2lin
(
d
,
1
),
data
[
0
])
return
0
return
1
def
test_lin2ulaw
(
self
):
self
.
assertEqual
(
audioop
.
lin2ulaw
(
data
[
0
],
1
),
'
\xff\xe7\xdb
'
)
def
testlin2ulaw
(
data
):
self
.
assertEqual
(
audioop
.
lin2ulaw
(
data
[
1
],
2
),
'
\xff\xff\xff
'
)
if
verbose
:
self
.
assertEqual
(
audioop
.
lin2ulaw
(
data
[
2
],
4
),
'
\xff\xff\xff
'
)
print
'lin2ulaw'
if
audioop
.
lin2ulaw
(
data
[
0
],
1
)
!=
'
\xff\xe7\xdb
'
or
\
def
test_ulaw2lin
(
self
):
audioop
.
lin2ulaw
(
data
[
1
],
2
)
!=
'
\xff\xff\xff
'
or
\
audioop
.
lin2ulaw
(
data
[
2
],
4
)
!=
'
\xff\xff\xff
'
:
return
0
return
1
def
testulaw2lin
(
data
):
if
verbose
:
print
'ulaw2lin'
# Cursory
# Cursory
d
=
audioop
.
lin2ulaw
(
data
[
0
],
1
)
d
=
audioop
.
lin2ulaw
(
data
[
0
],
1
)
if
audioop
.
ulaw2lin
(
d
,
1
)
!=
data
[
0
]:
self
.
assertEqual
(
audioop
.
ulaw2lin
(
d
,
1
),
data
[
0
])
return
0
return
1
def
testmul
(
data
):
def
test_mul
(
self
):
if
verbose
:
print
'mul'
data2
=
[]
data2
=
[]
for
d
in
data
:
for
d
in
data
:
str
=
''
str
=
''
for
s
in
d
:
for
s
in
d
:
str
=
str
+
chr
(
ord
(
s
)
*
2
)
str
=
str
+
chr
(
ord
(
s
)
*
2
)
data2
.
append
(
str
)
data2
.
append
(
str
)
if
audioop
.
mul
(
data
[
0
],
1
,
2
)
!=
data2
[
0
]
or
\
self
.
assertEqual
(
audioop
.
mul
(
data
[
0
],
1
,
2
),
data2
[
0
])
audioop
.
mul
(
data
[
1
],
2
,
2
)
!=
data2
[
1
]
or
\
self
.
assertEqual
(
audioop
.
mul
(
data
[
1
],
2
,
2
),
data2
[
1
])
audioop
.
mul
(
data
[
2
],
4
,
2
)
!=
data2
[
2
]:
self
.
assertEqual
(
audioop
.
mul
(
data
[
2
],
4
,
2
),
data2
[
2
])
return
0
return
1
def
test_ratecv
(
self
):
def
testratecv
(
data
):
if
verbose
:
print
'ratecv'
state
=
None
state
=
None
d1
,
state
=
audioop
.
ratecv
(
data
[
0
],
1
,
1
,
8000
,
16000
,
state
)
d1
,
state
=
audioop
.
ratecv
(
data
[
0
],
1
,
1
,
8000
,
16000
,
state
)
d2
,
state
=
audioop
.
ratecv
(
data
[
0
],
1
,
1
,
8000
,
16000
,
state
)
d2
,
state
=
audioop
.
ratecv
(
data
[
0
],
1
,
1
,
8000
,
16000
,
state
)
if
d1
+
d2
!=
'
\000\000\001\001\002\001\000\000\001\001\002
'
:
self
.
assertEqual
(
d1
+
d2
,
'
\000\000\001\001\002\001\000\000\001\001\002
'
)
return
0
return
1
def
test_reverse
(
self
):
self
.
assertEqual
(
audioop
.
reverse
(
data
[
0
],
1
),
'
\2\1\0
'
)
def
testreverse
(
data
):
if
verbose
:
def
test_tomono
(
self
):
print
'reverse'
if
audioop
.
reverse
(
data
[
0
],
1
)
!=
'
\2\1\0
'
:
return
0
return
1
def
testtomono
(
data
):
if
verbose
:
print
'tomono'
data2
=
''
data2
=
''
for
d
in
data
[
0
]:
for
d
in
data
[
0
]:
data2
=
data2
+
d
+
d
data2
=
data2
+
d
+
d
if
audioop
.
tomono
(
data2
,
1
,
0.5
,
0.5
)
!=
data
[
0
]:
self
.
assertEqual
(
audioop
.
tomono
(
data2
,
1
,
0.5
,
0.5
),
data
[
0
])
return
0
return
1
def
testtostereo
(
data
):
def
test_tostereo
(
self
):
if
verbose
:
print
'tostereo'
data2
=
''
data2
=
''
for
d
in
data
[
0
]:
for
d
in
data
[
0
]:
data2
=
data2
+
d
+
d
data2
=
data2
+
d
+
d
if
audioop
.
tostereo
(
data
[
0
],
1
,
1
,
1
)
!=
data2
:
self
.
assertEqual
(
audioop
.
tostereo
(
data
[
0
],
1
,
1
,
1
),
data2
)
return
0
return
1
def
testfindfactor
(
data
):
if
verbose
:
print
'findfactor'
if
audioop
.
findfactor
(
data
[
1
],
data
[
1
])
!=
1.0
:
return
0
return
1
def
testfindfit
(
data
):
if
verbose
:
print
'findfit'
if
audioop
.
findfit
(
data
[
1
],
data
[
1
])
!=
(
0
,
1.0
):
return
0
return
1
def
testfindmax
(
data
):
if
verbose
:
print
'findmax'
if
audioop
.
findmax
(
data
[
1
],
1
)
!=
2
:
return
0
return
1
def
testgetsample
(
data
):
if
verbose
:
print
'getsample'
for
i
in
range
(
3
):
if
audioop
.
getsample
(
data
[
0
],
1
,
i
)
!=
i
or
\
audioop
.
getsample
(
data
[
1
],
2
,
i
)
!=
i
or
\
audioop
.
getsample
(
data
[
2
],
4
,
i
)
!=
i
:
return
0
return
1
def
testone
(
name
,
data
):
try
:
func
=
eval
(
'test'
+
name
)
except
NameError
:
print
'No test found for audioop.'
+
name
+
'()'
return
try
:
rv
=
func
(
data
)
except
'xx'
:
print
'Test FAILED for audioop.'
+
name
+
'() (with an exception)'
return
if
not
rv
:
print
'Test FAILED for audioop.'
+
name
+
'()'
def
test_main
():
def
test_findfactor
(
self
):
data
=
[
gendata1
(),
gendata2
(),
gendata4
()]
self
.
assertEqual
(
audioop
.
findfactor
(
data
[
1
],
data
[
1
]),
1.0
)
names
=
dir
(
audioop
)
# We know there is a routine 'add'
def
test_findfit
(
self
):
routines
=
[]
self
.
assertEqual
(
audioop
.
findfit
(
data
[
1
],
data
[
1
]),
(
0
,
1.0
))
for
n
in
names
:
if
type
(
eval
(
'audioop.'
+
n
))
==
type
(
audioop
.
add
):
def
test_findmax
(
self
):
routines
.
append
(
n
)
self
.
assertEqual
(
audioop
.
findmax
(
data
[
1
],
1
),
2
)
for
n
in
routines
:
testone
(
n
,
data
)
def
test_getsample
(
self
):
for
i
in
range
(
3
):
self
.
assertEqual
(
audioop
.
getsample
(
data
[
0
],
1
,
i
),
i
)
self
.
assertEqual
(
audioop
.
getsample
(
data
[
1
],
2
,
i
),
i
)
self
.
assertEqual
(
audioop
.
getsample
(
data
[
2
],
4
,
i
),
i
)
def
test_main
():
run_unittest
(
TestAudioop
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_main
()
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment