mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2025-06-27 15:20:24 +01:00
add audio unit tests
add audio status command patch bump
This commit is contained in:
parent
57e31a7e49
commit
bc43c8483a
@ -1,3 +1,3 @@
|
||||
"""module for package metadata."""
|
||||
|
||||
__version__ = '0.9.1'
|
||||
__version__ = '0.9.2'
|
||||
|
@ -75,10 +75,10 @@ async def mute(ctx: click.Context, source_name: str):
|
||||
break
|
||||
else: # If no source by the given name was found
|
||||
conn.close()
|
||||
raise SlobsCliError(f"Source '{source_name}' not found.")
|
||||
raise SlobsCliError(f'Audio source "{source_name}" not found.')
|
||||
|
||||
await source.set_muted(True)
|
||||
click.echo(f'Muted audio source: {source_name}')
|
||||
click.echo(f'{source_name} muted successfully.')
|
||||
conn.close()
|
||||
|
||||
try:
|
||||
@ -106,10 +106,10 @@ async def unmute(ctx: click.Context, source_name: str):
|
||||
break
|
||||
else: # If no source by the given name was found
|
||||
conn.close()
|
||||
raise SlobsCliError(f"Source '{source_name}' not found.")
|
||||
raise SlobsCliError(f'Audio source "{source_name}" not found.')
|
||||
|
||||
await source.set_muted(False)
|
||||
click.echo(f'Unmuted audio source: {source_name}')
|
||||
click.echo(f'{source_name} unmuted successfully.')
|
||||
conn.close()
|
||||
|
||||
try:
|
||||
@ -136,15 +136,46 @@ async def toggle(ctx: click.Context, source_name: str):
|
||||
if model.name.lower() == source_name.lower():
|
||||
if model.muted:
|
||||
await source.set_muted(False)
|
||||
click.echo(f'Unmuted audio source: {source_name}')
|
||||
click.echo(f'{source_name} unmuted successfully.')
|
||||
else:
|
||||
await source.set_muted(True)
|
||||
click.echo(f'Muted audio source: {source_name}')
|
||||
click.echo(f'{source_name} muted successfully.')
|
||||
conn.close()
|
||||
break
|
||||
else: # If no source by the given name was found
|
||||
conn.close()
|
||||
raise SlobsCliError(f"Source '{source_name}' not found.")
|
||||
raise SlobsCliError(f'Audio source "{source_name}" not found.')
|
||||
|
||||
try:
|
||||
async with create_task_group() as tg:
|
||||
tg.start_soon(conn.background_processing)
|
||||
tg.start_soon(_run)
|
||||
except* SlobsCliError as excgroup:
|
||||
for e in excgroup.exceptions:
|
||||
raise e
|
||||
|
||||
|
||||
@audio.command()
|
||||
@click.argument('source_name')
|
||||
@click.pass_context
|
||||
async def status(ctx: click.Context, source_name: str):
|
||||
"""Get the mute status of an audio source by name."""
|
||||
conn = ctx.obj['connection']
|
||||
as_ = AudioService(conn)
|
||||
|
||||
async def _run():
|
||||
sources = await as_.get_sources()
|
||||
for source in sources:
|
||||
model = await source.get_model()
|
||||
if model.name.lower() == source_name.lower():
|
||||
click.echo(
|
||||
f'"{source_name}" is {"muted" if model.muted else "unmuted"}.'
|
||||
)
|
||||
conn.close()
|
||||
return
|
||||
else:
|
||||
conn.close()
|
||||
raise SlobsCliError(f'Audio source "{source_name}" not found.')
|
||||
|
||||
try:
|
||||
async with create_task_group() as tg:
|
||||
|
@ -84,7 +84,7 @@ async def current(ctx: click.Context, id: bool = False):
|
||||
|
||||
@scene.command()
|
||||
@click.option('--id', is_flag=True, help='Include scene IDs in the output.')
|
||||
@click.argument('scene_name', type=str)
|
||||
@click.argument('scene_name')
|
||||
@click.option(
|
||||
'--preview',
|
||||
is_flag=True,
|
||||
|
43
tests/test_audio.py
Normal file
43
tests/test_audio.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Test cases for audio commands in slobs_cli."""
|
||||
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
|
||||
from slobs_cli import cli
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_audio_list():
|
||||
"""Test the list audio sources command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ['audio', 'list'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Desktop Audio' in result.output
|
||||
assert 'Mic/Aux' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_audio_mute():
|
||||
"""Test the mute audio source command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ['audio', 'mute', 'Mic/Aux'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Mic/Aux muted successfully' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_audio_unmute():
|
||||
"""Test the unmute audio source command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ['audio', 'unmute', 'Mic/Aux'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Mic/Aux unmuted successfully' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_audio_invalid_source():
|
||||
"""Test handling of invalid audio source."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ['audio', 'mute', 'InvalidSource'])
|
||||
assert result.exit_code != 0
|
||||
assert 'Audio source "InvalidSource" not found' in result.output
|
Loading…
x
Reference in New Issue
Block a user