From 18e8ff164c43f27fc4a96fd6bdcd28f4001fd5d1 Mon Sep 17 00:00:00 2001 From: adamws Date: Thu, 5 Dec 2024 22:05:36 +0100 Subject: [PATCH] Add test for counting, key combinations and backspace --- examples/adamws-config/config | 2 ++ tests/src/test_rendering.py | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/examples/adamws-config/config b/examples/adamws-config/config index 27629a9..9c385f7 100644 --- a/examples/adamws-config/config +++ b/examples/adamws-config/config @@ -12,6 +12,7 @@ background_color = 0x000000ff ; black show_typing = true typing_font_size = 90 +backspace_mode = full typing_font_color = 0xffffffff ; white @@ -20,3 +21,4 @@ layout_path = ./my_pok3r_layout.json theme = vortex_pok3r key_tint_color = 0xa8a8a8ff + diff --git a/tests/src/test_rendering.py b/tests/src/test_rendering.py index 858ee32..cd2e8f8 100644 --- a/tests/src/test_rendering.py +++ b/tests/src/test_rendering.py @@ -160,11 +160,27 @@ def run_process_capture_logs(command, cwd, name="", process_holder=None) -> None process.wait() -def run_typing_process(text: str) -> None: +def run_typing_process(text: str | list[str]) -> None: if sys.platform == "win32": - ahk.send(text, key_delay=200, key_press_duration=50, send_mode="Event"); + if isinstance(text, str): + ahk.send(text, key_delay=200, key_press_duration=50, send_mode="Event") + else: + text_escaped = "" + for item in text: + if item == "BackSpace": + text_escaped += "{Backspace}" + elif item == "ctrl+alt+b": + text_escaped += "^!b" + elif item == "ctrl+b": + text_escaped += "^b" + else: + text_escaped += item + ahk.send_input(text_escaped) else: - result = subprocess.run(["xdotool", "type", "--delay", "200", text]) + if isinstance(text, str): + result = subprocess.run(["xdotool", "type", "--delay", "200", text]) + else: + result = subprocess.run(["xdotool", "key", "--delay", "200"] + text) assert result.returncode == 0 @@ -172,6 +188,8 @@ def __get_parameters(): texts = [ "The quick brown fox jumps over the lazy dog", "Dość błazeństw, żrą mój pęk luźnych fig", + # for testing key combinations, counting repetitions and backspace + 11 * ["a"] + ["b", "BackSpace"] + 4 * ["b"] + 4 * ["ctrl+alt+b"] + 4 * ["ctrl+b"] + 23 * ["BackSpace"] ] examples = [ "", # default @@ -187,6 +205,7 @@ def __get_parameters(): test_params.append(pytest.param(texts[0], examples[0])) test_params.append(pytest.param(texts[1], examples[0])) test_params.append(pytest.param(texts[0], examples[1])) + test_params.append(pytest.param(texts[2], examples[1])) test_params.append(pytest.param(texts[0], examples[2])) test_params.append(pytest.param(texts[0], examples[3])) test_params.append(pytest.param(texts[1], examples[4])) @@ -198,7 +217,7 @@ def __get_parameters(): @pytest.mark.parametrize( "text,example", __get_parameters() ) -def test_record_and_render(app_isolation, text: str, example) -> None: +def test_record_and_render(app_isolation, text: str | list[str], example) -> None: with app_isolation(example) as app: app_dir = Path(app).parent processes = {}