mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-04-17 22:43:38 +00:00
first commit
This commit is contained in:
3
tests/__init__.py
Normal file
3
tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
74
tests/conftest.py
Normal file
74
tests/conftest.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""pytest configuration file."""
|
||||
|
||||
import os
|
||||
|
||||
import obsws_python as obsws
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""Call after command line options are parsed.
|
||||
|
||||
All plugins and initial conftest files are loaded.
|
||||
"""
|
||||
|
||||
|
||||
def pytest_sessionstart(session):
|
||||
"""Call after the Session object is created.
|
||||
|
||||
Before performing collection and entering the run test loop.
|
||||
"""
|
||||
# Initialize the OBS WebSocket client
|
||||
session.obsws = obsws.ReqClient(
|
||||
host=os.environ['OBSWS_HOST'],
|
||||
port=os.environ['OBSWS_PORT'],
|
||||
password=os.environ['OBSWS_PASSWORD'],
|
||||
timeout=5,
|
||||
)
|
||||
resp = session.obsws.get_version()
|
||||
|
||||
out = (
|
||||
'Running tests with:',
|
||||
f'OBS Client version: {resp.obs_version} with WebSocket version: {resp.obs_web_socket_version}',
|
||||
)
|
||||
print(' '.join(out))
|
||||
|
||||
session.obsws.create_scene('pytest')
|
||||
session.obsws.create_input(
|
||||
sceneName='pytest',
|
||||
inputName='pytest_input',
|
||||
inputKind='color_source_v3',
|
||||
inputSettings={
|
||||
'color': 3279460728,
|
||||
'width': 1920,
|
||||
'height': 1080,
|
||||
'visible': True,
|
||||
},
|
||||
sceneItemEnabled=True,
|
||||
)
|
||||
session.obsws.create_input(
|
||||
sceneName='pytest',
|
||||
inputName='pytest_input_2',
|
||||
inputKind='color_source_v3',
|
||||
inputSettings={
|
||||
'color': 1789347616,
|
||||
'width': 720,
|
||||
'height': 480,
|
||||
'visible': True,
|
||||
},
|
||||
sceneItemEnabled=True,
|
||||
)
|
||||
|
||||
|
||||
def pytest_sessionfinish(session, exitstatus):
|
||||
"""Call after the whole test run finishes.
|
||||
|
||||
Return the exit status to the system.
|
||||
"""
|
||||
session.obsws.remove_scene('pytest')
|
||||
|
||||
# Close the OBS WebSocket client connection
|
||||
session.obsws.disconnect()
|
||||
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
"""Call before test process is exited."""
|
||||
15
tests/test_cli.py
Normal file
15
tests/test_cli.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""Unit tests for the root command in the OBS WebSocket CLI."""
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from obsws_cli.app import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_version():
|
||||
"""Test the version command."""
|
||||
result = runner.invoke(app, ['version'])
|
||||
assert result.exit_code == 0
|
||||
assert 'OBS Client version' in result.stdout
|
||||
assert 'WebSocket version' in result.stdout
|
||||
15
tests/test_item.py
Normal file
15
tests/test_item.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""Unit tests for the item command in the OBS WebSocket CLI."""
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from obsws_cli.app import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_item_list():
|
||||
"""Test the item list command."""
|
||||
result = runner.invoke(app, ['item', 'list', 'pytest'])
|
||||
assert result.exit_code == 0
|
||||
assert 'pytest_input' in result.stdout
|
||||
assert 'pytest_input_2' in result.stdout
|
||||
32
tests/test_record.py
Normal file
32
tests/test_record.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Unit tests for the record command in the OBS WebSocket CLI."""
|
||||
|
||||
import time
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from obsws_cli.app import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_record_start_status_stop():
|
||||
"""Test the record start command."""
|
||||
result = runner.invoke(app, ['record', 'start'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Recording started successfully.' in result.stdout
|
||||
|
||||
time.sleep(0.5) # Wait for the recording to start
|
||||
|
||||
result = runner.invoke(app, ['record', 'status'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Recording is in progress.' in result.stdout
|
||||
|
||||
result = runner.invoke(app, ['record', 'stop'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Recording stopped successfully.' in result.stdout
|
||||
|
||||
time.sleep(0.5) # Wait for the recording to stop
|
||||
|
||||
result = runner.invoke(app, ['record', 'status'])
|
||||
assert result.exit_code == 0
|
||||
assert 'Recording is not in progress.' in result.stdout
|
||||
22
tests/test_scene.py
Normal file
22
tests/test_scene.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Unit tests for the scene commands in the OBS WebSocket CLI."""
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from obsws_cli.app import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_scene_list():
|
||||
"""Test the scene list command."""
|
||||
result = runner.invoke(app, ['scene', 'list'])
|
||||
assert result.exit_code == 0
|
||||
assert 'pytest' in result.stdout
|
||||
|
||||
|
||||
def test_scene_current():
|
||||
"""Test the scene current command."""
|
||||
runner.invoke(app, ['scene', 'switch', 'pytest'])
|
||||
result = runner.invoke(app, ['scene', 'current'])
|
||||
assert result.exit_code == 0
|
||||
assert 'pytest' in result.stdout
|
||||
Reference in New Issue
Block a user