Skip to content
Merged
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/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Python

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
name: Python Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: astral-sh/setup-uv@v6
- name: Run tests
working-directory: PythonScripts
run: uv run pytest
10 changes: 5 additions & 5 deletions PythonScripts/audit_translations/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ def get_rules_dir(rules_dir: Optional[str] = None) -> Path:
return package_dir.parent.parent / "Rules" / "Languages"


def get_yaml_files(lang_dir: Path, region_dir: Optional[Path] = None) -> List[str]:
def get_yaml_files(lang_dir: Path, region_dir: Optional[Path] = None) -> List[Path]:
"""Get all YAML files to audit for a language, including region overrides."""
files: set[str] = set()
files: set[Path] = set()

def collect_from(directory: Path, root: Path) -> None:
if not directory.exists():
return
for f in directory.glob("*.yaml"):
if f.name != "prefs.yaml": # Skip prefs.yaml as it's not translated
files.add(str(f.relative_to(root)))
files.add(f.relative_to(root))
shared_dir = directory / "SharedRules"
if shared_dir.exists():
for f in shared_dir.glob("*.yaml"):
files.add(str(f.relative_to(root)))
files.add(f.relative_to(root))

collect_from(lang_dir, lang_dir)
if region_dir:
Expand Down Expand Up @@ -177,7 +177,7 @@ def print_diff_item(diff: RuleDifference, line_en: int, line_tr: int, verbose: b
def issue_base(rule: RuleInfo, file_name: str, language: str) -> dict:
return {
"language": language,
"file": file_name,
"file": Path(file_name).as_posix(),
"rule_name": rule.name or "",
"rule_tag": rule.tag or "",
"rule_key": rule.key,
Expand Down
21 changes: 18 additions & 3 deletions PythonScripts/audit_translations/tests/test_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

from pathlib import Path

import pytest

from ..auditor import collect_issues, compare_files, console, get_yaml_files, list_languages, print_warnings
from ..dataclasses import ComparisonResult, RuleDifference, RuleInfo


@pytest.fixture()
def fixed_console_width():
"""Pin Rich console to 80 columns so golden-file comparisons are portable."""
old = console.width
console.width = 80
yield
console.width = old


def make_rule(name: str, tag: str, line: int, raw: str) -> RuleInfo:
return RuleInfo(
name=name,
Expand Down Expand Up @@ -155,7 +166,7 @@ def test_get_yaml_files_includes_region(tmp_path) -> None:
(region_dir / "unicode.yaml").write_text("---", encoding="utf-8")

files = get_yaml_files(lang_dir, region_dir)
assert set(files) == {"base.yaml", "SharedRules/shared.yaml", "unicode.yaml"}
assert set(files) == {Path("base.yaml"), Path("SharedRules/shared.yaml"), Path("unicode.yaml")}


def test_list_languages_includes_region_codes(tmp_path) -> None:
Expand Down Expand Up @@ -183,9 +194,11 @@ def test_list_languages_includes_region_codes(tmp_path) -> None:
assert "zz-aa" in output


def test_print_warnings_omits_snippets_when_not_verbose() -> None:
def test_print_warnings_omits_snippets_when_not_verbose(fixed_console_width) -> None:
"""
Ensure the print_warnings output matches the non-verbose golden snapshot.

Uses pytest fixture for console width.
"""
base_dir = Path(__file__).parent
fixtures_dir = base_dir / "fixtures"
Expand All @@ -202,9 +215,11 @@ def test_print_warnings_omits_snippets_when_not_verbose() -> None:
assert output == golden_path.read_text(encoding="utf-8")


def test_print_warnings_includes_snippets_when_verbose() -> None:
def test_print_warnings_includes_snippets_when_verbose(fixed_console_width) -> None:
"""
Ensure the print_warnings output matches the verbose golden snapshot.

Uses pytest fixture for console width.
"""
base_dir = Path(__file__).parent
fixtures_dir = base_dir / "fixtures"
Expand Down