Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: pytest
on:
pull_request:
workflow_dispatch:

permissions:
contents: read
pull-requests: write
jobs:
pytest:
runs-on: ubuntu-latest
Expand All @@ -10,3 +14,17 @@ jobs:
- uses: ./.github/actions/setup-python
- run: |
uv run pytest

- name: Run tests (with coverage)
run: |
uv run pytest \
--junitxml=pytest.xml \
--cov-report=term-missing:skip-covered \
--cov=. \
| tee pytest-coverage.txt

- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
71 changes: 36 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,58 @@ requires-python = ">=3.9"
dependencies = ["jinja2>=3.1.6", "python-dotenv>=1.1.1", "ruamel-yaml>=0.18.14"]

[dependency-groups]
dev = ["bandit>=1.8.6", "ruff>=0.14.0", "ty>=0.0.1a22", "vulture>=2.14", "pytest>=8.4.2"]


dev = [
"bandit>=1.8.6",
"pytest>=8.4.2",
"pytest-cov>=7.0.0",
"ruff>=0.14.0",
"ty>=0.0.1a22",
"vulture>=2.14",
]

[tool.ruff]
indent-width = 4
line-length = 120


[tool.ruff.lint]
# select = ["ALL"]
ignore = [
"ANN", # flake8-annotations
"COM", # flake8-commas
"C90", # mccabe complexity
"DJ", # django
"EXE", # flake8-executable
"BLE", # blind except
"PTH", # flake8-pathlib
"T10", # debugger
"TID", # flake8-tidy-imports
"D100",
"D103",
"D104",
"D105",
"D106",
"D107",
"D101",
"D107", # missing docstring in public module
"D102", # missing docstring in public class
"D104", # missing docstring in public package
"D213",
"D203",
"D400",
"D415",
"G004",
"PLR2004",
"E501", # line too long
"TRY",
"SIM105", # faster without contextlib
"ANN", # flake8-annotations
"COM", # flake8-commas
"C90", # mccabe complexity
"DJ", # django
"EXE", # flake8-executable
"BLE", # blind except
"PTH", # flake8-pathlib
"T10", # debugger
"TID", # flake8-tidy-imports
"D100",
"D103",
"D104",
"D105",
"D106",
"D107",
"D101",
"D107", # missing docstring in public module
"D102", # missing docstring in public class
"D104", # missing docstring in public package
"D213",
"D203",
"D400",
"D415",
"G004",
"PLR2004",
"E501", # line too long
"TRY",
"SIM105", # faster without contextlib
]

fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
line-ending = "auto"

docstring-code-format = false
39 changes: 36 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
"""Pytest configuration and fixtures."""

import sys
from pathlib import Path

# Add src directory to Python path
import pytest

sys.path.insert(0, str(Path(__file__).parent.parent / "src"))


@pytest.fixture
def fixtures_dir():
return Path(__file__).parent / "fixtures"


@pytest.fixture
def valid_fixtures(fixtures_dir):
return fixtures_dir / "valid"


@pytest.fixture
def invalid_fixtures(fixtures_dir):
return fixtures_dir / "invalid"


@pytest.fixture
def valid_yaml_data():
return {
"title": "Test Cheatsheet",
"layout": {"keyboard": "US", "system": "Darwin"},
"shortcuts": {"General": {"CMD+C": {"description": "Copy"}}},
}


@pytest.fixture
def sample_system_mappings():
return {"cmd": "⌘", "ctrl": "⌃", "alt": "⌥", "shift": "⇧"}


@pytest.fixture
def sample_keyboard_layouts():
return {"US": {"layout": [["Esc", "F1", "F2"], ["`", "1", "2", "3"], ["Tab", "Q", "W", "E"]]}}
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/bad_indentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Bad Indentation"
shortcuts:
General:
"Ctrl+C":
description: "Odd indentation on line 3"
Empty file.
8 changes: 8 additions & 0 deletions tests/fixtures/invalid/invalid_keyboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: "Invalid Keyboard"
layout:
keyboard: INVALID
system: Darwin
shortcuts:
General:
"Ctrl+C":
description: "Copy"
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/invalid_shortcut_format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Invalid Shortcut Format"
shortcuts:
General:
"Ctrl+@#$%^&*()":
description: "Invalid characters"
8 changes: 8 additions & 0 deletions tests/fixtures/invalid/invalid_system.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: "Invalid System"
layout:
keyboard: US
system: INVALID
shortcuts:
General:
"Ctrl+C":
description: "Copy"
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/long_lines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Long Lines Test"
shortcuts:
General:
"Ctrl+C":
description: "This is a very long description that exceeds the 100 character limit for a single line in YAML files according to lint rules"
6 changes: 6 additions & 0 deletions tests/fixtures/invalid/malformed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: "Malformed
shortcuts:
- unclosed quote
General:
invalid yaml structure here
nested: wrong
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/missing_description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Missing Description"
shortcuts:
General:
"Ctrl+C":
other_key: "value"
3 changes: 3 additions & 0 deletions tests/fixtures/invalid/missing_shortcuts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: "Missing Shortcuts"
layout:
keyboard: US
4 changes: 4 additions & 0 deletions tests/fixtures/invalid/missing_title.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shortcuts:
General:
"Ctrl+C":
description: "Copy"
3 changes: 3 additions & 0 deletions tests/fixtures/invalid/non_dict_category.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: "Non Dict Category"
shortcuts:
General: "not a dict"
4 changes: 4 additions & 0 deletions tests/fixtures/invalid/non_dict_shortcuts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title: "Non Dict Shortcuts"
shortcuts:
- "item1"
- "item2"
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/trailing_whitespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Trailing Whitespace"
shortcuts:
General:
"Ctrl+C":
description: "Copy"
12 changes: 12 additions & 0 deletions tests/fixtures/valid/allowtext_mode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: "AllowText Mode Test"
RenderKeys: false
AllowText: true
layout:
keyboard: US
system: Darwin
shortcuts:
Commands:
"kubectl get pods":
description: "List all pods"
"docker ps -a":
description: "List all containers"
17 changes: 17 additions & 0 deletions tests/fixtures/valid/full_featured.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: "Full Featured Test"
RenderKeys: true
AllowText: false
layout:
keyboard: US
system: Darwin
shortcuts:
General:
"CMD+C":
description: "Copy selected item"
"CMD+V":
description: "Paste"
Navigation:
"CMD+Up":
description: "Go to top"
"Ctrl+Shift+A":
description: "Select all"
5 changes: 5 additions & 0 deletions tests/fixtures/valid/minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: "Minimal Test"
shortcuts:
General:
"Ctrl+C":
description: "Copy"
Loading