Bot & Automation
jorgasisten
/root/hermes-projects/jorgasisten
tests/test_sheets_schema_detection.py
text
from jorgasisten.services.sheets import count_detected_data_rows, detect_sheet_table
def test_detect_sheet_table_skips_title_rows_and_finds_real_headers() -> None:
values = [
["📋 LOG PROGRES PENGEMBANGAN WEBSITE & APLIKASi"],
["Nama Website / Proyek : Johan Garage", "Periode : 2026"],
[],
["No", "Tanggal", "Kegiatan / Progres", "Bagian Website/Aplikasi", "Status", "Catatan"],
["1", "04/09/2026", "Testing Adjustment", "Inventory - Adjustment (ERP)", "Selesai", ""],
["2", "04/09/2026", "Testing render", "Inventory - Opname (ERP)", "Selesai", ""],
]
header_index, headers, sample_rows, context_lines = detect_sheet_table(values, sample_limit=5)
assert header_index == 3
assert headers == ["No", "Tanggal", "Kegiatan / Progres", "Bagian Website/Aplikasi", "Status", "Catatan"]
assert sample_rows[0]["No"] == "1"
assert sample_rows[0]["Bagian Website/Aplikasi"] == "Inventory - Adjustment (ERP)"
assert "Johan Garage" in context_lines[1]
def test_detect_sheet_table_falls_back_for_simple_single_header_row() -> None:
values = [
["Nama", "WA", "Status"],
["Budi", "0812", "Booking"],
]
header_index, headers, sample_rows, context_lines = detect_sheet_table(values, sample_limit=5)
assert header_index == 0
assert headers == ["Nama", "WA", "Status"]
assert sample_rows[0]["Nama"] == "Budi"
assert context_lines == []
def test_detect_sheet_table_uses_representative_samples_across_long_data() -> None:
values = [["No", "Produk", "Status"]]
for index in range(1, 11):
values.append([str(index), f"Produk {index}", "Aktif"])
_, headers, sample_rows, _ = detect_sheet_table(values, sample_limit=5)
assert headers == ["No", "Produk", "Status"]
assert len(sample_rows) == 5
assert sample_rows[0]["No"] == "1"
assert sample_rows[-1]["No"] == "10"
def test_count_detected_data_rows_counts_only_non_empty_rows_after_header() -> None:
values = [
["No", "Nama"],
["1", "Budi"],
[],
["2", "Andi"],
]
assert count_detected_data_rows(values, 0, ["No", "Nama"]) == 2