Tests for Depreciations

This commit is contained in:
Lars Immisch
2020-07-13 20:20:28 +02:00
parent 0224c8a308
commit 08bdce9ed9

31
test.py
View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- mode: python; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
# These are internal tests. They shouldn't fail, but they don't cover all
# of the ALSA API. Most importantly PCM.read and PCM.write are missing.
@@ -12,13 +13,18 @@ import alsaaudio
import warnings
# we can't test read and write well - these are tested otherwise
PCMMethods = [('pcmtype', None),
PCMMethods = [
('pcmtype', None),
('pcmmode', None),
('cardname', None),
('cardname', None)
]
PCMDeprecatedMethods = [
('setchannels', (2,)),
('setrate', (44100,)),
('setformat', (alsaaudio.PCM_FORMAT_S8,)),
('setperiodsize', (320,))]
('setperiodsize', (320,))
]
# A clever test would look at the Mixer capabilities and selectively run the
# omitted tests, but I am too tired for that.
@@ -132,5 +138,22 @@ class PCMTest(unittest.TestCase):
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
for m, a in PCMDeprecatedMethods:
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
pcm = alsaaudio.PCM()
f = alsaaudio.PCM.__dict__[m]
if a is None:
f(pcm)
else:
f(pcm, *a)
# Verify we got a DepreciationWarning
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
if __name__ == '__main__':
unittest.main()