From 0a944f1f58124bccf8ebbfc77c6f6f6e3889c9c5 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 26 May 2025 00:18:53 +0100 Subject: [PATCH] check for error code 600 and print error message add filter tests --- obsws_cli/filter.py | 10 +++++++++- tests/test_filter.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/test_filter.py diff --git a/obsws_cli/filter.py b/obsws_cli/filter.py index 507e32f..d408dfb 100644 --- a/obsws_cli/filter.py +++ b/obsws_cli/filter.py @@ -1,5 +1,6 @@ """module containing commands for manipulating filters in scenes.""" +import obsws_python as obsws import typer from rich.console import Console from rich.table import Table @@ -20,7 +21,14 @@ def main(): @app.command('list | ls') def list(ctx: typer.Context, source_name: str): """List filters for a source.""" - resp = ctx.obj.get_source_filter_list(source_name) + try: + resp = ctx.obj.get_source_filter_list(source_name) + except obsws.error.OBSSDKError as e: + if e.code == 600: + err_console.print(f"No source was found by the name of '{source_name}'.") + raise typer.Exit(1) + else: + raise if not resp.filters: out_console.print(f'No filters found for source {source_name}') diff --git a/tests/test_filter.py b/tests/test_filter.py new file mode 100644 index 0000000..1ffc185 --- /dev/null +++ b/tests/test_filter.py @@ -0,0 +1,30 @@ +"""Unit tests for the filter command in the OBS WebSocket CLI.""" + +from typer.testing import CliRunner + +from obsws_cli.app import app + +runner = CliRunner(mix_stderr=False) + + +def test_filter_list(): + """Test the filter list command on an audio source.""" + result = runner.invoke(app, ['filter', 'list', 'Mic/Aux']) + assert result.exit_code == 0 + assert 'Filters for Source: Mic/Aux' in result.stdout + assert 'pytest filter' in result.stdout + + +def test_filter_list_scene(): + """Test the filter list command on a scene.""" + result = runner.invoke(app, ['filter', 'list', 'pytest_scene']) + assert result.exit_code == 0 + assert 'Filters for Source: pytest_scene' in result.stdout + assert 'pytest filter' in result.stdout + + +def test_filter_list_invalid_source(): + """Test the filter list command with an invalid source.""" + result = runner.invoke(app, ['filter', 'list', 'invalid_source']) + assert result.exit_code != 0 + assert "No source was found by the name of 'invalid_source'" in result.stderr