mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2026-04-18 06:53:39 +00:00
add ruff config
run files through formatter add dosctrings to satisfy the linter
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Test suite for the slobs_cli package."""
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""pytest configuration for async tests using anyio."""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def anyio_backend():
|
||||
return "asyncio"
|
||||
"""Return the backend to use for async tests."""
|
||||
return 'asyncio'
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
"""Create test scenes in Streamlabs.
|
||||
|
||||
Usage:
|
||||
Run this script as a standalone program to setup the test environment.
|
||||
Requires 'SLOBS_DOMAIN' and 'SLOBS_TOKEN' environment variables to be set.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import anyio
|
||||
@@ -6,20 +13,22 @@ from pyslobs import ConnectionConfig, ScenesService, SlobsConnection
|
||||
|
||||
|
||||
async def setup(conn: SlobsConnection):
|
||||
"""Set up test scenes in Streamlabs OBS."""
|
||||
ss = ScenesService(conn)
|
||||
await ss.create_scene("slobs-test-scene-1")
|
||||
await ss.create_scene("slobs-test-scene-2")
|
||||
await ss.create_scene("slobs-test-scene-3")
|
||||
await ss.create_scene('slobs-test-scene-1')
|
||||
await ss.create_scene('slobs-test-scene-2')
|
||||
await ss.create_scene('slobs-test-scene-3')
|
||||
|
||||
conn.close()
|
||||
|
||||
|
||||
async def main():
|
||||
"""Establish connection and set up scenes."""
|
||||
conn = SlobsConnection(
|
||||
ConnectionConfig(
|
||||
domain=os.environ["SLOBS_DOMAIN"],
|
||||
domain=os.environ['SLOBS_DOMAIN'],
|
||||
port=59650,
|
||||
token=os.environ["SLOBS_TOKEN"],
|
||||
token=os.environ['SLOBS_TOKEN'],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -28,5 +37,5 @@ async def main():
|
||||
tg.start_soon(setup, conn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
anyio.run(main)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
"""Remove test scenes in Streamlabs, disable streaming, recording, and replay buffer.
|
||||
|
||||
Usage:
|
||||
Run this script as a standalone program to tear down the test environment.
|
||||
Requires 'SLOBS_DOMAIN' and 'SLOBS_TOKEN' environment variables to be set.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import anyio
|
||||
@@ -6,30 +13,32 @@ from pyslobs import ConnectionConfig, ScenesService, SlobsConnection, StreamingS
|
||||
|
||||
|
||||
async def cleanup(conn: SlobsConnection):
|
||||
"""Clean up test scenes and ensure streaming, recording, and replay buffer are stopped."""
|
||||
ss = ScenesService(conn)
|
||||
scenes = await ss.get_scenes()
|
||||
for scene in scenes:
|
||||
if scene.name.startswith("slobs-test-scene-"):
|
||||
if scene.name.startswith('slobs-test-scene-'):
|
||||
await ss.remove_scene(scene.id)
|
||||
|
||||
ss = StreamingService(conn)
|
||||
model = await ss.get_model()
|
||||
if model.streaming_status != "offline":
|
||||
if model.streaming_status != 'offline':
|
||||
await ss.toggle_streaming()
|
||||
if model.replay_buffer_status != "offline":
|
||||
if model.replay_buffer_status != 'offline':
|
||||
await ss.stop_replay_buffer()
|
||||
if model.recording_status != "offline":
|
||||
if model.recording_status != 'offline':
|
||||
await ss.toggle_recording()
|
||||
|
||||
conn.close()
|
||||
|
||||
|
||||
async def main():
|
||||
"""Establish connection and clean up test scenes."""
|
||||
conn = SlobsConnection(
|
||||
ConnectionConfig(
|
||||
domain=os.environ["SLOBS_DOMAIN"],
|
||||
domain=os.environ['SLOBS_DOMAIN'],
|
||||
port=59650,
|
||||
token=os.environ["SLOBS_TOKEN"],
|
||||
token=os.environ['SLOBS_TOKEN'],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -38,5 +47,5 @@ async def main():
|
||||
tg.start_soon(cleanup, conn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
anyio.run(main)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"""Test cases for the recording commands of the slobs_cli CLI application."""
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
@@ -7,33 +9,35 @@ from slobs_cli import cli
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_record_start():
|
||||
"""Test the start recording command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["record", "status"])
|
||||
result = await runner.invoke(cli, ['record', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Recording is currently active." in result.output
|
||||
active = 'Recording is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["record", "start"])
|
||||
result = await runner.invoke(cli, ['record', 'start'])
|
||||
if not active:
|
||||
assert result.exit_code == 0
|
||||
assert "Recording started" in result.output
|
||||
assert 'Recording started' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the recording to start
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Recording is already active." in result.output
|
||||
assert 'Recording is already active.' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_record_stop():
|
||||
"""Test the stop recording command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["record", "status"])
|
||||
result = await runner.invoke(cli, ['record', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Recording is currently active." in result.output
|
||||
active = 'Recording is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["record", "stop"])
|
||||
result = await runner.invoke(cli, ['record', 'stop'])
|
||||
if active:
|
||||
assert result.exit_code == 0
|
||||
assert "Recording stopped" in result.output
|
||||
assert 'Recording stopped' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the recording to stop
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Recording is already inactive." in result.output
|
||||
assert 'Recording is already inactive.' in result.output
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"""Test cases for the replay buffer commands in slobs_cli."""
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
@@ -7,33 +9,35 @@ from slobs_cli import cli
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_replaybuffer_start():
|
||||
"""Test the start replay buffer command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["replaybuffer", "status"])
|
||||
result = await runner.invoke(cli, ['replaybuffer', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Replay buffer is currently active." in result.output
|
||||
active = 'Replay buffer is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["replaybuffer", "start"])
|
||||
result = await runner.invoke(cli, ['replaybuffer', 'start'])
|
||||
if not active:
|
||||
assert result.exit_code == 0
|
||||
assert "Replay buffer started" in result.output
|
||||
assert 'Replay buffer started' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the replay buffer to start
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Replay buffer is already active." in result.output
|
||||
assert 'Replay buffer is already active.' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_replaybuffer_stop():
|
||||
"""Test the stop replay buffer command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["replaybuffer", "status"])
|
||||
result = await runner.invoke(cli, ['replaybuffer', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Replay buffer is currently active." in result.output
|
||||
active = 'Replay buffer is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["replaybuffer", "stop"])
|
||||
result = await runner.invoke(cli, ['replaybuffer', 'stop'])
|
||||
if active:
|
||||
assert result.exit_code == 0
|
||||
assert "Replay buffer stopped" in result.output
|
||||
assert 'Replay buffer stopped' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the replay buffer to stop
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Replay buffer is already inactive." in result.output
|
||||
assert 'Replay buffer is already inactive.' in result.output
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"""Test cases for scene commands in slobs_cli."""
|
||||
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
|
||||
@@ -6,20 +8,22 @@ from slobs_cli import cli
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_scene_list():
|
||||
"""Test the list scenes command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["scene", "list"])
|
||||
result = await runner.invoke(cli, ['scene', 'list'])
|
||||
assert result.exit_code == 0
|
||||
assert "slobs-test-scene-1" in result.output
|
||||
assert "slobs-test-scene-2" in result.output
|
||||
assert "slobs-test-scene-3" in result.output
|
||||
assert 'slobs-test-scene-1' in result.output
|
||||
assert 'slobs-test-scene-2' in result.output
|
||||
assert 'slobs-test-scene-3' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_scene_current():
|
||||
"""Test the current scene command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["scene", "switch", "slobs-test-scene-2"])
|
||||
result = await runner.invoke(cli, ['scene', 'switch', 'slobs-test-scene-2'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
result = await runner.invoke(cli, ["scene", "current"])
|
||||
result = await runner.invoke(cli, ['scene', 'current'])
|
||||
assert result.exit_code == 0
|
||||
assert "Current active scene: slobs-test-scene-2" in result.output
|
||||
assert 'Current active scene: slobs-test-scene-2' in result.output
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"""Tests for the stream commands in slobs_cli."""
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
@@ -7,33 +9,35 @@ from slobs_cli import cli
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_start():
|
||||
"""Test the start stream command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["stream", "status"])
|
||||
result = await runner.invoke(cli, ['stream', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Stream is currently active." in result.output
|
||||
active = 'Stream is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["stream", "start"])
|
||||
result = await runner.invoke(cli, ['stream', 'start'])
|
||||
if not active:
|
||||
assert result.exit_code == 0
|
||||
assert "Stream started" in result.output
|
||||
assert 'Stream started' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the stream to start
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Stream is already active." in result.output
|
||||
assert 'Stream is already active.' in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_stop():
|
||||
"""Test the stop stream command."""
|
||||
runner = CliRunner()
|
||||
result = await runner.invoke(cli, ["stream", "status"])
|
||||
result = await runner.invoke(cli, ['stream', 'status'])
|
||||
assert result.exit_code == 0
|
||||
active = "Stream is currently active." in result.output
|
||||
active = 'Stream is currently active.' in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["stream", "stop"])
|
||||
result = await runner.invoke(cli, ['stream', 'stop'])
|
||||
if active:
|
||||
assert result.exit_code == 0
|
||||
assert "Stream stopped" in result.output
|
||||
assert 'Stream stopped' in result.output
|
||||
await anyio.sleep(0.2) # Allow some time for the stream to stop
|
||||
else:
|
||||
assert result.exit_code != 0
|
||||
assert "Stream is already inactive." in result.output
|
||||
assert 'Stream is already inactive.' in result.output
|
||||
|
||||
Reference in New Issue
Block a user