diff options
Diffstat (limited to 'packages/meshbay-cli/tests/test_clipboard.py')
| -rw-r--r-- | packages/meshbay-cli/tests/test_clipboard.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/packages/meshbay-cli/tests/test_clipboard.py b/packages/meshbay-cli/tests/test_clipboard.py index 6296317..20e90b6 100644 --- a/packages/meshbay-cli/tests/test_clipboard.py +++ b/packages/meshbay-cli/tests/test_clipboard.py @@ -10,7 +10,7 @@ import time import pytest from meshbay_cli.tui import clipboard -pytestmark = pytest.mark.skipif(sys.platform in ("win32", "darwin"), +unix_tools = pytest.mark.skipif(sys.platform in ("win32", "darwin"), reason="the Wayland and X11 tools") # Found before a test leaves only the fake tools on PATH. CAT, SLEEP = shutil.which("cat"), shutil.which("sleep") @@ -31,12 +31,14 @@ def wayland(tmp_path, monkeypatch): return held +@unix_tools async def test_what_is_copied_is_what_is_pasted(wayland): assert await clipboard.write_text("héllo — 你好\nsecond") is True assert wayland.read_text(encoding="utf-8") == "héllo — 你好\nsecond" assert await clipboard.read_text() == "héllo — 你好\nsecond" +@unix_tools async def test_no_tool_is_none_not_an_error(tmp_path, monkeypatch): monkeypatch.setenv("PATH", str(tmp_path)) monkeypatch.setenv("WAYLAND_DISPLAY", "wayland-0") @@ -45,14 +47,33 @@ async def test_no_tool_is_none_not_an_error(tmp_path, monkeypatch): assert await clipboard.write_text("x") is False +@unix_tools async def test_a_failing_tool_is_skipped(wayland): (wayland.parent / "bin" / "wl-paste").write_text("#!/bin/sh\nexit 1\n") assert await clipboard.read_text() is None +@unix_tools async def test_a_hanging_tool_is_given_up(wayland, monkeypatch): (wayland.parent / "bin" / "wl-paste").write_text(f"#!/bin/sh\nexec {SLEEP} 30\n") monkeypatch.setattr(clipboard, "TIMEOUT", 0.3) started = time.monotonic() assert await clipboard.read_text() is None assert 0.3 <= time.monotonic() - started < 5 + + +def test_the_tools_run_on_a_selector_loop(monkeypatch): + """The client's loop on Windows (`__main__.loop_factory`), which cannot start + a process through asyncio: right-click copy and paste raised there.""" + import asyncio + + def tools(read): + return [[sys.executable, "-c", "print('pasted', end='')" if read + else "import sys; sys.stdin.buffer.read()"]] + monkeypatch.setattr(clipboard, "_tools", tools) + loop = asyncio.SelectorEventLoop() + try: + assert loop.run_until_complete(clipboard.read_text()) == "pasted" + assert loop.run_until_complete(clipboard.write_text("x")) is True + finally: + loop.close() |