Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""Stage 1 검증 (계획서 §3) — 샘플 원본이 data/raw 에 있을 때만 실행."""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from ingest.normalize import clean_text_field, normalize_raw_text, parse_collected_file
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
RAW = ROOT / "data" / "raw"
|
|
|
|
|
|
def test_normalize_regex_removes_wrap_artifact():
|
|
raw = '{"A":"REPORT\n zfir10070 MESSAGE-ID zfim01."}'
|
|
assert json.loads(normalize_raw_text(raw))["A"] == "REPORT zfir10070 MESSAGE-ID zfim01."
|
|
|
|
|
|
def test_escaped_newline_preserved():
|
|
# 이스케이프된 \n(백슬래시+n)은 json.loads 후 진짜 줄바꿈이 되어야 한다
|
|
raw = '{"A":"LINE1\\nLINE2"}'
|
|
assert json.loads(normalize_raw_text(raw))["A"] == "LINE1\nLINE2"
|
|
|
|
|
|
def test_clean_text_field():
|
|
assert clean_text_field("총계정원장 조회") == "총계정원장 조회"
|
|
|
|
|
|
@pytest.mark.skipif(not (RAW / "ZFIR10070.txt").exists(), reason="샘플 원본 없음")
|
|
def test_sample_program_source():
|
|
data = parse_collected_file((RAW / "ZFIR10070.txt").read_text(encoding="utf-8"))
|
|
assert clean_text_field(data["DESCRIPTION"]) == "총계정원장 조회"
|
|
f01 = next(i for i in data["INCLUDE_PROGRAM"] if "F01" in i["INCLUDE"])
|
|
form_lines = [
|
|
ln for ln in f01["SOURCE_CODE"].split("\n") if ln.strip().upper().startswith("FORM ")
|
|
]
|
|
assert len(form_lines) == 73
|
|
|
|
|
|
@pytest.mark.skipif(not (RAW / "ZFI01.txt").exists(), reason="샘플 원본 없음")
|
|
def test_sample_package_list():
|
|
data = parse_collected_file((RAW / "ZFI01.txt").read_text(encoding="utf-8"))
|
|
assert isinstance(data, list) and len(data) > 900
|
|
assert data[0]["DEVCLASS"] == "ZFI01"
|