Port the AVA2 switchbot window and switchbot module

PythonSwitchbot + PythonNetworkStreamPhaseGameSwitchbot from AVA2 (CG/GC 171,
SWITCHBOT window 7, SLOT_TYPE_SWITCHBOT), uiswitchbot.py verbatim in
SwitchbotScript.inc plus its ENABLE_SWITCHBOT glue (tooltip, mouse/inventory
drag-back, interface/game hooks, zh strings, server switchbot_* messages).
Entry is the minimap 洗练 button; F9 stays with auto-hunt. The client version
timestamp is now "mt20261016" so the server enables the switchbot.
50348/50349 no longer open the window. Adds docs/AVA2-PARITY-PLAN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 20:26:06 +09:00
co-authored by Claude Opus 5.5
parent e70a6abf7a
commit fc98e6e2b4
21 changed files with 2941 additions and 577 deletions
+3 -4
View File
@@ -24,12 +24,11 @@ class Action(Widget):
class ItemActionsTests(unittest.TestCase):
def setUp(self):
names=('game','grp','player','ui','wndMgr','mt_biolog','mt_preview','mt_chest','mt_wiki','uiInventory','mt_battlepass','mt_switchbot')
names=('game','grp','player','ui','wndMgr','mt_biolog','mt_preview','mt_chest','mt_wiki','uiInventory','mt_battlepass')
mods={name:types.ModuleType(name) for name in names};self.mods=mods;self.actions=[];self.bag={3:(50011,2),4:(19,1)}
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None))
mods['uiInventory'].InventoryWindow=type('InventoryWindow',(),dict(UseItemSlot=lambda owner,cell:self.actions.append(('use',cell)),_InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos=lambda owner,cell:cell))
mods['mt_battlepass'].g_window=types.SimpleNamespace(OfferTicket=lambda c,v:self.actions.append(('ticket',c,v)))
mods['mt_switchbot'].g_window=types.SimpleNamespace(Open=lambda:self.actions.append(('lock',)))
mods['ui'].Window=Widget;mods['mt_biolog'].Action=Action
mods['player'].GetItemIndex=lambda cell:self.bag.get(cell,(0,0))[0]
mods['player'].GetItemCount=lambda cell:self.bag.get(cell,(0,0))[1]
@@ -57,11 +56,11 @@ class ItemActionsTests(unittest.TestCase):
self.ns['ShowInventory'](self.owner,4)
self.window.buttons[1].event();self.assertEqual(self.actions[-1],('preview',19))
def test_ticket_lock_and_original_use(self):
def test_ticket_and_original_use(self):
inventory=self.mods['uiInventory'].InventoryWindow()
for vnum in (25159,50348,50349,27001):
self.bag[5]=(vnum,1);inventory.UseItemSlot(5)
self.assertEqual(self.actions,[('ticket',5,25159),('lock',),('lock',),('use',5)])
self.assertEqual(self.actions,[('ticket',5,25159),('use',5),('use',5),('use',5)]) # 50348/50349 no longer open the switchbot window
def test_stale_actions_never_fire(self):
for change in ('page','vnum','count','closed'):
+94 -144
View File
@@ -1,23 +1,28 @@
import re
"""mt_switchbot (SwitchbotScript.inc): AVA2 root/uiswitchbot.py verbatim plus its ENABLE_SWITCHBOT glue. The window
talks to the C++ switchbot module (CG/GC_SWITCHBOT 171), items move through the SWITCHBOT window, and the server
reports end/stop/error as switchbot_* commands. The old /mt_switchbot chat protocol is gone."""
import sys
import types
import unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
AVA2=ROOT.parent/'AVA2/TEST/1. Client DEV/pack_maker/root/uiswitchbot.py'
def script(name):return (ROOT/'src/platform/ScriptLib'/name).read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0]
class Widget(object):
def __init__(self,*a,**k):self.shown=False;self.text='';self.pos=(0,0);self.size=(0,0)
def __getattr__(self,name):return lambda *a,**k:None
def __init__(self,*a,**k):self.shown=False;self.text='';self.pos=(0,0);self.size=(0,0);self.itemList=[]
def __getattr__(self,name):
if name.startswith('__'):raise AttributeError(name)
return lambda *a,**k:0
def Show(self):self.shown=True
def Hide(self):self.shown=False
def IsShow(self):return self.shown
def SetText(self,text):self.text=text
def GetText(self):return self.text
def SetPosition(self,x,y):self.pos=(x,y)
def GetLocalPosition(self):return self.pos
def GetGlobalPosition(self):return self.pos
def SetSize(self,w,h):self.size=(w,h)
def GetWidth(self):return self.size[0]
@@ -25,159 +30,104 @@ class Widget(object):
class Action(Widget):
def __init__(self,parent,x,y,width,text,event):
Widget.__init__(self);self.pos=(x,y);self.event=event;self.enabled=True;self.label=Widget();self.text=text;self.shown=True
def SetEnabled(self,enabled):self.enabled=enabled
def __init__(self,parent,x,y,width,text,event):Widget.__init__(self);self.text=text;self.event=event;self.shown=True
class Mouse(object):
def __init__(self):self.AttachedFlag=False;self.AttachedType=0;self.AttachedSlotNumber=0;self.AttachedCount=0;self.AttachedIconHandle=0
def AttachObject(self,owner,kind,slot,vnum,count=0):
self.AttachedFlag=True;self.AttachedType=kind;self.AttachedSlotNumber=slot;self.AttachedCount=count;self.AttachedIconHandle=9
def DeattachObject(self):self.AttachedFlag=False;self.AttachedIconHandle=0
def isAttached(self):return self.AttachedFlag
def GetAttachedType(self):return self.AttachedType
def GetAttachedSlotNumber(self):return self.AttachedSlotNumber
def GetAttachedItemCount(self):return self.AttachedCount
class SwitchbotTests(unittest.TestCase):
def setUp(self):
self.time=1.;self.sent=[];self.chat=[];self.events=[]
self.inventory={10:(11209,1,[(3,2),(15,1)]),20:(71084,7,[]),21:(71084,3,[]),30:(27001,5,[])}
protos={11209:(2,0),71084:(3,18),27001:(3,0)}
mods={n:types.ModuleType(n) for n in ('app','chat','game','grp','item','net','player','ui','uiToolTip','wndMgr','mt_biolog','mt_wiki')}
mods['app'].GetTime=lambda:self.time
self.moves=[];self.chat=[];self.icons=[];self.deleted=[];self.passed=[];self.bag={(7,2):11209}
names=('dbg','constInfo','app','ime','item','grp','net','ui','uiToolTip','player','mouseModule','localeInfo','wndMgr',
'cPickle','switchbot','chat','game','interfaceModule','uiInventory','mt_biolog')
mods={n:types.ModuleType(n) for n in names};self.mods=mods
mods['constInfo'].GET_ITEM_QUESTION_DIALOG_STATUS=lambda:0
mods['grp'].GenerateColor=lambda *a:0
it=mods['item'];it.APPLY_SKILL_DAMAGE_BONUS=71;it.APPLY_NORMAL_HIT_DAMAGE_BONUS=72;self.selected=0
it.SelectItem=lambda v:setattr(self,'selected',v);it.GetItemName=lambda:'N%d'%self.selected;it.GetItemSize=lambda:(1,2)
it.DeleteIconInstance=self.deleted.append
mods['net'].SendItemMovePacket=lambda *a:self.moves.append(a)
ui=mods['ui']
for n in ('Window','Bar','BoardWithTitleBar','Box','Button','EditLine','ExpandedImageBox','GridSlotWindow','ListBoxEx',
'RadioButton','ScrollBar','TextLine'):setattr(ui,n,type(n,(Widget,),{}))
ui.__mem_func__=lambda f:f
mods['uiToolTip'].ItemToolTip=type('ItemToolTip',(),dict(AFFECT_DICT={}))
pl=mods['player'];pl.INVENTORY=1;pl.SWITCHBOT=7;pl.SLOT_TYPE_INVENTORY=1;pl.SLOT_TYPE_SWITCHBOT=33
pl.AutoHuntLocalize=lambda t:t;pl.GetItemIndex=lambda w,c:self.bag.get((w,c),0)
mods['mouseModule'].CMouseController=Mouse;self.mouse=mods['mouseModule'].mouseController=Mouse()
mods['wndMgr'].AttachIcon=lambda *a:self.icons.append(a)
sb=mods['switchbot'];sb.SLOT_COUNT=5;sb.ALTERNATIVE_COUNT=2
mods['chat'].CHAT_TYPE_INFO=1;mods['chat'].AppendChat=lambda t,m:self.chat.append(m)
mods['net'].SendChatPacket=self.sent.append
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None,BINARY_ServerCommand_Run=lambda s,line:7))
grp=mods['grp'];grp.SetColor=grp.RenderBar=grp.RenderBox=lambda *a:None
it=mods['item'];it.ITEM_TYPE_WEAPON=1;it.ITEM_TYPE_ARMOR=2;it.ITEM_TYPE_USE=3;it.ARMOR_PENDANT=7;self.selected=None
it.SelectItem=lambda v:setattr(self,'selected',v);it.GetItemType=lambda:protos[self.selected][0];it.GetItemSubType=lambda:protos[self.selected][1]
it.GetItemName=lambda:'N%d'%self.selected
pl=mods['player'];pl.INVENTORY=1;pl.INVENTORY_PAGE_SIZE=45;pl.INVENTORY_PAGE_COUNT=5
pl.GetItemIndex=lambda w,c:self.inventory.get(c,(0,))[0];pl.GetItemCount=lambda w,c:self.inventory[c][1]
pl.GetItemAttribute=lambda w,c,i:(self.inventory[c][2]+[(0,0)]*5)[i]
mods['ui'].Window=Widget
mods['uiToolTip'].ItemToolTip=type('ItemToolTip',(),dict(AFFECT_DICT={3:lambda v:'STR+%d'%v}))
mods['wndMgr'].GetScreenWidth=lambda:800;mods['wndMgr'].GetScreenHeight=lambda:600
mods['mt_biolog'].Action=Action;mods['mt_biolog'].Text=lambda p,x,y,t='',c=0:Widget();mods['mt_biolog'].L=lambda t:t if isinstance(t,str) else t.decode('utf-8')
mods['mt_wiki'].U=lambda t:t if isinstance(t,str) else t.decode('utf-8');mods['mt_wiki'].B=lambda t,limit=0:t
self.previous={n:sys.modules.get(n) for n in mods}
sys.modules.update(mods)
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None,
BINARY_ServerCommand_Run=lambda s,line:self.passed.append(line) or 7))
mods['interfaceModule'].Interface=type('Interface',(),dict(HideAllWindows=lambda s:None,_Interface__HideWindows=lambda s:[]))
mods['uiInventory'].InventoryWindow=type('InventoryWindow',(),dict(SelectEmptySlot=lambda s,c:self.passed.append(('empty',c)),
_InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos=lambda s,c:c+45))
mods['mt_biolog'].Action=Action
self.previous={n:sys.modules.get(n) for n in mods};sys.modules.update(mods)
self.ns={'__name__':'mt_switchbot'};exec(script('SwitchbotScript.inc'),self.ns)
self.bot=self.ns['Bot'](self.sent.append,lambda:self.time,self.events.append)
def tearDown(self):
for name,value in self.previous.items():
if value is None:sys.modules.pop(name,None)
else:sys.modules[name]=value
for n,value in self.previous.items():
if value is None:sys.modules.pop(n,None)
else:sys.modules[n]=value
def advance(self,seconds=.4):self.time+=seconds;self.bot.Tick()
def test_verbatim_ava2_window(self):
text=script('SwitchbotScript.inc')
for name in ('SwitchbotItemTab(ui.ThinBoardCircle)','SwitchbotAttribute(ui.Window)','SwitchbotWindow(ui.BoardWithTitleBar)',
'SearchListWindow(ui.BoardWithTitleBar)','ConfigurationWindow(ui.BoardWithTitleBar)'):
self.assertIn('class %s:'%name,text)
self.assertNotIn('/mt_switchbot',text);self.assertNotIn('SendChatPacket',text)
if not AVA2.is_file():self.skipTest('AVA2 tree not checked out')
src=AVA2.read_bytes().decode('latin1').replace('\r\n','\n');src=src[src.index('COLOR_INACTIVE'):].rstrip()
src=src.replace('self.alternativeTextLine.SetText("Alternativen:")','self.alternativeTextLine.SetText(localeInfo.SWITCHBOT_ALTERNATIVES)')
body=text[text.index('COLOR_INACTIVE'):text.index('# --- uitooltip.py')].rstrip()
body=body.replace('\t# PORT: AVA2 left this German','').replace(
'attrTab.Hide()\t# PORT: switchers stay in the inventory, cell 5 is unused (server port_switchbot.cpp)','attrTab.Show()')
self.assertEqual(body,src)
def load(self,bot,cell=10):
for line in ('MTSB1 attrs %d 11209 3'%cell,'MTSB1 attr 0 3 12','MTSB1 attr 1 63 6','MTSB1 attr 2 71 30','MTSB1 attrs_end %d 3'%cell):bot.Receive(line)
def test_ui_and_locale_parts(self):
self.assertIs(self.mods['ui'].ThinBoardCircle,self.ns['ThinBoardCircle'])
box=self.mods['ui'].ListBoxEx();box.itemList=[1,2];self.assertEqual(box.GetItems(),[1,2])
self.assertEqual(self.mods['localeInfo'].SWITCHBOT_TITLE,'自动洗练')
self.assertEqual(self.mods['constInfo'].USERDATA_DIRECTORY,'')
self.assertEqual(self.ns['ITEM_TAB_WIDTH'],(400-16)/5+1-2) # 5 tabs: cell 5 is hidden, as in AVA2
def test_commands_are_paced_and_attrs_requests_collapse(self):
self.bot.RequestAttrs(10);self.bot.RequestAttrs(11);self.bot.RequestAttrs(12);self.bot.Status()
self.assertEqual(self.sent,['/mt_switchbot 1 attrs 10'])
self.load(self.bot);self.advance()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 attrs 12')
self.bot.Receive('MTSB1 error attrs no_attr');self.advance()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 status')
self.assertEqual(len(self.sent),3)
def test_server_messages(self):
game=self.mods['game'].GameWindow()
for line in ('switchbot_end 2','switchbot_stop noattr 1','switchbot_stop nochanger 0','switchbot_error active',
'switchbot_error invalid','switchbot_end x','quest 3'):
game.BINARY_ServerCommand_Run(line)
self.assertEqual(self.chat,['N11209(第 3 格)洗练完成!','第 2 格的物品没有可洗练的属性,已停止。',
'自动洗练已停止:背包里没有可用的洗练道具。','该格正在洗练,请先停止。','这件物品不能自动洗练。'])
self.assertEqual(self.passed,['quest 3'])
def test_atomic_attr_list_and_rejected_partials(self):
self.load(self.bot)
self.assertEqual(self.bot.allowed[10]['rows'],[(3,12),(63,6),(71,30)])
for bad in (['MTSB1 attrs 11 1 2','MTSB1 attr 0 3 12','MTSB1 attrs_end 11 2'],
['MTSB1 attrs 11 1 1','MTSB1 attr 1 3 12','MTSB1 attrs_end 11 1'],
['MTSB1 attrs 11 1 1','MTSB1 attr 0 3 -1','MTSB1 attrs_end 11 1'],
['MTSB1 attrs_end 11 0']):
for line in bad:self.assertTrue(self.bot.Receive(line))
self.assertNotIn(11,self.bot.allowed)
self.assertFalse(self.bot.Receive('MTF1 cap 1 1 127 0'))
def test_drag_back_to_inventory(self):
self.mouse.AttachObject(None,self.mods['player'].SLOT_TYPE_SWITCHBOT,2,11209,1)
self.assertEqual(self.mouse.AttachedType,33);self.assertEqual(self.icons,[(33,11209,2,1,2)])
self.mods['uiInventory'].InventoryWindow().SelectEmptySlot(4)
self.assertEqual(self.moves,[(7,2,1,49,1)]);self.assertFalse(self.mouse.isAttached());self.assertEqual(self.deleted,[9])
self.mods['uiInventory'].InventoryWindow().SelectEmptySlot(5);self.assertEqual(self.passed,[('empty',5)])
def test_start_validates_against_server_list_and_builds_command(self):
self.load(self.bot)
self.assertEqual(self.bot.Start(10,71084,100,[[(3,13)],[]]),'target')
self.assertEqual(self.bot.Start(10,71084,100,[[(1,1)],[]]),'target')
self.assertEqual(self.bot.Start(10,71084,100,[[(3,1),(3,2)],[]]),'invalid')
self.assertEqual(self.bot.Start(10,71084,1001,[[(3,1)],[]]),'invalid')
self.assertEqual(self.bot.Start(10,71084,100,[[],[]]),'invalid')
self.assertIsNone(self.bot.Start(10,71084,100,[[(3,8),(63,6)],[(71,30)]]))
self.advance()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 start 10 71084 100 2 3 8 63 6 1 71 30')
self.bot.Receive('MTSB1 error start running')
self.assertIsNone(self.bot.Start(10,71084,5,[[],[(71,1)]]));self.advance()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 start 10 71084 5 1 71 1') # empty first alternative skipped
def test_state_errors_and_timeout(self):
self.bot.Receive('MTSB1 state 1 10 11209 3 100 71084 4 running')
self.assertTrue(self.bot.Running());self.assertEqual(self.bot.state['scrolls'],4)
self.bot.Receive('MTSB1 state 0 10 11209 4 100 71084 3 matched')
self.assertFalse(self.bot.Running());self.assertEqual(self.bot.state['reason'],'matched')
self.bot.Receive('MTSB1 state 0 10 11209 4 100 71084 3 exploded')
self.assertEqual(self.bot.state['reason'],'matched') # unknown reason ignored
self.bot.Receive('MTSB1 error start busy');self.assertEqual(self.bot.error,'busy')
self.bot.Status();self.advance(4.1);self.advance()
self.assertEqual(self.bot.error,'unsupported');self.assertTrue(self.bot.unsupported)
def test_server_constants_match(self):
server=ROOT.parent/'metin2-server/src/server/game/src/port_switchbot.h'
if not server.exists():self.skipTest('server checkout not installed')
text=server.read_text(encoding='latin1')
reasons=set(re.findall(r'return "([a-z_]+)"',text))|{'running','stopped','idle'}
errors=set(re.findall(r'error [a-z%]+ ([a-z_]+)"',text))|{'invalid','rate'}
lock_errors={'slot','max','db'}
self.assertTrue(reasons-{'invalid','running','item','equipped','no_attr','scroll','target','busy'}-lock_errors<=set(self.ns['REASONS']))
self.assertTrue(lock_errors<=set(self.ns['ERRORS']))
self.assertTrue(errors<=set(self.ns['ERRORS']))
self.assertIn('kPortSwitchLimit=1000',text);self.assertEqual(max(self.ns['LIMITS']),1000)
self.assertEqual(self.ns['MAX_TARGETS'],5)
def test_lock_protocol_and_buttons(self):
self.bot.Lock(10,0);self.assertEqual(self.sent,[]) # no lock line yet: old server, no request
self.load(self.bot);self.bot.Receive('MTSB1 lock 10 11209 2')
self.assertEqual(self.bot.LockMask(10,11209),2);self.assertIsNone(self.bot.LockMask(10,11210))
self.bot.Lock(10,5);self.bot.Lock(10,0);self.advance()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 lock 10 0')
self.bot.Receive('MTSB1 lock 10 11209 3');self.assertIsNone(self.bot.waiting);self.assertEqual(self.bot.LockMask(10,11209),3)
self.bot.Lock(10,1);self.advance();self.bot.Receive('MTSB1 error lock max');self.assertEqual(self.bot.error,'max')
for bad in ('MTSB1 lock 10 11209','MTSB1 lock 10 11209 32'):self.bot.Receive(bad)
self.assertEqual(self.bot.LockMask(10,11209),3)
# Window: one button per filled slot, hidden while picking, locked attributes marked.
game=sys.modules['game'];gw=game.GameWindow();gw.interface=types.SimpleNamespace(wndMiniMap=Widget())
game.GameWindow.Open(gw);w=self.ns['g_window'];w.Open()
self.assertFalse(any(b.shown for b in w.lockButtons))
self.load(w.bot);w.bot.Receive('MTSB1 lock 10 11209 2')
self.assertEqual([b.shown for b in w.lockButtons],[True,True,False,False,False])
self.assertEqual([b.text for b in w.lockButtons[:2]],['锁1','【锁2】']);self.assertIn('[锁]',w.current.text.split(' / ')[1])
self.assertIn('保持不变',w.status.text)
self.time+=.5;w.OnUpdate();w.bot.Receive('MTSB1 state 0 0 0 0 0 0 0 idle') # answers the status request
sent=len(self.sent);w.lockButtons[0].event();self.time+=.5;w.OnUpdate()
self.assertEqual(self.sent[sent:],['/mt_switchbot 1 lock 10 0'])
w.TogglePick();self.assertFalse(any(b.shown for b in w.lockButtons));w.TogglePick()
w.bot.Receive('MTSB1 state 1 10 11209 0 100 71084 9 running');self.assertFalse(w.lockButtons[0].enabled)
sent=len(self.sent);w.lockButtons[0].event();self.time+=.5;w.OnUpdate()
self.assertNotIn('/mt_switchbot 1 lock 10 0',self.sent[sent:])
game.GameWindow.Close(gw)
def test_window_scan_pick_start_and_notify(self):
game=sys.modules['game'];window_type=game.GameWindow
gw=window_type();gw.interface=types.SimpleNamespace(wndMiniMap=Widget())
game.GameWindow.Open(gw);w=self.ns['g_window'];w.Open()
self.assertEqual(w.items,[(10,11209)]);self.assertEqual(w.scrolls,[(71084,10)])
self.assertEqual(self.sent,['/mt_switchbot 1 attrs 10']) # the status request waits for this reply
self.load(w.bot);self.time+=.5;w.OnUpdate()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 status')
self.assertEqual(game.GameWindow.BINARY_ServerCommand_Run(gw,'MTSB1 state 0 0 0 0 0 0 0 idle'),1)
self.assertEqual(game.GameWindow.BINARY_ServerCommand_Run(gw,'other'),7)
w.TogglePick();w.Pick(0)
self.assertEqual(w.alternatives[0],[[3,12]])
w.Adjust(0,-1);self.assertEqual(w.alternatives[0][0][1],10);w.Adjust(0,1);w.Adjust(0,1);self.assertEqual(w.alternatives[0][0][1],12)
w.Start();self.time+=.5;w.OnUpdate()
self.assertEqual(self.sent[-1],'/mt_switchbot 1 start 10 71084 100 1 3 12')
w.bot.Receive('MTSB1 state 1 10 11209 1 100 71084 9 running');self.assertFalse(w.startButton.enabled)
self.inventory[40]=self.inventory.pop(10);sent=len(self.sent) # moved while running: follow the server's cell
w.bot.Receive('MTSB1 state 1 40 11209 2 100 71084 8 running');w.Scan()
self.assertEqual(w.Selected(),(40,11209));self.assertEqual(w.alternatives[0],[[3,12]])
self.assertEqual(w.Allowed(),[(3,12),(63,6),(71,30)]);self.time+=.5;w.OnUpdate();self.assertEqual(len(self.sent),sent)
w.bot.Receive('MTSB1 state 0 40 11209 2 100 71084 8 stopped')
self.inventory[5]=self.inventory.pop(40);w.Scan();self.assertEqual(w.Selected(),(5,11209)) # moved while idle: same vnum
self.inventory[10]=self.inventory.pop(5);w.Scan()
w.Hide();w.bot.Receive('MTSB1 state 0 10 11209 2 100 71084 8 matched')
self.assertTrue(w.IsShow());self.assertIn('已获得目标属性',self.chat[-1])
game.GameWindow.Close(gw);self.assertIsNone(self.ns['g_window'])
def test_interface_hooks(self):
Interface=self.mods['interfaceModule'].Interface;ui=Interface()
ui.RefreshSwitchbotWindow();ui.ToggleSwitchbotWindow() # no window yet: no-ops
calls=[]
ui.wndSwitchbot=types.SimpleNamespace(shown=True,IsShow=lambda:True,Hide=lambda:calls.append('hide'),
RefreshSwitchbotWindow=lambda:calls.append('refresh'),RefreshSwitchbotItem=lambda s:calls.append(('item',s)),Close=lambda:calls.append('close'))
game=self.mods['game'].GameWindow();game.interface=ui
game.RefreshSwitchbotWindow();game.RefreshSwitchbotItem(3);ui.ToggleSwitchbotWindow()
self.assertEqual(ui._Interface__HideWindows(),[ui.wndSwitchbot]);ui.HideAllWindows()
self.assertEqual(calls,['refresh',('item',3),'close','hide','hide'])
if __name__=='__main__':unittest.main()