fix: preserve legacy cleanup document and tip transitions

This commit is contained in:
阿白叔 committed 2026-11-17 10:34:50 +08:00
1 parent 7eafae417d
commit 701e5cd3b4
2 files changed
+66 -5

No files matched your search

+56
View File
@@ -226,3 +226,59 @@ def test_registered_cleanup_preserves_frame_with_an_additional_mdi_document(tmp_
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',windows)
assert sessions._request_close(row)['release_status']=='WAITING'
assert records and not messages
@pytest.mark.parametrize('hidden_sibling',[None,False,True])
def test_real_legacy_adapter_keeps_hidden_documents_before_any_native_action(tmp_path,monkeypatch,hidden_sibling):
import win32con,win32gui,win32process
snapshot,adapter=sessions._process_windows,sessions._legacy_diagnostic_windows
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch)
monkeypatch.setattr(sessions,'_process_windows',snapshot)
monkeypatch.setattr(sessions,'_legacy_diagnostic_windows',adapter)
monkeypatch.setattr(sessions,'_process_threads',lambda pids:{12:[1]})
monkeypatch.setattr(sessions,'_thread_desktop_name',lambda tid:job['desktop'])
monkeypatch.setattr(sessions,'_desktop_windows',lambda desktop:[100,200] if not state['declined'] else [100])
classes={100:'Afx:main',101:'MDIClient',102:'Afx:document',103:'Afx:document',
200:'#32770',30:'Static',31:'Button',32:'Button'}
texts={100:'Expedition PCB - Reusable Block - [IP101GR]',101:'',102:'IP101GR',103:'Other',
200:'Expedition PCB',30:'New changes are ready for Forward Annotation. Do you want to Forward Annotate now?',31:'&No',32:'&Yes'}
parents={101:100,102:101,103:101,30:200,31:200,32:200}
monkeypatch.setattr(win32process,'GetWindowThreadProcessId',lambda h:(1,12))
monkeypatch.setattr(win32gui,'GetClassName',lambda h:classes[h])
monkeypatch.setattr(win32gui,'GetWindowText',lambda h:texts[h])
monkeypatch.setattr(win32gui,'GetParent',lambda h:parents.get(h,0))
monkeypatch.setattr(win32gui,'GetDlgCtrlID',lambda h:{30:6172,31:7,32:6}.get(h,0))
monkeypatch.setattr(win32gui,'GetWindowRect',lambda h:(0,0,300,200))
monkeypatch.setattr(win32gui,'IsWindowVisible',lambda h:not (h==103 and hidden_sibling))
monkeypatch.setattr(win32gui,'IsWindowEnabled',lambda h:h!=100 or state['declined'])
monkeypatch.setattr(win32gui,'GetWindow',lambda h,k:102 if h==101 and k==win32con.GW_CHILD else 100 if h==200 and k==win32con.GW_OWNER else 0)
monkeypatch.setattr(win32gui,'EnumChildWindows',lambda h,fn,arg:[fn(c,arg) for c in ([101,102]+([103] if hidden_sibling is not None else []) if h==100 else [30,31,32])])
result=sessions._request_close(row)
if hidden_sibling is None:
assert result['release_status']=='RELEASED',result
assert not records and messages==[(31,245),(100,16)]
else:
assert result['release_status']=='WAITING',result
assert records and not messages
@pytest.mark.parametrize('closed',[False,True])
def test_legacy_tip_continues_to_loaded_cleanup_only_without_prior_close(tmp_path,monkeypatch,closed):
import win32con,win32gui
from copy import deepcopy
job,row,records,messages,state=registered_fixture(tmp_path,monkeypatch,closed=closed)
state['tip']=True
tip_windows=[dict(hwnd=100,**{'class':'Afx:main'},title='Expedition PCB',enabled=False,
desktop=job['desktop'],children=[],documents=[]),
dict(hwnd=200,**{'class':'#32770'},title='Tip of the Day',enabled=True,
desktop=job['desktop'],documents=[],children=[dict(hwnd=201,**{'class':'Button'},id=1,text='OK',enabled=True)])]
monkeypatch.setattr(sessions,'_process_windows',lambda pids:{12:deepcopy(tip_windows) if state['tip'] else []})
monkeypatch.setattr(win32gui,'GetWindow',lambda h,k:100 if h==200 and k==win32con.GW_OWNER else 0)
original=win32gui.PostMessage
def post(hwnd,message,*args):
original(hwnd,message,*args)
if closed and hwnd==201:records.clear()
monkeypatch.setattr(win32gui,'PostMessage',post)
assert sessions._request_close(row)['release_status']=='RELEASED'
assert messages==([(201,245)] if closed else [(201,245),(31,245),(100,16)])
assert not records and state['ticks']<30