113 lines
4.5 KiB
Python
113 lines
4.5 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
os.environ.setdefault("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu --no-sandbox")
|
|
os.environ.setdefault("QTWEBENGINE_DISABLE_SANDBOX", "1")
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from PySide6.QtCore import QTimer, QUrl
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
from mdhelper.main_window import MainWindow, ReaderView
|
|
|
|
|
|
def main() -> int:
|
|
project_root = PROJECT_ROOT
|
|
app = QApplication.instance() or QApplication([sys.argv[0]])
|
|
window = MainWindow(project_root=project_root, initial_path=project_root / "sample.md")
|
|
window.show()
|
|
|
|
checks: list[str] = []
|
|
|
|
def verify() -> None:
|
|
window.find_box.setText("斐波那契")
|
|
window.find_next()
|
|
if window.current_file != (project_root / "sample.md").resolve():
|
|
checks.append("current_file")
|
|
if window.tabs.count() < 1:
|
|
checks.append("tabs")
|
|
if not isinstance(window.tabs.currentWidget(), ReaderView):
|
|
checks.append("reader_view")
|
|
if not window.export_pdf_action.isEnabled():
|
|
checks.append("export_pdf_action")
|
|
if not window.export_html_action.isEnabled():
|
|
checks.append("export_html_action")
|
|
if hasattr(window, "theme_action"):
|
|
checks.append("theme_toolbar_action")
|
|
if not hasattr(window, "theme_menu"):
|
|
checks.append("theme_menu")
|
|
if window.search_index.search("斐波那契") == []:
|
|
checks.append("search_index")
|
|
if not window._is_current_page_anchor_url(QUrl("#2-表格示例")):
|
|
checks.append("plain_anchor_url")
|
|
base_anchor = QUrl.fromLocalFile(str((project_root / "sample.md").resolve().parent))
|
|
base_anchor.setFragment("2-表格示例")
|
|
if not window._is_current_page_anchor_url(base_anchor):
|
|
checks.append("base_anchor_url")
|
|
if window._is_current_page_anchor_url(QUrl("mailto:user@example.com#message")):
|
|
checks.append("external_fragment_url")
|
|
window.katex_action.trigger()
|
|
if window.math_engine != "katex":
|
|
checks.append("katex_action")
|
|
window.mathjax_action.trigger()
|
|
if window.math_engine != "mathjax":
|
|
checks.append("mathjax_action")
|
|
snapshot = window._configuration_snapshot()
|
|
if snapshot.get("version") is None:
|
|
checks.append("config_version")
|
|
if "external_applications" not in snapshot:
|
|
checks.append("config_external_applications")
|
|
if snapshot.get("reader", {}).get("theme_background") is None:
|
|
checks.append("config_theme_background")
|
|
window._apply_configuration(
|
|
{
|
|
"reader": {
|
|
"theme_color": "dark_gray",
|
|
"theme_background": "circuit",
|
|
"math_engine": "katex",
|
|
"font_scale": 1.2,
|
|
"document_font_family": "Microsoft YaHei UI",
|
|
"document_font_size": 18,
|
|
"ui_font_family": "Microsoft YaHei UI",
|
|
"ui_font_point_size": 10,
|
|
},
|
|
"recent_files": [str(project_root / "sample.md")],
|
|
"bookmarks": [{"path": str(project_root / "sample.md"), "fragment": "", "label": "sample"}],
|
|
"scroll_positions": {str(project_root / "sample.md"): 42},
|
|
"external_applications": {".mp4": "C:/Tools/player.exe"},
|
|
}
|
|
)
|
|
if window.theme != "dark" or window.theme_color != "dark_gray" or window.math_engine != "katex":
|
|
checks.append("config_apply_reader")
|
|
if window.theme_background != "circuit":
|
|
checks.append("config_apply_theme_background")
|
|
if window.document_font_size != 18 or window.document_font_family != "Microsoft YaHei UI":
|
|
checks.append("config_apply_document_font")
|
|
if window.ui_font_family != "Microsoft YaHei UI" or window.ui_font_point_size != 10:
|
|
checks.append("config_apply_ui_font")
|
|
if ".mp4" not in window.external_applications:
|
|
checks.append("config_apply_external_apps")
|
|
window.close()
|
|
app.quit()
|
|
|
|
QTimer.singleShot(1600, verify)
|
|
app.exec()
|
|
|
|
if checks:
|
|
print("GUI smoke failed:", ", ".join(checks))
|
|
return 1
|
|
|
|
print("GUI smoke ok")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|