48 lines
2.3 KiB
Python
48 lines
2.3 KiB
Python
from pathlib import Path
|
|
import shutil
|
|
p=Path(__file__).parent/'test_qt_tray_lifecycle.py'
|
|
s=p.read_text(encoding='utf-8')
|
|
addition=''' def test_taskbar_native_restore_clears_fallback_mode(self):
|
|
self.window._ensure_system_tray.return_value = False
|
|
self.window.close()
|
|
self.window.showNormal()
|
|
self.assertFalse(self.window._close_minimized)
|
|
|
|
def test_no_tray_fallback_restores_capsule_hidden_surfaces(self):
|
|
self.window.console_shell = QWidget(self.window)
|
|
self.window.console_shell.show()
|
|
self.window.enter_capsule_mode()
|
|
self.window._ensure_system_tray.return_value = False
|
|
self.window.close()
|
|
self.assertTrue(self.window.isMinimized())
|
|
self.assertFalse(self.window.console_shell.isHidden())
|
|
|
|
def test_about_to_quit_is_wired_to_cleanup(self):
|
|
self.window._shutdown_application = mock.Mock()
|
|
with mock.patch.object(sys, 'argv', ['test', '--qt-smoke-test']):
|
|
self.window._initialize_system_tray()
|
|
try:
|
|
self.app.aboutToQuit.emit()
|
|
self.window._shutdown_application.assert_called_once()
|
|
finally:
|
|
self.app.aboutToQuit.disconnect(self.window._shutdown_application)
|
|
self.app.removeEventFilter(self.window._quit_filter)
|
|
self.window._quit_filter.deleteLater()
|
|
|
|
'''
|
|
s=s.replace(' def test_explicit_disable_close_to_tray_quits(self):',addition+' def test_explicit_disable_close_to_tray_quits(self):',1)
|
|
addition=''' def test_guard_constructor_failure_is_reported_without_login(self):
|
|
constructor = mock.Mock(side_effect=OSError('mock token unavailable'))
|
|
with mock.patch.dict(sys.modules, {'desktop_instance': SimpleNamespace(DesktopInstanceGuard=constructor)}):
|
|
with mock.patch.object(sys, 'argv', ['wechat_gui.py']), mock.patch.object(qt, '_run_desktop_session') as session:
|
|
with mock.patch.object(qt.QMessageBox, 'critical') as error:
|
|
qt.main()
|
|
error.assert_called_once()
|
|
session.assert_not_called()
|
|
|
|
'''
|
|
s=s.replace(' def test_session_exception_releases_guard(self):',addition+' def test_session_exception_releases_guard(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)
|