From 9d4248f5f652879dd439f6e561c221d36f5dc793 Mon Sep 17 00:00:00 2001 From: elParaguayo Date: Fri, 15 Nov 2024 17:44:14 +0000 Subject: [PATCH] Add test --- test/test_command.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_command.py b/test/test_command.py index fc6da38428..0c74074a4b 100644 --- a/test/test_command.py +++ b/test/test_command.py @@ -21,6 +21,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import asyncio + import pytest import libqtile.bar @@ -36,6 +38,7 @@ from libqtile.ipc import Client, IPCError from libqtile.lazy import lazy from test.conftest import dualmonitor +from test.helpers import Retry class CallConfig(Config): @@ -458,6 +461,28 @@ def test_func(qtile, value, multiplier=1): assert val == "500" +def test_lazy_function_coroutine(manager_nospawn): + """Test that lazy.function accepts coroutines.""" + + @Retry(ignore_exceptions=(AssertionError,)) + def assert_func_text(manager, value): + _, text = manager.c.eval("self.test_func_output") + assert text == value + + @lazy.function + async def test_async_func(qtile, value): + await asyncio.sleep(0.1) + qtile.test_func_output = value + + config = ServerConfig + config.keys = [libqtile.config.Key(["control"], "k", test_async_func("qtile"))] + + manager_nospawn.start(config) + + manager_nospawn.c.simulate_keypress(["control"], "k") + assert_func_text(manager_nospawn, "qtile") + + def test_decorators_direct_call(): widget = DecoratedTextBox() undecorated = libqtile.widget.TextBox()