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
4 changes: 2 additions & 2 deletions PythonScripts/audit_translations/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def merge_rules(base_rules: list[RuleInfo], region_rules: list[RuleInfo]) -> lis
shared_keys = source_keys & target_keys
source_order = [rule for rule in english_rules if rule.key in shared_keys and not rule.audit_ignore]
target_order = [rule for rule in translated_rules if rule.key in shared_keys and not rule.audit_ignore]
for position, (source_rule, target_rule) in enumerate(zip(source_order, target_order), start=1):
for position, (source_rule, target_rule) in enumerate(zip(source_order, target_order, strict=True), start=1):
if source_rule.key != target_rule.key:
first_order_mismatch_position = position
break
Expand Down Expand Up @@ -277,7 +277,7 @@ def audit_language(
total_definition_type_mismatches = 0
files_with_issues = 0
files_ok = 0
order_findings: list[tuple[str, int]] = [] # One item per file, eg [("calculus.yaml", 2), ...]
order_findings: list[tuple[str, int]] = [] # One item per file, eg [("calculus.yaml", 2), ...]

for file_name in files:
english_path = source_dir / file_name
Expand Down
3 changes: 1 addition & 2 deletions PythonScripts/audit_translations/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ def print_order_findings(findings: list[tuple[str, int]]) -> None:
"""Print the first shared-rule order difference for each affected file."""
for file_name, position in findings:
console.print(
f"[yellow]Rule order differs[/] in {escape(str(file_name))}: "
f"first difference at shared rule position {position}"
f"[yellow]Rule order differs[/] in {escape(str(file_name))}: first difference at shared rule position {position}"
)


Expand Down
70 changes: 50 additions & 20 deletions PythonScripts/audit_translations/tests/test_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,26 @@ def test_rule_order_reports_first_shared_difference(tmp_path) -> None:
"""A swapped pair records the first shared rule position without adding an issue."""
source = tmp_path / "source.yaml"
target = tmp_path / "target.yaml"
source.write_text("""- name: a
source.write_text(
"""- name: a
tag: mi
- name: b
tag: mi
- name: c
tag: mi
""", encoding="utf-8")
target.write_text("""- name: a
""",
encoding="utf-8",
)
target.write_text(
"""- name: a
tag: mi
- name: c
tag: mi
- name: b
tag: mi
""", encoding="utf-8")
""",
encoding="utf-8",
)

result = compare_files(source, target)
assert result.first_order_mismatch_position == 2
Expand All @@ -74,53 +80,71 @@ def test_missing_and_ignored_rules_do_not_shift_order(tmp_path) -> None:
"""Only shared rules without audit-ignore markers participate in ordering."""
source = tmp_path / "source.yaml"
target = tmp_path / "target.yaml"
source.write_text("""- name: a
source.write_text(
"""- name: a
tag: mi
- name: missing
tag: mi
- name: b
tag: mi
""", encoding="utf-8")
target.write_text("""- name: a
""",
encoding="utf-8",
)
target.write_text(
"""- name: a
tag: mi
- name: extra
tag: mi
- name: b
tag: mi
""", encoding="utf-8")
""",
encoding="utf-8",
)
assert compare_files(source, target).first_order_mismatch_position is None

source.write_text("""- name: a
source.write_text(
"""- name: a
tag: mi
- name: b
tag: mi
# audit-ignore
- name: c
tag: mi
""", encoding="utf-8")
target.write_text("""# audit-ignore
""",
encoding="utf-8",
)
target.write_text(
"""# audit-ignore
- name: c
tag: mi
- name: a
tag: mi
- name: b
tag: mi
""", encoding="utf-8")
""",
encoding="utf-8",
)
assert compare_files(source, target).first_order_mismatch_position is None


def test_include_placement_is_not_checked(tmp_path) -> None:
"""An include moving around a named rule has no effect on named rule order."""
source = tmp_path / "source.yaml"
target = tmp_path / "target.yaml"
source.write_text("""- include: shared.yaml
source.write_text(
"""- include: shared.yaml
- name: a
tag: mi
""", encoding="utf-8")
target.write_text("""- name: a
""",
encoding="utf-8",
)
target.write_text(
"""- name: a
tag: mi
- include: shared.yaml
""", encoding="utf-8")
""",
encoding="utf-8",
)
result = compare_files(source, target)
assert result.first_order_mismatch_position is None
assert result.english_rule_count == result.translated_rule_count == 1
Expand All @@ -133,12 +157,18 @@ def test_unicode_entries_are_not_checked_for_order(tmp_path) -> None:
source = tmp_path / "unicode.yaml"
target = tmp_path / "target" / "unicode.yaml"
target.parent.mkdir()
source.write_text("""- "←": [t: left]
source.write_text(
"""- "←": [t: left]
- "∥": [t: parallel]
""", encoding="utf-8")
target.write_text("""- "∥": [T: parallel]
""",
encoding="utf-8",
)
target.write_text(
"""- "∥": [T: parallel]
- "←": [T: left]
""", encoding="utf-8")
""",
encoding="utf-8",
)

assert compare_files(source, target).first_order_mismatch_position is None

Expand Down
Loading