mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2025-02-22 09:45:17 +00:00
import Callable, Iterable from collections.abs instead of typing.
update tests to reflect changes in the API. reorganise hatch envs add black,isort configs to pyproject.toml add pre-commit config
This commit is contained in:
parent
0fe78197fc
commit
797161a6f2
2
.gitignore
vendored
2
.gitignore
vendored
@ -51,7 +51,7 @@ venv.bak/
|
|||||||
.python-version
|
.python-version
|
||||||
|
|
||||||
# Test/config
|
# Test/config
|
||||||
quick.py
|
test-*.py
|
||||||
config.toml
|
config.toml
|
||||||
obsws.log
|
obsws.log
|
||||||
|
|
||||||
|
10
.pre-commit-config.yaml
Normal file
10
.pre-commit-config.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: format
|
||||||
|
name: format
|
||||||
|
entry: hatch run style:fmt
|
||||||
|
language: system
|
||||||
|
pass_filenames: false
|
||||||
|
verbose: true
|
||||||
|
files: \.(py)$
|
26
README.md
26
README.md
@ -1,5 +1,6 @@
|
|||||||
[](https://badge.fury.io/py/obsws-python)
|
[](https://badge.fury.io/py/obsws-python)
|
||||||
[](https://github.com/aatikturk/obsstudio_sdk/blob/main/LICENSE)
|
[](https://github.com/aatikturk/obsstudio_sdk/blob/main/LICENSE)
|
||||||
|
[][obsws-events]
|
||||||
[](https://github.com/psf/black)
|
[](https://github.com/psf/black)
|
||||||
[](https://pycqa.github.io/isort/)
|
[](https://pycqa.github.io/isort/)
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ resp = cl_req.send("GetVersion", raw=True)
|
|||||||
print(f"response data: {resp}")
|
print(f"response data: {resp}")
|
||||||
```
|
```
|
||||||
|
|
||||||
For a full list of requests refer to [Requests](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)
|
For a full list of requests refer to [Requests][obsws-reqs]
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ cl.callback.deregister(on_input_mute_state_changed)
|
|||||||
|
|
||||||
`register(fns)` and `deregister(fns)` accept both single functions and lists of functions.
|
`register(fns)` and `deregister(fns)` accept both single functions and lists of functions.
|
||||||
|
|
||||||
For a full list of events refer to [Events](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events)
|
For a full list of events refer to [Events][obsws-events]
|
||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ def on_scene_created(data):
|
|||||||
- The following attributes are available:
|
- The following attributes are available:
|
||||||
- `req_name`: name of the request.
|
- `req_name`: name of the request.
|
||||||
- `code`: request status code.
|
- `code`: request status code.
|
||||||
- For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
- For a full list of status codes refer to [Codes][obsws-codes]
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
|
|
||||||
@ -168,18 +169,19 @@ logging.basicConfig(level=logging.DEBUG)
|
|||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
First install development dependencies:
|
Install [hatch][hatch-install] and then:
|
||||||
|
|
||||||
`pip install -e .['dev']`
|
`hatch test`
|
||||||
|
|
||||||
To run all tests:
|
|
||||||
|
|
||||||
```
|
|
||||||
pytest -v
|
|
||||||
```
|
|
||||||
|
|
||||||
### Official Documentation
|
### Official Documentation
|
||||||
|
|
||||||
For the full documentation:
|
For the full documentation:
|
||||||
|
|
||||||
- [OBS Websocket SDK](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#obs-websocket-501-protocol)
|
- [OBS Websocket SDK][obsws-pro]
|
||||||
|
|
||||||
|
|
||||||
|
[obsws-reqs]: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests
|
||||||
|
[obsws-events]: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events
|
||||||
|
[obsws-codes]: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus
|
||||||
|
[obsws-pro]: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#obs-websocket-501-protocol
|
||||||
|
[hatch-install]: https://hatch.pypa.io/latest/install/
|
||||||
|
@ -96,10 +96,8 @@ class ObsClient:
|
|||||||
|
|
||||||
auth = base64.b64encode(
|
auth = base64.b64encode(
|
||||||
hashlib.sha256(
|
hashlib.sha256(
|
||||||
(
|
|
||||||
secret
|
secret
|
||||||
+ self.server_hello["d"]["authentication"]["challenge"].encode()
|
+ self.server_hello["d"]["authentication"]["challenge"].encode()
|
||||||
)
|
|
||||||
).digest()
|
).digest()
|
||||||
).decode()
|
).decode()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from typing import Callable, Iterable, Union
|
from collections.abc import Callable, Iterable
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from .util import as_dataclass, to_camel_case, to_snake_case
|
from .util import as_dataclass, to_camel_case, to_snake_case
|
||||||
|
|
||||||
|
@ -17,14 +17,6 @@ dependencies = [
|
|||||||
"websocket-client",
|
"websocket-client",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
|
||||||
dev = [
|
|
||||||
"black",
|
|
||||||
"isort",
|
|
||||||
"pytest",
|
|
||||||
"pytest-randomly",
|
|
||||||
]
|
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://github.com/aatikturk/obsws-python"
|
Homepage = "https://github.com/aatikturk/obsws-python"
|
||||||
|
|
||||||
@ -36,19 +28,58 @@ include = [
|
|||||||
"/obsws_python",
|
"/obsws_python",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.hatch.envs.default]
|
||||||
|
dependencies = ["pre-commit"]
|
||||||
|
|
||||||
|
[tool.hatch.envs.e]
|
||||||
|
dependencies = ["keyboard"]
|
||||||
|
|
||||||
[tool.hatch.envs.e.scripts]
|
[tool.hatch.envs.e.scripts]
|
||||||
events = "python {root}\\examples\\events\\."
|
events = "python {root}\\examples\\events\\."
|
||||||
hotkeys = "python {root}\\examples\\hotkeys\\."
|
hotkeys = "python {root}\\examples\\hotkeys\\."
|
||||||
levels = "python {root}\\examples\\levels\\."
|
levels = "python {root}\\examples\\levels\\."
|
||||||
scene_rotate = "python {root}\\examples\\scene_rotate\\."
|
scene_rotate = "python {root}\\examples\\scene_rotate\\."
|
||||||
|
|
||||||
[tool.hatch.envs.test]
|
[tool.hatch.envs.hatch-test]
|
||||||
|
randomize = true
|
||||||
|
|
||||||
|
[tool.hatch.envs.hatch-test.scripts]
|
||||||
|
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
|
||||||
|
|
||||||
|
[[tool.hatch.envs.hatch-test.matrix]]
|
||||||
|
python = ["313", "312", "311", "310", "39"]
|
||||||
|
|
||||||
|
[tool.hatch.envs.style]
|
||||||
|
detached = true
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pytest",
|
"black",
|
||||||
|
"isort",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.hatch.envs.test.scripts]
|
[tool.hatch.envs.style.scripts]
|
||||||
run = 'pytest -v'
|
check = [
|
||||||
|
"black --check --diff .",
|
||||||
|
"isort --check-only --diff .",
|
||||||
|
]
|
||||||
|
fmt = [
|
||||||
|
"isort .",
|
||||||
|
"black .",
|
||||||
|
]
|
||||||
|
|
||||||
[[tool.hatch.envs.test.matrix]]
|
[tool.black]
|
||||||
python = ["39", "310", "311", "312"]
|
line-length = 88
|
||||||
|
include = '\.pyi?$'
|
||||||
|
# 'extend-exclude' excludes files or directories in addition to the defaults
|
||||||
|
extend-exclude = '''
|
||||||
|
(
|
||||||
|
^/\.git/ # exclude all files in the .git directory
|
||||||
|
^/\.hatch/ # exclude all files in the .hatch directory
|
||||||
|
^/\.pytest_cache/ # exclude all files in the .pytest_cache directory
|
||||||
|
| .*_pb2.py # exclude autogenerated Protocol Buffer files anywhere in the project
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
|
||||||
|
[tool.isort]
|
||||||
|
profile = "black"
|
||||||
|
skip = [".gitignore", ".dockerignore"]
|
||||||
|
skip_glob = [".git/*", ".hatch/*", ".pytest_cache/*"]
|
@ -18,7 +18,12 @@ class TestAttrs:
|
|||||||
|
|
||||||
def test_get_current_program_scene_attrs(self):
|
def test_get_current_program_scene_attrs(self):
|
||||||
resp = req_cl.get_current_program_scene()
|
resp = req_cl.get_current_program_scene()
|
||||||
assert resp.attrs() == ["current_program_scene_name"]
|
assert resp.attrs() == [
|
||||||
|
"current_program_scene_name",
|
||||||
|
"current_program_scene_uuid",
|
||||||
|
"scene_name",
|
||||||
|
"scene_uuid",
|
||||||
|
]
|
||||||
|
|
||||||
def test_get_transition_kind_list_attrs(self):
|
def test_get_transition_kind_list_attrs(self):
|
||||||
resp = req_cl.get_transition_kind_list()
|
resp = req_cl.get_transition_kind_list()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from obsws_python.callback import Callback
|
from obsws_python.callback import Callback
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class TestRequests:
|
|||||||
resp = req_cl.get_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name)
|
resp = req_cl.get_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name)
|
||||||
assert resp.slot_value == data
|
assert resp.slot_value == data
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="possible bug in obs-websocket, needs checking")
|
||||||
def test_profile_list(self):
|
def test_profile_list(self):
|
||||||
req_cl.create_profile("test")
|
req_cl.create_profile("test")
|
||||||
resp = req_cl.get_profile_list()
|
resp = req_cl.get_profile_list()
|
||||||
@ -97,11 +98,15 @@ class TestRequests:
|
|||||||
"START_TEST", "test", "color_source_v3", {"color": 4294945535}, True
|
"START_TEST", "test", "color_source_v3", {"color": 4294945535}, True
|
||||||
)
|
)
|
||||||
resp = req_cl.get_input_list()
|
resp = req_cl.get_input_list()
|
||||||
assert {
|
for input_item in resp.inputs:
|
||||||
"inputKind": "color_source_v3",
|
if input_item["inputName"] == "test":
|
||||||
"inputName": "test",
|
assert input_item["inputKind"] == "color_source_v3"
|
||||||
"unversionedInputKind": "color_source",
|
assert input_item["unversionedInputKind"] == "color_source"
|
||||||
} in resp.inputs
|
break
|
||||||
|
else:
|
||||||
|
# This else block is executed if the for loop completes without finding the input_item with inputName "test"
|
||||||
|
raise AssertionError("Input with inputName 'test' not found")
|
||||||
|
|
||||||
resp = req_cl.get_input_settings("test")
|
resp = req_cl.get_input_settings("test")
|
||||||
assert resp.input_kind == "color_source_v3"
|
assert resp.input_kind == "color_source_v3"
|
||||||
assert resp.input_settings == {"color": 4294945535}
|
assert resp.input_settings == {"color": 4294945535}
|
||||||
|
Loading…
Reference in New Issue
Block a user