fix: restore the main window geometry across sessions
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m28s
Core regression / JavaScript syntax (push) Successful in 6s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m27s
Core regression / JavaScript syntax (pull_request) Successful in 9s
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m28s
Core regression / JavaScript syntax (push) Successful in 6s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m27s
Core regression / JavaScript syntax (pull_request) Successful in 9s
This commit is contained in:
1 parent
46deb9cec8
commit
650dfd5491
3 files changed
+142
-1
No files matched your search
@@ -0,0 +1,89 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QByteArray
|
||||
|
||||
from test_ui_remediation import window
|
||||
|
||||
|
||||
_GEOMETRY = 'main_window/geometry'
|
||||
|
||||
|
||||
def test_geometry_persists_across_application_processes(tmp_path):
|
||||
source = Path(__file__).resolve().parents[2] / 'src'
|
||||
env = os.environ | {'PYTHONPATH': str(source)}
|
||||
script = """
|
||||
import json
|
||||
import sys
|
||||
from PySide6.QtCore import QTimer
|
||||
from dx_productivity.trial_task_center import application
|
||||
|
||||
mode, root = sys.argv[1:]
|
||||
window_type = application._load_window()
|
||||
|
||||
def open_window(service):
|
||||
window = window_type(service)
|
||||
|
||||
def capture():
|
||||
normal = window.normalGeometry()
|
||||
area = window.screen().availableGeometry()
|
||||
print(json.dumps({'normal': normal.getRect(), 'maximized': window.isMaximized(),
|
||||
'reachable': area.contains(normal.topLeft()), 'fits': area.contains(normal)}),
|
||||
flush=True)
|
||||
window.close()
|
||||
|
||||
def arrange():
|
||||
if mode == 'save':
|
||||
window.setGeometry(45, 55, 1200, 760)
|
||||
window.showMaximized()
|
||||
QTimer.singleShot(200, capture)
|
||||
|
||||
QTimer.singleShot(0, arrange)
|
||||
return window
|
||||
|
||||
application._load_window = lambda: open_window
|
||||
raise SystemExit(application.main(['--data-root', root]))
|
||||
"""
|
||||
env.setdefault('QT_QPA_PLATFORM', 'offscreen')
|
||||
|
||||
def launch(mode, **overrides):
|
||||
result = subprocess.run([sys.executable, '-c', script, mode, str(tmp_path)], env=env | overrides,
|
||||
timeout=90, capture_output=True, text=True)
|
||||
assert result.returncode == 0, result.stderr
|
||||
return json.loads(result.stdout)
|
||||
|
||||
saved = launch('save')
|
||||
reopened = launch('restore')
|
||||
rescaled = launch('restore', QT_SCALE_FACTOR='1.5')
|
||||
print(f'window geometry saved={saved}, reopened={reopened}')
|
||||
print(f'window geometry at changed DPI={rescaled}')
|
||||
assert saved['maximized'] and reopened['maximized']
|
||||
assert saved['normal'][2:] == [1200, 760]
|
||||
assert reopened['reachable'] and rescaled['reachable']
|
||||
if saved['fits']:
|
||||
assert reopened['normal'] == saved['normal']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('saved', ['broken', QByteArray(b'bad'), 'offscreen'])
|
||||
def test_invalid_or_offscreen_settings_leave_window_visible(window, qtbot, saved):
|
||||
if saved == 'offscreen':
|
||||
window.setGeometry(50000, 50000, 1200, 760)
|
||||
saved = window.saveGeometry()
|
||||
window._layout_settings.setValue(_GEOMETRY, saved)
|
||||
window._layout_settings.sync()
|
||||
|
||||
reopened = type(window)(window.service)
|
||||
qtbot.addWidget(reopened)
|
||||
try:
|
||||
reopened.show()
|
||||
rect = reopened.geometry()
|
||||
area = reopened.screen().availableGeometry()
|
||||
assert area.contains(rect.topLeft())
|
||||
assert rect.intersects(area)
|
||||
assert not reopened.isMaximized()
|
||||
finally:
|
||||
reopened.close()
|
||||
Reference in new issue
Block a user