27 lines
1.8 KiB
Python
27 lines
1.8 KiB
Python
from pathlib import Path
|
|
import shutil, os, difflib
|
|
artifact=Path(__file__).parent
|
|
for root in (Path('C:/wechat_rpa'), Path('C:/kefu/wechat_rpa')):
|
|
p=root/'wechat_gui_qt.py';s=p.read_text(encoding='utf-8')
|
|
s=s.replace(' event.accept()\n return\n if (not getattr(self, "_exit_requested", False)', ' event.accept()\n return\n app = QApplication.instance()\n if app is not None and app.isSavingSession():\n self._exit_requested = True\n if (not getattr(self, "_exit_requested", False)',1)
|
|
compile(s,str(p),'exec')
|
|
t=p.with_suffix('.tray.tmp');t.write_text(s,encoding='utf-8');os.replace(t,p)
|
|
old=(root/'backups/single-instance-tray-20260917/wechat_gui_qt.py').read_text(encoding='utf-8')
|
|
diffname='production-qt.diff' if root == Path('C:/wechat_rpa') else 'source-qt.diff'
|
|
(artifact/diffname).write_text(''.join(difflib.unified_diff(old.splitlines(True),s.splitlines(True),fromfile='before/wechat_gui_qt.py',tofile=str(p))),encoding='utf-8')
|
|
p=artifact/'test_qt_tray_lifecycle.py';s=p.read_text(encoding='utf-8')
|
|
extra=''' def test_system_logoff_does_not_close_to_tray(self):
|
|
self.window._shutdown_application = mock.Mock()
|
|
with mock.patch.object(QApplication, 'isSavingSession', return_value=True):
|
|
with mock.patch.object(QApplication, 'quit'):
|
|
self.window.close()
|
|
self.assertTrue(self.window._exit_requested)
|
|
self.window._shutdown_application.assert_called_once()
|
|
self.window._ensure_system_tray.assert_not_called()
|
|
|
|
'''
|
|
s=s.replace(' def test_exit_menu_bypasses_close_to_tray(self):',extra+' def test_exit_menu_bypasses_close_to_tray(self):',1)
|
|
p.write_text(s,encoding='utf-8')
|
|
for root in ('C:/wechat_rpa','C:/kefu/wechat_rpa'):
|
|
shutil.copyfile(p,Path(root)/p.name)
|