diff --git a/PythonScripts/audit_translations/auditor.py b/PythonScripts/audit_translations/auditor.py index 6cf718ea1..5df06b6fe 100644 --- a/PythonScripts/audit_translations/auditor.py +++ b/PythonScripts/audit_translations/auditor.py @@ -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 @@ -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 diff --git a/PythonScripts/audit_translations/renderer.py b/PythonScripts/audit_translations/renderer.py index 1ba2db693..198aefc54 100644 --- a/PythonScripts/audit_translations/renderer.py +++ b/PythonScripts/audit_translations/renderer.py @@ -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}" ) diff --git a/PythonScripts/audit_translations/tests/test_auditor.py b/PythonScripts/audit_translations/tests/test_auditor.py index ff7f32a0f..e8e7ec266 100644 --- a/PythonScripts/audit_translations/tests/test_auditor.py +++ b/PythonScripts/audit_translations/tests/test_auditor.py @@ -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 @@ -74,38 +80,50 @@ 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 @@ -113,14 +131,20 @@ 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 @@ -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