Skip to content

Commit

Permalink
Add test for counting, key combinations and backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
adamws committed Dec 5, 2024
1 parent cede78c commit 15e6793
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- uses: actions/download-artifact@v4
with:
name: klawa-${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions examples/adamws-config/config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ background_color = 0x000000ff ; black

show_typing = true
typing_font_size = 90
backspace_mode = full

typing_font_color = 0xffffffff ; white

Expand All @@ -20,3 +21,4 @@ layout_path = ./my_pok3r_layout.json
theme = vortex_pok3r

key_tint_color = 0xa8a8a8ff

27 changes: 23 additions & 4 deletions tests/src/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,36 @@ 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


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
Expand All @@ -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]))
Expand All @@ -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 = {}
Expand Down

0 comments on commit 15e6793

Please sign in to comment.