v3: gstack-code-gen 生成

This commit is contained in:
hangshuo652
2026-05-24 12:36:44 +08:00
commit 818e81269c
50 changed files with 1343 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from comparator.aligner import align_records
def test_align_by_key():
c = [{"CUST-ID": "C001", "AMT": 100}, {"CUST-ID": "C002", "AMT": 200}]
s = [{"CUST-ID": "C002", "AMT": 200}, {"CUST-ID": "C001", "AMT": 100}]
result = align_records(c, s, key_field="CUST-ID")
assert len(result) == 2
assert all(st == "MATCHED" for _, _, st in result)
def test_missing_in_spark():
c = [{"CUST-ID": "C001"}, {"CUST-ID": "C002"}]
s = [{"CUST-ID": "C001"}]
result = align_records(c, s, key_field="CUST-ID")
assert "MISSING_IN_SPARK" in [st for _, _, st in result]
def test_extra_in_spark():
c = [{"CUST-ID": "C001"}]
s = [{"CUST-ID": "C001"}, {"CUST-ID": "C002"}]
result = align_records(c, s, key_field="CUST-ID")
assert "EXTRA_IN_SPARK" in [st for _, _, st in result]
def test_empty_inputs():
assert align_records([], [], "key") == []
def test_duplicate_keys():
c = [{"ID": "K1", "V": 1}, {"ID": "K1", "V": 2}]
s = [{"ID": "K1", "V": 1}, {"ID": "K1", "V": 2}]
assert len(align_records(c, s, key_field="ID")) == 2
def test_none_key():
assert len(align_records([{"ID": None, "V": 1}], [{"ID": None, "V": 1}], "ID")) == 1
+31
View File
@@ -0,0 +1,31 @@
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from comparator.field_compare import compare_field, DEFAULT_TOLERANCE
def test_exact_match():
assert compare_field("F1", "1500000", "1500000", "decimal").status == "PASS"
def test_within_tolerance():
assert compare_field("F1", "1500000", "1499999.99", "decimal", DEFAULT_TOLERANCE).status == "TOLERATED"
def test_beyond_tolerance():
assert compare_field("F1", "1500000", "1000000", "decimal", DEFAULT_TOLERANCE).status == "MISMATCH"
def test_string_trim():
assert compare_field("F1", "A ", "A", "string").status == "PASS"
def test_date_normalization():
assert compare_field("F1", "20260522", "2026-05-22", "date").status == "PASS"
def test_default_zero():
assert compare_field("F1", "\x00\x00\x00\x00\x00", "0", "decimal").status in ("PASS", "TOLERATED")
def test_java_null():
assert compare_field("F1", "1500000", "None", "decimal").status in ("MISMATCH", "NOT_SET")
+30
View File
@@ -0,0 +1,30 @@
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from comparator.normalizer import Normalizer
def test_ebcdic():
n = Normalizer()
assert n.normalize_encoding(b'\xc1\xc2', "EBCDIC") == "AB"
def test_ascii_passthrough():
assert Normalizer().normalize_encoding(b"hello", "ASCII") == "hello"
def test_comp3():
assert Normalizer().normalize_comp3(b'\x00\x15\x0C') == "150"
def test_comp3_negative():
assert Normalizer().normalize_comp3(b'\x15\x0D') == "-150"
def test_date_iso():
assert Normalizer().normalize_date("20260522") == "2026-05-22"
def test_ir_record():
n = Normalizer()
ir = n.to_ir_record("BR-AMT", "15000C", "1500", "EBCDIC", "COMP3", 5, 2, True)
assert ir.field_name == "BR-AMT"
assert ir.cobol.decoded_value == "1500"
+19
View File
@@ -0,0 +1,19 @@
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from comparator.rounding_detect import detect_rounding
def test_truncation():
r = detect_rounding("1500000", "1499999")
assert r.mode in ("TRUNCATE", "HALF_UP")
def test_exact():
r = detect_rounding("1500000", "1500000")
assert r.mode == "EXACT"
assert r.confidence == 1.0
def test_small_diff():
r = detect_rounding("1500", "1498")
assert r.confidence < 1.0