rosetta-sql 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ """Plain-text report generator for Rosetta."""
2
+
3
+ import logging
4
+ import time
5
+ from typing import Dict
6
+
7
+ from ..models import CompareResult
8
+
9
+ log = logging.getLogger("rosetta")
10
+
11
+
12
+ def write_text_report(path: str, test_file: str,
13
+ comparisons: Dict[str, CompareResult]) -> bool:
14
+ """Write a plain-text comparison report.
15
+
16
+ Returns True if all comparisons passed.
17
+ """
18
+ all_pass = True
19
+
20
+ with open(path, "w", encoding="utf-8") as f:
21
+ f.write("=" * 70 + "\n")
22
+ f.write("Rosetta Cross-DBMS Test Comparison Report\n")
23
+ f.write(f"Test file: {test_file}\n")
24
+ f.write(f"Time: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
25
+ f.write("=" * 70 + "\n\n")
26
+
27
+ f.write("SUMMARY\n")
28
+ f.write("-" * 70 + "\n")
29
+ f.write(f"{'Comparison':<35} {'Match':>6} {'Mismatch':>9} "
30
+ f"{'Skip':>6} {'Total':>6} {'Pass%':>7}\n")
31
+ f.write("-" * 70 + "\n")
32
+
33
+ for key, cmp in comparisons.items():
34
+ f.write(f"{key:<35} {cmp.matched:>6} "
35
+ f"{cmp.mismatched:>9} {cmp.skipped:>6} "
36
+ f"{cmp.total_stmts:>6} "
37
+ f"{cmp.pass_rate:>6.1f}%\n")
38
+ if cmp.mismatched > 0:
39
+ all_pass = False
40
+
41
+ f.write("-" * 70 + "\n")
42
+ if all_pass:
43
+ f.write("RESULT: ALL PASSED\n\n")
44
+ else:
45
+ f.write("RESULT: DIFFERENCES FOUND\n\n")
46
+
47
+ for key, cmp in comparisons.items():
48
+ if not cmp.diffs:
49
+ continue
50
+ f.write("=" * 70 + "\n")
51
+ f.write(f"DIFFS: {key}\n")
52
+ f.write("=" * 70 + "\n")
53
+ for d in cmp.diffs:
54
+ f.write(f"\n--- Block {d['block']}: "
55
+ f"{d['stmt'][:80]}\n")
56
+ # Show surrounding context for quick orientation
57
+ ctx_before = d.get("context_before", [])
58
+ ctx_after = d.get("context_after", [])
59
+ if ctx_before or ctx_after:
60
+ f.write(" Context:\n")
61
+ for c in ctx_before:
62
+ f.write(f" Block {c['block']:>4}: "
63
+ f"{c['stmt'][:70]}\n")
64
+ f.write(f" ▶ Block {d['block']:>4}: "
65
+ f"{d['stmt'][:70]}\n")
66
+ for c in ctx_after:
67
+ f.write(f" Block {c['block']:>4}: "
68
+ f"{c['stmt'][:70]}\n")
69
+ for dl in d["diff"]:
70
+ f.write(dl + "\n")
71
+ f.write("\n")
72
+
73
+ log.info("Text report written: %s", path)
74
+ return all_pass
75
+
76
+
77
+ def write_diff_file(path: str,
78
+ comparisons: Dict[str, CompareResult]):
79
+ """Write a unified diff file."""
80
+ diff_lines = []
81
+ for key, cmp in comparisons.items():
82
+ if not cmp.diffs:
83
+ continue
84
+ diff_lines.append("=" * 70)
85
+ diff_lines.append(f"DIFFS: {key}")
86
+ diff_lines.append("=" * 70)
87
+ for d in cmp.diffs:
88
+ diff_lines.append(
89
+ f"\n--- Block {d['block']}: {d['stmt'][:100]}"
90
+ )
91
+ ctx_before = d.get("context_before", [])
92
+ ctx_after = d.get("context_after", [])
93
+ if ctx_before or ctx_after:
94
+ diff_lines.append(" Context:")
95
+ for c in ctx_before:
96
+ diff_lines.append(
97
+ f" Block {c['block']:>4}: {c['stmt'][:80]}")
98
+ diff_lines.append(
99
+ f" ▶ Block {d['block']:>4}: {d['stmt'][:80]}")
100
+ for c in ctx_after:
101
+ diff_lines.append(
102
+ f" Block {c['block']:>4}: {c['stmt'][:80]}")
103
+ for dl in d["diff"]:
104
+ diff_lines.append(dl)
105
+ diff_lines.append("")
106
+
107
+ if diff_lines:
108
+ with open(path, "w", encoding="utf-8") as f:
109
+ f.write("\n".join(diff_lines) + "\n")
110
+ log.info("Diff file written: %s", path)