586 lines
21 KiB
Python
586 lines
21 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""v1.0.65 回归:登录页可改服务器地址(server.base_url)
|
||
|
||
现场需求:换机房 / 切备用服务器时,不用退出程序、不用手改 config.json。
|
||
|
||
本文件验证:
|
||
① 登录页页脚显示当前服务器地址(问 mock 时提示离线模拟)
|
||
② 「修改」弹窗能打开,输入框预填当前地址
|
||
③ 非法地址(无 http(s) 前缀 / 空)不会保存
|
||
④ 合法地址:写回配置、立刻作用到 ApiClient、页脚刷新、弹窗关闭
|
||
⑤ 保存时把 server.mock 置回 false,并把地址记进 server.history
|
||
不需要网络(「测试连接」单独人工验,本用例不联网)。
|
||
"""
|
||
import sys
|
||
import io
|
||
import os
|
||
import json
|
||
import time
|
||
|
||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
import tkinter as tk
|
||
import ui.app as A
|
||
from ui.tablet import TouchButton
|
||
|
||
SAVED = {}
|
||
|
||
|
||
def fake_save(cfg, path='config.json'):
|
||
"""截住写盘:用例绝不碰真实 config.json"""
|
||
SAVED['cfg'] = json.loads(json.dumps(cfg, ensure_ascii=False))
|
||
SAVED['path'] = path
|
||
|
||
|
||
A.save_config = fake_save
|
||
|
||
ok = fail = 0
|
||
|
||
|
||
def check(name, cond, extra=''):
|
||
global ok, fail
|
||
if cond:
|
||
ok += 1
|
||
print(' ✔', name)
|
||
else:
|
||
fail += 1
|
||
print(' ✘', name, extra)
|
||
|
||
|
||
root = tk.Tk()
|
||
root.withdraw()
|
||
app = A.App(root)
|
||
cur = str((app.cfg.get('server') or {}).get('base_url') or '')
|
||
|
||
print('=== 1. 页脚显示当前服务器 ===')
|
||
app._refresh_login_srv()
|
||
check('页脚有当前地址', cur in app.lbl_login_srv.cget('text'),
|
||
app.lbl_login_srv.cget('text'))
|
||
|
||
print('=== 2. 打开修改窗口 ===')
|
||
app._edit_server()
|
||
root.update()
|
||
tops = [w for w in root.winfo_children() if isinstance(w, tk.Toplevel)]
|
||
check('弹窗已打开', len(tops) == 1, str(tops))
|
||
dlg = tops[0]
|
||
|
||
entries = []
|
||
btns = []
|
||
|
||
|
||
def walk(w):
|
||
for c in w.winfo_children():
|
||
if isinstance(c, tk.Entry):
|
||
entries.append(c)
|
||
if isinstance(c, TouchButton):
|
||
btns.append(c)
|
||
walk(c)
|
||
|
||
|
||
walk(dlg)
|
||
check('弹窗里有输入框', len(entries) == 1, str(len(entries)))
|
||
ent = entries[0]
|
||
check('预填当前地址', ent.get().rstrip('/') == cur.rstrip('/'), ent.get())
|
||
check('有保存按钮', any(b._text == '保存并应用' for b in btns),
|
||
str([b._text for b in btns]))
|
||
check('有测试连接按钮', any(b._text == '测试连接' for b in btns),
|
||
str([b._text for b in btns]))
|
||
save_btn = [b for b in btns if b._text == '保存并应用'][0]
|
||
|
||
print('=== 3. 非法地址不保存 ===')
|
||
for bad in ('', 'ftp://bad', 'www.example.com/api'):
|
||
ent.delete(0, 'end')
|
||
ent.insert(0, bad)
|
||
save_btn._command()
|
||
root.update()
|
||
check('拒绝「%s」' % (bad or '空'), not SAVED, str(SAVED))
|
||
|
||
print('=== 4. 合法地址:写配置 + 立即生效 ===')
|
||
ent.delete(0, 'end')
|
||
ent.insert(0, 'https://test.example.com/api/') # 结尾多余斜杠要去掉
|
||
save_btn._command()
|
||
root.update()
|
||
srv = (SAVED.get('cfg') or {}).get('server', {})
|
||
check('写回配置(去掉尾部斜杠)',
|
||
srv.get('base_url') == 'https://test.example.com/api', str(srv))
|
||
check('mock 置回 false', srv.get('mock') is False, str(srv.get('mock')))
|
||
check('ApiClient 立即生效',
|
||
app.engine.api.base_url == 'https://test.example.com/api',
|
||
app.engine.api.base_url)
|
||
check('页脚同步刷新',
|
||
'test.example.com/api' in app.lbl_login_srv.cget('text'),
|
||
app.lbl_login_srv.cget('text'))
|
||
check('弹窗已关闭',
|
||
not [w for w in root.winfo_children() if isinstance(w, tk.Toplevel)])
|
||
|
||
print('=== 5. 历史地址 ===')
|
||
check('地址进 history 首位',
|
||
(srv.get('history') or [])[:1] == ['https://test.example.com/api'],
|
||
str(srv.get('history')))
|
||
|
||
print('=== 6. 再打开时预填新地址,旧地址进「用过」 ===')
|
||
app._edit_server()
|
||
root.update()
|
||
dlg2 = [w for w in root.winfo_children() if isinstance(w, tk.Toplevel)][0]
|
||
entries2 = []
|
||
btns2 = []
|
||
|
||
|
||
def walk2(w):
|
||
for c in w.winfo_children():
|
||
if isinstance(c, tk.Entry):
|
||
entries2.append(c)
|
||
if isinstance(c, TouchButton):
|
||
btns2.append(c)
|
||
walk2(c)
|
||
|
||
|
||
walk2(dlg2)
|
||
check('预填新地址', entries2[0].get() == 'https://test.example.com/api',
|
||
entries2[0].get())
|
||
if cur:
|
||
chips = [b for b in btns2
|
||
if b._text not in ('取消', '保存并应用', '测试连接')]
|
||
check('有「用过」快捷按钮', bool(chips),
|
||
str([b._text for b in btns2]))
|
||
if chips:
|
||
chips[0]._command() # 点一下应该把旧地址填回输入框
|
||
root.update()
|
||
check('点一下能切回旧地址',
|
||
entries2[0].get().rstrip('/') == cur.rstrip('/'),
|
||
entries2[0].get())
|
||
else:
|
||
print(' - 跳过「用过」校验(原配置没有地址)')
|
||
dlg2.destroy()
|
||
root.update()
|
||
|
||
print('=== 7. 写盘失败要回滚(磁盘满/文件被占用) ===')
|
||
cur2 = app.cfg['server']['base_url']
|
||
|
||
|
||
def boom(cfg, path='config.json'):
|
||
raise IOError('模拟写盘失败')
|
||
|
||
|
||
A.save_config = boom
|
||
app._edit_server()
|
||
root.update()
|
||
dlg3 = [w for w in root.winfo_children() if isinstance(w, tk.Toplevel)][0]
|
||
entries3 = []
|
||
btns3 = []
|
||
|
||
|
||
def walk3(w):
|
||
for c in w.winfo_children():
|
||
if isinstance(c, tk.Entry):
|
||
entries3.append(c)
|
||
if isinstance(c, TouchButton):
|
||
btns3.append(c)
|
||
walk3(c)
|
||
|
||
|
||
walk3(dlg3)
|
||
entries3[0].delete(0, 'end')
|
||
entries3[0].insert(0, 'https://broken.example.com/api')
|
||
[b for b in btns3 if b._text == '保存并应用'][0]._command()
|
||
root.update()
|
||
check('配置回滚', app.cfg['server']['base_url'] == cur2,
|
||
app.cfg['server']['base_url'])
|
||
check('ApiClient 回滚', app.engine.api.base_url == cur2,
|
||
app.engine.api.base_url)
|
||
check('弹窗不关(方便重试)',
|
||
bool([w for w in root.winfo_children() if isinstance(w, tk.Toplevel)]))
|
||
dlg3.destroy()
|
||
|
||
print('=== 8. 页脚布局:按钮不被地址挤掉 ===')
|
||
root.deiconify() # 需要真实几何信息才能验布局
|
||
root.update()
|
||
foot = app.lbl_login_srv.master
|
||
form = foot.master
|
||
frow = [w for w in foot.winfo_children() if isinstance(w, tk.Frame)][0]
|
||
edit_btn = [w for w in frow.winfo_children()
|
||
if isinstance(w, tk.Button) and '修改' in str(w.cget('text'))][0]
|
||
quit_btn = [w for w in frow.winfo_children()
|
||
if isinstance(w, tk.Button) and '退出' in str(w.cget('text'))][0]
|
||
root.update_idletasks()
|
||
check('「修改服务器地址」没被裁切',
|
||
edit_btn.winfo_width() >= edit_btn.winfo_reqwidth() - 1,
|
||
'实际 %d / 需要 %d' % (edit_btn.winfo_width(),
|
||
edit_btn.winfo_reqwidth()))
|
||
check('「退出程序」没被裁切',
|
||
quit_btn.winfo_width() >= quit_btn.winfo_reqwidth() - 1,
|
||
'实际 %d / 需要 %d' % (quit_btn.winfo_width(),
|
||
quit_btn.winfo_reqwidth()))
|
||
check('两个按钮不重叠',
|
||
edit_btn.winfo_x() + edit_btn.winfo_width() <= quit_btn.winfo_x(),
|
||
'%d+%d vs %d' % (edit_btn.winfo_x(), edit_btn.winfo_width(),
|
||
quit_btn.winfo_x()))
|
||
check('地址行在按钮行上方(分两行)',
|
||
app.lbl_login_srv.winfo_y() + app.lbl_login_srv.winfo_height()
|
||
<= frow.winfo_y() + 1,
|
||
'addr %d+%d, row %d' % (app.lbl_login_srv.winfo_y(),
|
||
app.lbl_login_srv.winfo_height(),
|
||
frow.winfo_y()))
|
||
check('地址不超出行宽',
|
||
app.lbl_login_srv.winfo_reqwidth() <= form.winfo_width(),
|
||
'%d vs %d' % (app.lbl_login_srv.winfo_reqwidth(), form.winfo_width()))
|
||
root.withdraw()
|
||
|
||
print('=== 9. 识别通道不继承系统代理(ProxyError 回归) ===')
|
||
from core.recognition.cloud import CloudRecognizer
|
||
from core.api.client import ApiClient, ApiError
|
||
|
||
c1 = CloudRecognizer({'vision': {'provider': 'doubao', 'api_key': 'k'},
|
||
'account': {'role': 'inspector'}})
|
||
check('默认直连(trust_env=False)', c1._session.trust_env is False,
|
||
str(c1._session.trust_env))
|
||
c2 = CloudRecognizer({'vision': {'provider': 'doubao', 'api_key': 'k',
|
||
'trust_env': True},
|
||
'account': {'role': 'inspector'}})
|
||
check('配置可显式打开代理', c2._session.trust_env is True,
|
||
str(c2._session.trust_env))
|
||
|
||
print('=== 10. 严格写入开关关闭时,提示要能指导现场 ===')
|
||
api = ApiClient({'server': {'base_url': 'http://x', 'mock': False},
|
||
'account': {}})
|
||
api._request = lambda *a, **k: {'data': {
|
||
'strict_capable': True, 'scope_token': 'tok',
|
||
'strict_write_enabled': False}}
|
||
try:
|
||
api.preview_merge_scope('1', ['1'])
|
||
msg = ''
|
||
except ApiError as e:
|
||
msg = str(e)
|
||
check('提示包含处置办法', '管理员' in msg and '严格入库写入' in msg, msg)
|
||
check('提示写明本次未提交', '未提交' in msg, msg)
|
||
|
||
print('=== 11. 服务端重量容差拒绝 → 提示要说清原因 ===')
|
||
from core.flow import reject_hint
|
||
|
||
row30 = {'item_name': '苹果', 'unit': '斤', 'remaining_qty': 30}
|
||
m = reject_hint('业务拒绝 400: {"error":"weigh_tolerance_exceeded"}', row30)
|
||
check('提示含应量与单位', '30.00 斤' in m, m)
|
||
check('提示说未入账', '未入账' in m, m)
|
||
check('其他错误不瞎改',
|
||
reject_hint('业务拒绝 400: {"error":"invalid_cost"}', row30) == '',
|
||
reject_hint('业务拒绝 400: {"error":"invalid_cost"}', row30))
|
||
|
||
print('=== 12. 模拟称重量可给列表(一屏演示多种商品) ===')
|
||
from core.scale.reader import sim_kg_of
|
||
|
||
check('单个数字', sim_kg_of(15.0, 3) == 15.0, sim_kg_of(15.0, 3))
|
||
check('列表按轮次循环',
|
||
[sim_kg_of([15, 6, 3], i) for i in range(4)]
|
||
== [15.0, 6.0, 3.0, 15.0],
|
||
[sim_kg_of([15, 6, 3], i) for i in range(4)])
|
||
check('列表里 0/非法值被跳过', sim_kg_of([0, '3', None, 6], 0) == 3.0,
|
||
sim_kg_of([0, '3', None, 6], 0))
|
||
check('没配 = 不放货', sim_kg_of(None, 0) == 0.0)
|
||
|
||
print('=== 13. 回放摄像头(没相机时用真实商品图跑真识别) ===')
|
||
import numpy as np
|
||
from core.evidence.frames import FrameSource
|
||
|
||
fs = FrameSource({'camera': {'simulate': True, 'replay_dir': 'data/photos',
|
||
'width': 1280, 'height': 720,
|
||
'replay_hold_s': 1}})
|
||
files = fs._replay_files()
|
||
check('扫到回放图', len(files) >= 1, '%d 张' % len(files))
|
||
fs.start()
|
||
import time as _t
|
||
_t.sleep(1.0)
|
||
img, seq, _arr = fs.get_frame()
|
||
check('回放画面尺寸正确',
|
||
img is not None and img.shape == (720, 1280, 3),
|
||
str(None if img is None else img.shape))
|
||
check('回放画面不是空白占位',
|
||
img is not None and float(np.std(img)) > 10,
|
||
str(None if img is None else float(np.std(img))))
|
||
check('帧序号在推进', seq > 0, str(seq))
|
||
check('状态显示回放', '回放摄像头' in fs.preview_status(), fs.preview_status())
|
||
fs.stop()
|
||
_t.sleep(0.3)
|
||
|
||
check('不配 replay_dir 仍是合成画面',
|
||
FrameSource({'camera': {'simulate': True}})._replay_files() == [])
|
||
|
||
print('=== 14. 模拟画面不得进样本库 ===')
|
||
import core.recognition.dataset as DS
|
||
|
||
added = []
|
||
|
||
|
||
class _FakeStore:
|
||
def add(self, name, path, source='weak', was='', conf=None):
|
||
added.append(name)
|
||
return True
|
||
|
||
|
||
DS.get_store = lambda *a, **k: _FakeStore()
|
||
sim_cfg = {'flow': {}, 'camera': {'simulate': True}, 'scale': {},
|
||
'vision': {}, 'server': {'mock': True}}
|
||
simg = A.FlowEngine(sim_cfg, lambda e, p=None: None)
|
||
simg._cycle_recog_path = 'data/photos/红富士苹果.png'
|
||
simg._learn_sample({'item_name': '苹果'})
|
||
check('模拟摄像头不存样本', not added, str(added))
|
||
simg.cfg['camera']['simulate'] = False
|
||
simg._learn_sample({'item_name': '苹果'})
|
||
check('真实摄像头才存样本', added == ['苹果'], str(added))
|
||
|
||
print('=== 15. 分组行拆出原料/普通各自的量 ===')
|
||
grouper = ApiClient({'server': {'base_url': 'http://x', 'mock': True},
|
||
'account': {}})
|
||
flat = [
|
||
{'id': 'g1', 'item_name': '冬瓜', 'unit': '斤', 'remaining_qty': 12,
|
||
'processing_details': {'independent_inbound': True}},
|
||
{'id': 'g2', 'item_name': '冬瓜', 'unit': '斤', 'remaining_qty': 20},
|
||
]
|
||
groups = [{'inspection_ids': ['g1', 'g2'],
|
||
'group_key': 'BR003|-|independent|purchase|SKU1|斤',
|
||
'group_hash': 'h1', 'item_name': '冬瓜', 'unit': '斤',
|
||
'total_prepare_qty': 32, 'lines': []}]
|
||
rows = grouper._preview_group_rows(groups, flat)
|
||
check('分组行算出来了', len(rows) == 1, str(len(rows)))
|
||
parts = {p['kind']: p for p in (rows[0].get('group_parts') or [])}
|
||
check('原料 12 斤', parts.get('independent', {}).get('qty') == 12.0,
|
||
str(parts))
|
||
check('普通 20 斤', parts.get('normal', {}).get('qty') == 20.0, str(parts))
|
||
from core.matching.engine import is_independent_inbound as _is_indep
|
||
check('混合组不能整组标成独立入库',
|
||
not _is_indep(rows[0]),
|
||
str(rows[0].get('processing_details')))
|
||
|
||
all_ind = [
|
||
{'id': 'x1', 'unit': '斤', 'remaining_qty': 5,
|
||
'processing_details': {'independent_inbound': True}},
|
||
{'id': 'x2', 'unit': '斤', 'remaining_qty': 7,
|
||
'processing_details': {'independent_inbound': True}},
|
||
]
|
||
rows2 = grouper._preview_group_rows(
|
||
[{'inspection_ids': ['x1', 'x2'],
|
||
'group_key': 'BR003|-|independent|purchase|SKU2|斤',
|
||
'group_hash': 'h2', 'item_name': '南瓜', 'unit': '斤'}], all_ind)
|
||
check('全原料组仍标记独立入库',
|
||
_is_indep(rows2[0]), str(rows2[0].get('processing_details')))
|
||
|
||
print('=== 16. 卡片黄底提示文案 ===')
|
||
check('混合:分开写两边',
|
||
app._indep_badge_text(rows[0]) == '独立入库原料 12 斤 · 普通入库 20 斤',
|
||
app._indep_badge_text(rows[0]))
|
||
check('全原料:保持原文案',
|
||
app._indep_badge_text(rows2[0]) == '独立入库 · 加工原材料',
|
||
app._indep_badge_text(rows2[0]))
|
||
check('全普通:不显示',
|
||
app._indep_badge_text({'group_parts': [{'kind': 'normal',
|
||
'qty': 32}],
|
||
'unit': '斤'}) == '',
|
||
app._indep_badge_text({'group_parts': [{'kind': 'normal',
|
||
'qty': 32}], 'unit': '斤'}))
|
||
check('无明细时回退旧判断(普通行不显示)',
|
||
app._indep_badge_text({'item_name': '冬瓜', 'unit': '斤'}) == '',
|
||
app._indep_badge_text({'item_name': '冬瓜', 'unit': '斤'}))
|
||
|
||
print('=== 17. 待办列表左右滑动翻页 ===')
|
||
app._page_count = 3
|
||
app._page = 1
|
||
app._layout_cards = lambda: None
|
||
|
||
|
||
def _ev(x, y):
|
||
return type('E', (), {'x_root': x, 'y_root': y})()
|
||
|
||
|
||
app._swipe_press(_ev(600, 300))
|
||
app._swipe_move(_ev(520, 302))
|
||
app._swipe_release(_ev(510, 302))
|
||
check('左划 → 下一页', app._page == 2, str(app._page))
|
||
|
||
app._swipe_press(_ev(500, 300))
|
||
app._swipe_move(_ev(600, 300))
|
||
app._swipe_release(_ev(620, 300))
|
||
check('右划 → 上一页', app._page == 1, str(app._page))
|
||
|
||
app._swipe_press(_ev(600, 300))
|
||
app._swipe_move(_ev(605, 400))
|
||
app._swipe_release(_ev(605, 420))
|
||
check('竖向拖动不翻页', app._page == 1, str(app._page))
|
||
|
||
app._swipe_press(_ev(600, 300))
|
||
app._swipe_move(_ev(560, 300))
|
||
app._swipe_release(_ev(555, 300))
|
||
check('横向位移不够不翻页', app._page == 1, str(app._page))
|
||
|
||
app._page_count = 1
|
||
app._page = 0
|
||
app._swipe_press(_ev(600, 300))
|
||
app._swipe_move(_ev(400, 300))
|
||
app._swipe_release(_ev(380, 300))
|
||
check('只有一页时不翻', app._page == 0, str(app._page))
|
||
|
||
print('=== 18. 顶栏/窗口标题按工位改名 ===')
|
||
check('分拣工位叫「分拣工作站」',
|
||
app._station_title('picking') == '分拣工作站',
|
||
app._station_title('picking'))
|
||
check('入库工位叫「入库工作站」',
|
||
app._station_title('inspection') == '入库工作站',
|
||
app._station_title('inspection'))
|
||
app.engine.station = 'picking'
|
||
app._paint_station()
|
||
check('窗口标题跟着变', app.root.title() == '分拣工作站', app.root.title())
|
||
|
||
print('=== 19. 卡片高亮:不抖 + 不同时亮两张 ===')
|
||
# 把登录页换掉,真正建一次作业界面。
|
||
# 必须 deiconify:窗口 withdraw 时 canvas 宽只有 1px,_layout_cards 直接
|
||
# return,卡片根本没摆上,下面那些「几何没变」的断言会空过(踩过)。
|
||
for _w in list(root.winfo_children()):
|
||
_w.destroy()
|
||
# 第 17 组把 _layout_cards 换成了空函数(测翻页时不想重排),这里恢复真方法
|
||
try:
|
||
del app._layout_cards
|
||
except AttributeError:
|
||
pass
|
||
app.engine.station = 'picking'
|
||
app.engine.logged_in = True
|
||
app.ready = True
|
||
root.deiconify()
|
||
try:
|
||
root.geometry('1400x820+20+20')
|
||
except Exception:
|
||
pass
|
||
root.update()
|
||
app._build()
|
||
root.update()
|
||
frows = [{'id': 'c%d' % i, 'item_name': n, 'unit': '个', 'remaining_qty': 2,
|
||
'customer_name': '富顺分公司', 'order_code': 'O%d' % i}
|
||
for i, n in enumerate(['虾皮', '绿豆', '盐', '花椒'])]
|
||
app.engine.rows = [dict(r) for r in frows]
|
||
app._fill_todo(frows)
|
||
root.update()
|
||
|
||
gridded = [c for c in app.todo_cards.values() if c.winfo_manager() == 'grid']
|
||
check('卡片真的摆上了(不是空跑)', len(gridded) >= 2, str(len(gridded)))
|
||
check('画布有真实宽度', app.todo_canvas.winfo_width() > 400,
|
||
str(app.todo_canvas.winfo_width()))
|
||
check('所有卡边框厚度统一',
|
||
{c.cget('highlightthickness') for c in app.todo_cards.values()}
|
||
== {A.CARD_HL},
|
||
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
|
||
check('高亮样式是纯颜色', isinstance(app._card_style('c1'), str),
|
||
str(type(app._card_style('c1'))))
|
||
|
||
|
||
def _positions():
|
||
return {r: (c.winfo_x(), c.winfo_y(), c.winfo_width(),
|
||
c.winfo_height(), c.grid_info().get('row'),
|
||
c.grid_info().get('column'))
|
||
for r, c in app.todo_cards.items()}
|
||
|
||
|
||
# 点一张 → 只有它亮,位置/尺寸不动
|
||
p_before = _positions()
|
||
app._pre_rid = None
|
||
app._sel_rid = 'c1'
|
||
app._repaint_cards(['c1'])
|
||
root.update()
|
||
p_after = _positions()
|
||
check('选中不改变卡片几何', p_before == p_after,
|
||
str({k: (p_before[k], p_after[k]) for k in p_after
|
||
if p_before[k] != p_after[k]}))
|
||
check('选中不改边框粗细',
|
||
{c.cget('highlightthickness') for c in app.todo_cards.values()}
|
||
== {A.CARD_HL},
|
||
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
|
||
|
||
# 高亮只跟手点那张走(现场:亮盐、详情却是刚点的腐竹)
|
||
app._pre_rid = 'c0'
|
||
app._sel_rid = 'c2'
|
||
app._repaint_cards(['c0', 'c1', 'c2', 'c3'])
|
||
root.update()
|
||
lit = {r: c for r, c in app._paint_cache.items() if c != A.C.line}
|
||
check('高亮跟最后点过的那张走', set(lit) == {'c2'}, str(lit))
|
||
|
||
# 连点两张:先点那张的 preselect 事件晚到,不能把高亮挪回去
|
||
app.engine.state = 'IDLE'
|
||
app._pre_rid = None
|
||
app._sel_rid = None
|
||
app._repaint_cards(['c0', 'c1', 'c2', 'c3'])
|
||
app._select_card('c0')
|
||
app._select_card('c1')
|
||
app._on_preselect('c0') # 迟到的旧事件
|
||
root.update()
|
||
lit = {r: c for r, c in app._paint_cache.items() if c != A.C.line}
|
||
check('迟到的预选事件不挪高亮', set(lit) == {'c1'}, str(lit))
|
||
|
||
# 非待机态点卡:引擎不收预选,但高亮仍跟着手点走(只能一张)
|
||
app.engine.state = 'WEIGHING'
|
||
app.engine._pre_pick_rid = 'c0' # 引擎真正记着的预选
|
||
app._pre_rid = 'c0'
|
||
app._sel_rid = None
|
||
app._repaint_cards(['c0', 'c1', 'c2', 'c3'])
|
||
app._select_card('c2')
|
||
root.update()
|
||
lit = {r: c for r, c in app._paint_cache.items() if c != A.C.line}
|
||
check('非待机态点卡也只亮手点那张', set(lit) == {'c2'}, str(lit))
|
||
app.engine.state = 'IDLE'
|
||
app.engine._pre_pick_rid = None
|
||
|
||
# 引擎接管确认行 → 旧琥珀被清掉,只剩一张绿的
|
||
app._pre_rid = 'c1'
|
||
app._sel_rid = 'c1'
|
||
app._repaint_cards(['c0', 'c1', 'c2', 'c3'])
|
||
root.update()
|
||
p2 = _positions()
|
||
app._on_focus({'row_id': 'c3', 'mode': 'weigh'})
|
||
root.update()
|
||
lit = {r: c for r, c in app._paint_cache.items() if c != A.C.line}
|
||
check('确认时只剩一张高亮', len(lit) == 1 and 'c3' in lit, str(lit))
|
||
check('旧的手动选中已清', app._sel_rid is None, str(app._sel_rid))
|
||
check('旧的预选已清', app._pre_rid is None, str(app._pre_rid))
|
||
p3 = _positions()
|
||
check('确认行高亮不引起抖动', p2 == p3,
|
||
str({k: (p2[k], p3[k]) for k in p3 if p2[k] != p3[k]}))
|
||
check('确认行高亮不改边框粗细',
|
||
{c.cget('highlightthickness') for c in app.todo_cards.values()}
|
||
== {A.CARD_HL},
|
||
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
|
||
|
||
print('=== 20. 分页不裁最底行(徽标只在后面几页) ===')
|
||
rows2 = []
|
||
_names = ['尖白菜', '仔姜', '四季豆', '莲花白', '大白菜', '大葱']
|
||
for _i in range(24):
|
||
rows2.append({
|
||
'id': 'p%02d' % _i,
|
||
'item_name': _names[_i % len(_names)],
|
||
'unit': '斤',
|
||
'remaining_qty': 5 + _i,
|
||
'customer_name': '富顺分公司',
|
||
# 第一页没有徽标(卡矮),后面几页有(卡高)——现场就是这个组合
|
||
'independent_inbound': (_i >= 12),
|
||
})
|
||
app.engine.rows = [dict(r) for r in rows2]
|
||
app._fill_todo(rows2)
|
||
root.update()
|
||
time.sleep(0.25)
|
||
root.update()
|
||
|
||
cv = app.todo_canvas
|
||
worst = []
|
||
for _pg in range(max(1, getattr(app, '_page_count', 1))):
|
||
inside = [c for c in app.todo_cards.values()
|
||
if c.winfo_manager() == 'grid']
|
||
for c in inside:
|
||
over = (c.winfo_y() + c.winfo_height()) - cv.winfo_height()
|
||
if over > 0:
|
||
worst.append((_pg + 1, c.winfo_y(), c.winfo_height(), over))
|
||
app._page_turn(1)
|
||
root.update()
|
||
check('每一页卡片都在视口内(不被裁)', not worst,
|
||
'超出:%r' % worst[:4])
|
||
check('多页时页码正常', getattr(app, '_page_count', 1) > 1,
|
||
getattr(app, '_page_count', 1))
|
||
|
||
root.destroy()
|
||
print('\n结果:%d 项通过,%d 项失败' % (ok, fail))
|
||
sys.exit(1 if fail else 0)
|