chore: make pyright happy on tests

This commit is contained in:
Matteo Bernardini
2025-08-06 18:04:54 +08:00
committed by Lars Immisch
parent 0b8db5f46d
commit a48389b750

View File

@@ -13,14 +13,16 @@ import alsaaudio
import warnings import warnings
from contextlib import closing from contextlib import closing
MethodsType = list[tuple[str, tuple[int, ...] | None]]
# we can't test read and write well - these are tested otherwise # we can't test read and write well - these are tested otherwise
PCMMethods = [ PCMMethods: MethodsType = [
('pcmtype', None), ('pcmtype', None),
('pcmmode', None), ('pcmmode', None),
('cardname', None) ('cardname', None)
] ]
PCMDeprecatedMethods = [ PCMDeprecatedMethods: MethodsType = [
('setchannels', (2,)), ('setchannels', (2,)),
('setrate', (44100,)), ('setrate', (44100,)),
('setformat', (alsaaudio.PCM_FORMAT_S8,)), ('setformat', (alsaaudio.PCM_FORMAT_S8,)),
@@ -30,7 +32,8 @@ PCMDeprecatedMethods = [
# A clever test would look at the Mixer capabilities and selectively run the # A clever test would look at the Mixer capabilities and selectively run the
# omitted tests, but I am too tired for that. # omitted tests, but I am too tired for that.
MixerMethods = [('cardname', None), MixerMethods: MethodsType = [
('cardname', None),
('mixer', None), ('mixer', None),
('mixerid', None), ('mixerid', None),
('switchcap', None), ('switchcap', None),
@@ -43,7 +46,7 @@ MixerMethods = [('cardname', None),
# ('setvolume', (60,)), # ('setvolume', (60,)),
# ('setmute', (0,)) # ('setmute', (0,))
# ('setrec', (0')), # ('setrec', (0')),
] ]
class MixerTest(unittest.TestCase): class MixerTest(unittest.TestCase):
"""Test Mixer objects""" """Test Mixer objects"""
@@ -162,25 +165,25 @@ class PollDescriptorArgsTest(unittest.TestCase):
def testArgsNoList(self): def testArgsNoList(self):
with closing(alsaaudio.PCM()) as pcm: with closing(alsaaudio.PCM()) as pcm:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pcm.polldescriptors_revents('foo') pcm.polldescriptors_revents('foo') # pyright: ignore[reportArgumentType]
def testArgsListButNoTuples(self): def testArgsListButNoTuples(self):
with closing(alsaaudio.PCM()) as pcm: with closing(alsaaudio.PCM()) as pcm:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pcm.polldescriptors_revents(['foo', 1]) pcm.polldescriptors_revents(['foo', 1]) # pyright: ignore[reportArgumentType]
def testArgsListButInvalidTuples(self): def testArgsListButInvalidTuples(self):
with closing(alsaaudio.PCM()) as pcm: with closing(alsaaudio.PCM()) as pcm:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pcm.polldescriptors_revents([('foo', 'bar')]) pcm.polldescriptors_revents([('foo', 'bar')]) # pyright: ignore[reportArgumentType]
def testArgsListTupleWrongLength(self): def testArgsListTupleWrongLength(self):
with closing(alsaaudio.PCM()) as pcm: with closing(alsaaudio.PCM()) as pcm:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pcm.polldescriptors_revents([(1, )]) pcm.polldescriptors_revents([(1, )]) # pyright: ignore[reportArgumentType]
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pcm.polldescriptors_revents([(1, 2, 3)]) pcm.polldescriptors_revents([(1, 2, 3)]) # pyright: ignore[reportArgumentType]
if __name__ == '__main__': if __name__ == '__main__':