84 lines
3.8 KiB
Python
84 lines
3.8 KiB
Python
"""
|
||
海运运输分类:只认 Port to Port、其他。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
import unittest
|
||
|
||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||
if ROOT not in sys.path:
|
||
sys.path.insert(0, ROOT)
|
||
|
||
from agent.schema.sea_options import (
|
||
canonicalize_sea_class,
|
||
drop_invented_door_trade_terms,
|
||
harvest_sea_class,
|
||
sea_class_prompt,
|
||
)
|
||
|
||
|
||
class SeaOptionsTest(unittest.TestCase):
|
||
def test_port_to_port_aliases(self):
|
||
self.assertEqual(canonicalize_sea_class("Port to Port"), "Port to Port")
|
||
self.assertEqual(canonicalize_sea_class("port to port"), "Port to Port")
|
||
self.assertEqual(canonicalize_sea_class("P2P"), "Port to Port")
|
||
self.assertEqual(canonicalize_sea_class("港到港"), "Port to Port")
|
||
glued = "15件,Port\u00a0to\u00a0Port\n贸易条款:DOOR-DOOR"
|
||
self.assertEqual(canonicalize_sea_class(glued), "Port to Port")
|
||
self.assertEqual(harvest_sea_class(glued, {}).get("运输分类"), "Port to Port")
|
||
|
||
def test_other_alias(self):
|
||
self.assertEqual(canonicalize_sea_class("其他"), "其他")
|
||
self.assertEqual(canonicalize_sea_class("其它"), "其他")
|
||
|
||
def test_door_to_door_rejected(self):
|
||
self.assertEqual(canonicalize_sea_class("门到门"), "")
|
||
|
||
def test_harvest_keeps_current_when_text_has_none(self):
|
||
got = harvest_sea_class("上海到洛杉矶整柜", {"运输分类": "Port to Port"})
|
||
self.assertEqual(got["运输分类"], "Port to Port")
|
||
|
||
def test_harvest_overrides_from_text(self):
|
||
got = harvest_sea_class("运输分类:其他", {"运输分类": "Port to Port"})
|
||
self.assertEqual(got["运输分类"], "其他")
|
||
|
||
def test_clarify_example_does_not_override_filled_other(self):
|
||
"""举例行里的 Port to Port 不能盖掉冒号后的其它/其他。"""
|
||
pasted = "1.运输分类(必填):其它\n(如:Port to Port、其他)"
|
||
got = harvest_sea_class(pasted, {"运输分类": "Port to Port"})
|
||
self.assertEqual(got["运输分类"], "其他")
|
||
other = harvest_sea_class("运输分类(必填):其他\n(如:Port to Port、其他)", {})
|
||
self.assertEqual(other["运输分类"], "其他")
|
||
|
||
def test_door_to_door_not_kept_as_trade_terms(self):
|
||
text = "海运、纽约港到巴生西港,机器设备,40HQ*1,整柜,1.5KG,15CBM,15件"
|
||
got = drop_invented_door_trade_terms(text, {"贸易条款": "门到门", "品名": "机器设备"})
|
||
self.assertNotIn("贸易条款", got)
|
||
kept = drop_invented_door_trade_terms("贸易条款:门到门", {"贸易条款": "门到门"})
|
||
self.assertEqual(kept["贸易条款"], "门到门")
|
||
|
||
def test_wo012_trade_port_class_other(self):
|
||
"""条款写 Port to Port、分类写其它:二者各归各栏,禁止互盖。"""
|
||
text = (
|
||
"运输方式:海运\n起运港:纽约港\n目的港:巴生西港\n品名:机器设备\n"
|
||
"货物数量:15件\n整柜或拼柜:整柜\n箱型箱量:40HQ*1\n"
|
||
"贸易条款:Port to Port\n运输分类:其它\n报价日期:2026-09-29"
|
||
)
|
||
got = harvest_sea_class(text, {"贸易条款": "门到门", "运输分类": "Port to Port"})
|
||
self.assertEqual(got.get("运输分类"), "其他")
|
||
got = drop_invented_door_trade_terms(text, {"贸易条款": "门到门", "运输分类": "其他"})
|
||
self.assertEqual(got.get("贸易条款"), "Port to Port")
|
||
self.assertEqual(got.get("运输分类"), "其他")
|
||
|
||
def test_trade_line_port_does_not_set_class_when_class_labeled_other(self):
|
||
text = "贸易条款:Port to Port\n运输分类:其它"
|
||
self.assertEqual(harvest_sea_class(text, {}).get("运输分类"), "其他")
|
||
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|