"""253-1 거리이정표 행 1:1 → B09 운반공 줄 — 자동 상자 = 옛 키 · 사용자 상자 = `haul:r-{id}`.""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from B08_Quantity.B08_Quantity_Haul import haul_rows, route_bill_key # noqa: E402 from B08_Quantity.B08_Quantity_Milestone_Calc import compute_milestone # noqa: E402 from B09_Estimation.B09_Estimation_Bill_Items import haul_items # noqa: E402 from B09_Estimation.B09_Estimation_Router import haul_user # noqa: E402 LOGIC = {"tab": "logic", "code": "GF000134", "name": "골재운반", "given": {}} DATA = { "site": {"mid_station_m": 2000, "mid_road": "비포장"}, "base": {"enabled": False, "legs": []}, "routes": [ {"id": "h-sand", "name": "골재상", "haul": "sand", "via_base": False, "legs": [{"road": "포장", "km": 25.1}], "rows": [{"item": "모래", "dest": "start"}]}, {"id": "u1", "name": "석산", "ref": LOGIC, "via_base": False, "legs": [{"road": "포장", "km": 10}, {"road": "비포장", "km": 0.8}], "rows": [{"item": "혼합골재", "dest": "start"}, {"item": "깬돌", "dest": "mid"}]}, ], } # fmt: skip def test_keys(): assert route_bill_key({"id": "h-sand", "haul": "sand"}) == "haul:3" assert route_bill_key({"id": "h-x", "haul": "remicon"}) == "haul:remicon" assert route_bill_key({"id": "u1"}) == "haul:r-u1" assert route_bill_key({"id": "u1"}, 1) == "haul:r-u1.1" def test_rows_one_per_table_row(): rows = haul_rows(DATA, compute_milestone(DATA, None)) got = {r["key"]: r for r in rows} assert list(got) == ["haul:3", "haul:r-u1", "haul:r-u1.1"] assert (got["haul:3"]["L1"], got["haul:3"]["L2"], got["haul:3"]["user"]) == (25.1, 0, False) assert (got["haul:r-u1"]["name"], got["haul:r-u1"]["L1"], got["haul:r-u1"]["L2"]) == ( "혼합골재", 10, 0.8) # fmt: skip 261-4 항목명 그대로 assert got["haul:r-u1.1"]["L2"] == 2.8 # 중점 = 시점 → 중점 2 km 비포장 더함 assert got["haul:r-u1"]["ref"] == LOGIC def test_bill_items_user_rows(): rows = haul_rows(DATA, compute_milestone(DATA, None)) extra = haul_user(rows) items = {i["key"]: i for i in haul_items(None, extra["haul_refs"], rows)} assert ( "haul:3" in items and items["haul:3"]["name"] == "모래" ) # 자동 = 상자 항목명(261-4) user = items["haul:r-u1"] assert (user["section"], user["name"], user["qty"], user["ref"]) == ( "3", "혼합골재", None, LOGIC, ) assert items["haul:r-u1.1"]["name"] == "깬돌" and items["haul:r-u1.1"]["ref"] == LOGIC assert extra["haul_dist"]["haul:r-u1"] == {"L1": 10, "L2": 0.8}