obsws-python/tests/test_callback.py
onyx-and-iris f5c2293dce add callback unit tests.
callback deregister now accepts iterable.
2022-07-27 20:49:45 +01:00

60 lines
1.6 KiB
Python

import pytest
from obsstudio_sdk.callback import Callback
class TestCallbacks:
__test__ = True
@classmethod
def setup_class(cls):
cls.callback = Callback()
@pytest.fixture(autouse=True)
def wraps_tests(self):
yield
self.callback.clear()
def test_register_callback(self):
def on_callback_method():
pass
self.callback.register(on_callback_method)
assert self.callback.get() == ["CallbackMethod"]
def test_register_callbacks(self):
def on_callback_method_one():
pass
def on_callback_method_two():
pass
self.callback.register((on_callback_method_one, on_callback_method_two))
assert self.callback.get() == ["CallbackMethodOne", "CallbackMethodTwo"]
def test_deregister_callback(self):
def on_callback_method_one():
pass
def on_callback_method_two():
pass
self.callback.register((on_callback_method_one, on_callback_method_two))
self.callback.deregister(on_callback_method_one)
assert self.callback.get() == ["CallbackMethodTwo"]
def test_deregister_callbacks(self):
def on_callback_method_one():
pass
def on_callback_method_two():
pass
def on_callback_method_three():
pass
self.callback.register(
(on_callback_method_one, on_callback_method_two, on_callback_method_three)
)
self.callback.deregister((on_callback_method_two, on_callback_method_three))
assert self.callback.get() == ["CallbackMethodOne"]