Files

197 lines
6.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""回归测试:独立入库政策(v1.0.32 立,v1.0.44 改)
历史沿革:
- v1.0.32:独立入库(无单、按 SKU 直进库存)停用,flagged 行从识别候选
里剔除,提示到后台按商品入库处理。
- v1.0.44:现场口径再改 —— 服务端已让自采商品走待验通道(下发待验行仍带
independent_inbound 标记),终端不再剔除,识别绑定照常,提交改调单行
结案接口 /mobile/inspection/complete(详见 _test_v1044.py)。
「按 SKU 直进库存」(stock-in)在任何开关下都不再使用。
本文件保留验证:
① indep_allowed() 默认仍为 False(stock-in 老路径保持停用)
② 名单只有 flagged 行 → 正常绑定到确认条(不再拦)
③ 混合名单 → 正常行照旧
④ 人工点选 flagged 行确认 → 正常提交(不再拒、不写 stock-in)
⑤ 无订单号的商品入库行 → 标签打「商品入库」,不是「None」
不需要秤/摄像头/网络。
"""
import sys
import io
import os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.flow import FlowEngine
CFG = {
'flow': {'min_scale_kg': 0.05, 'stable_ms': 400, 'settle_ms': 650,
'stable_delta_kg': 0.03, 'done_timeout_s': 12,
'done_lift_off_kg': 0.2, 'confirm_before_submit': True,
'auto_submit': True, 'allow_independent_inbound': False},
'scale': {'simulate': True},
'camera': {'simulate': True},
'vision': {'min_confidence': 60, 'auto_over_pct': 30},
'server': {'mock': True},
'noweigh': {'picking_allow_weight_unit': True},
}
EVENTS = []
def emit(ev, p=None):
EVENTS.append((ev, p))
eng = FlowEngine(CFG, emit)
eng.refresh_pending = lambda initial=False: None
eng.logged_in = True
eng._running = True
eng.server_config = {'weigh_match_tolerance_mode': 'percent',
'weigh_match_tolerance_value': 50}
GOOD = {'id': 'g1', 'item_name': '香菇', 'unit': '斤', 'required_qty': 10,
'order_code': 'PO001', 'sku_code': 'S1'}
LEGACY = {'id': 'x1', 'item_name': '香菇', 'unit': '斤', 'required_qty': 5,
'order_code': None, 'sku_code': 'S9',
'processing_details': {'independent_inbound': True}}
class FakeJournal:
def begin(self, *a, **k):
return {'op': a[0] if a else 'op'}
def update(self, *a, **k):
pass
def conclude(self, *a, **k):
pass
def has_unresolved(self):
return False
class FakeRecog:
def __init__(self, name='香菇', conf=90, alt=''):
self.name, self.conf, self.alt = name, conf, alt
def identify_ex(self, path, names, timeout=8):
return {'name': self.name, 'conf': self.conf, 'alt': self.alt,
'alt_conf': None}
def reset(rows):
EVENTS.clear()
eng.rows = [dict(r) for r in rows]
eng.state = 'IDLE'
eng._focus = None
eng._count_mode = False
eng._count_qty = 0.0
eng._frozen_kg = 10.0
eng._frozen_row = None
eng._aborted = False
eng._running = True
eng._stocked = {}
eng._last_ok = None
eng._plan = []
eng.journal = FakeJournal()
eng._cycle_conf = 90
eng._cycle_detected = ''
eng._cycle_recog_path = 'fake.jpg'
eng.recog = FakeRecog()
eng.submitted = []
eng.stocked = []
eng._start_submit = lambda row, biz, src: (
eng.submitted.append((row['id'], biz, src)),
eng._set_state('SUBMIT'))
eng._start_stock_in = lambda row, biz, src: (
eng.stocked.append((row['id'], biz, src)),
eng._set_state('SUBMIT'))
def last_focus():
for e, p in reversed(EVENTS):
if e == 'focus':
return p
return None
print('=== 1. stock-in 老路径保持停用 ===')
assert eng.indep_allowed() is False, '默认必须是关的'
print(' indep_allowed =', eng.indep_allowed())
print('=== 2. 名单只有 flagged 行 → 正常绑定到确认条(v1.0.44 不再拦) ===')
reset([LEGACY])
eng._run_recognition()
f = last_focus()
print(' state =', eng.state, '| submitted =', eng.submitted,
'| stocked =', eng.stocked)
print(' focus row =', (f or {}).get('row_id'))
assert not eng.stocked, 'stock-in 已死,绝不能走'
assert not eng.submitted
assert eng.state == 'CONFIRM'
assert f and f.get('row_id') == 'x1'
print('=== 3. 有名但只有 flagged 行 → 同样正常绑定 ===')
reset([LEGACY])
eng.recog = FakeRecog('香菇', 95)
eng._run_recognition()
assert not eng.stocked and not eng.submitted
assert (last_focus() or {}).get('row_id') == 'x1'
print(' ok,stocked =', eng.stocked)
print('=== 4. 正常行照旧:混名单里正常行可确认提交 ===')
reset([GOOD, LEGACY])
eng._run_recognition()
f = last_focus()
print(' focus row =', (f or {}).get('row_id'), '| state =', eng.state)
assert f and f['row_id'] == 'g1'
ok, msg = eng.confirm_focus()
print(' 确认 →', ok, msg, '| submitted =', eng.submitted)
assert ok and eng.submitted == [('g1', 20.0, '人工确认')]
assert not eng.stocked
print('=== 5. 人工点选 flagged 行再确认 → 正常提交(不再拒、不写 stock-in) ===')
reset([GOOD, LEGACY])
eng._to_focus(dict(LEGACY), 5.0, detected='香菇', conf=90, mode='weigh')
ok, msg = eng.confirm_focus()
print(' 确认 →', ok, msg, '| submitted =', eng.submitted)
assert ok and eng.submitted and eng.submitted[0][0] == 'x1'
assert not eng.stocked
print('=== 5b. 开关打开也一样:stock-in 已死,只走提交 ===')
CFG['flow']['allow_independent_inbound'] = True
reset([LEGACY])
assert eng.indep_allowed() is True
eng._run_recognition()
ok, msg = eng.confirm_focus()
print(' 确认 →', ok, msg, '| submitted =', eng.submitted,
'| stocked =', eng.stocked)
assert ok and eng.submitted and eng.submitted[0][0] == 'x1'
assert not eng.stocked
CFG['flow']['allow_independent_inbound'] = False
print('=== 7. 无订单号的商品入库行:标签打「商品入库」 ===')
reset([dict(GOOD, order_code=None)])
printed = []
class FakePrinter:
enabled = True
def print_inspection(self, oc, name, qty, unit, sup=''):
printed.append((oc, name, qty, unit))
return True, 'ok'
eng.printer = FakePrinter()
eng._do_print({'row': eng.rows[0], 'business': 20.0, 'station': 'inspection'})
print(' 标签字段 =', printed)
assert printed and printed[0][0] == '商品入库', printed
assert printed[0][1] == '香菇' and abs(printed[0][2] - 20.0) < 1e-9
print('\n全部通过 ✅')