Skip to content

Commit 66a0bd9

Browse files
committed
Xfail tests when audio devices are missing.
1 parent 4990592 commit 66a0bd9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test_sdl_audio.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313
# ruff: noqa: D103
1414

1515

16+
needs_audio_device = pytest.mark.xfail(
17+
not list(tcod.sdl.audio.get_devices()), reason="This test requires an audio device"
18+
)
19+
needs_audio_capture = pytest.mark.xfail(
20+
not list(tcod.sdl.audio.get_capture_devices()), reason="This test requires an audio capture device"
21+
)
22+
23+
1624
def test_devices() -> None:
1725
list(tcod.sdl.audio.get_devices())
1826
list(tcod.sdl.audio.get_capture_devices())
1927

2028

29+
@needs_audio_device
2130
def test_audio_device() -> None:
2231
with tcod.sdl.audio.open(frequency=44100, format=np.float32, channels=2, paused=True) as device:
2332
assert not device.stopped
@@ -47,14 +56,17 @@ def test_audio_device() -> None:
4756
mixer.stop()
4857

4958

59+
@needs_audio_capture
5060
def test_audio_capture() -> None:
5161
with tcod.sdl.audio.open(capture=True) as device:
5262
assert not device.stopped
5363
assert isinstance(device.dequeue_audio(), np.ndarray)
5464

5565

66+
@needs_audio_device
5667
def test_audio_device_repr() -> None:
5768
with tcod.sdl.audio.open(format=np.uint16, paused=True, callback=True) as device:
69+
assert not device.stopped
5870
assert "silence=" in repr(device)
5971
assert "callback=" in repr(device)
6072
assert "stopped=" in repr(device)
@@ -83,6 +95,7 @@ def test_convert_float64() -> None:
8395
)
8496

8597

98+
@needs_audio_device
8699
def test_audio_callback() -> None:
87100
class CheckCalled:
88101
was_called: bool = False
@@ -95,13 +108,15 @@ def __call__(self, device: tcod.sdl.audio.AudioDevice, stream: NDArray[Any]) ->
95108

96109
check_called = CheckCalled()
97110
with tcod.sdl.audio.open(callback=check_called, paused=False) as device:
111+
assert not device.stopped
98112
device.callback = device.callback
99113
while not check_called.was_called:
100114
time.sleep(0.001)
101115

102116

103117
@pytest.mark.skipif(sys.version_info < (3, 8), reason="Needs sys.unraisablehook support")
104118
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
119+
@needs_audio_device
105120
def test_audio_callback_unraisable() -> None:
106121
"""Test unraisable error in audio callback.
107122
@@ -116,6 +131,7 @@ def __call__(self, device: tcod.sdl.audio.AudioDevice, stream: NDArray[Any]) ->
116131
raise Exception("Test unraisable error") # noqa
117132

118133
check_called = CheckCalled()
119-
with tcod.sdl.audio.open(callback=check_called, paused=False):
134+
with tcod.sdl.audio.open(callback=check_called, paused=False) as device:
135+
assert not device.stopped
120136
while not check_called.was_called:
121137
time.sleep(0.001)

0 commit comments

Comments
 (0)