from pathlib import Path from app.config import AppConfig from app.pcf_parser import PcfParser, parse_blocks def test_sample_pcf_weld_count(): config = AppConfig.load() parser = PcfParser(config) files = list(Path("PCF文件样本(1)").glob("*.pcf")) records, candidates, messages = parser.parse_files(files) assert len(files) == 20 assert len(records) == 169 assert not messages assert records[0].line_no assert records[0].pipeline_reference assert records[0].weld_area in {"安装", "预制"} def test_parse_nonstandard_field_candidate(): text = """ PIPELINE-REFERENCE L-001 PIPING-SPEC C10C WELD COMPONENT-IDENTIFIER 1 LINE-NO 01ABC WELD-DIA 150 WELD-ATTRIBUTE3 Shop weld """.strip() blocks = parse_blocks(text) assert blocks[0].block_type == "PIPELINE-REFERENCE" assert blocks[1].block_type == "WELD" tmp = Path("tests/_tmp_nonstandard.pcf") tmp.write_text(text, encoding="utf-8") try: config = AppConfig.load() parser = PcfParser(config) _records, candidates, _messages = parser.parse_files([tmp]) fields = {c.source_field for c in candidates} assert "LINE-NO" in fields assert "WELD-DIA" in fields finally: tmp.unlink(missing_ok=True)