Skip to content

Commit

Permalink
Try fix flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ownbee committed Jan 18, 2023
1 parent 3fbc74f commit 7e6e02e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions doorstop_edit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
doorstop.Item.auto = False # Disable automatic save.


def show_splash_screen() -> QSplashScreen:
def show_splash_screen(app: QApplication) -> QSplashScreen:
pixmap = QIcon(":/icons/favicon").pixmap(QSize(400, 400))
splash = QSplashScreen(pixmap)
splash.showMessage(
"Loading doorstop tree...", Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignBottom, Qt.GlobalColor.white
)
splash.show()
QApplication.processEvents()
app.processEvents()
return splash


Expand Down Expand Up @@ -94,8 +94,6 @@ def setup(app: QApplication, argv: List[str]) -> Optional[DoorstopEdit]:
logger.error("Invalid argument: '%s' is not a directory.", root_directory)
return None

splash = show_splash_screen()

# Add custom font
QFontDatabase.addApplicationFont(":/font/DroidSansMono.ttf")

Expand All @@ -105,19 +103,21 @@ def setup(app: QApplication, argv: List[str]) -> Optional[DoorstopEdit]:
web_engine_context_log = QLoggingCategory("qt.webenginecontext") # type: ignore
web_engine_context_log.setFilterRules("*.info=false")

app.processEvents() # Make sure splash screen shows.

editor = DoorstopEdit(root_directory)
splash.finish(editor.window)
return editor


def main() -> int:
# As minimalistic as possible since it wont be tested.
app = QApplication([])

splash = show_splash_screen(app)
editor = setup(app, sys.argv)
app.aboutToQuit.connect(editor.quit) # type: ignore
if editor is not None:
editor.show()
splash.finish(editor.window)
return app.exec()

return 0
5 changes: 4 additions & 1 deletion doorstop_edit/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

from PySide6.QtWidgets import QApplication
from pytestqt.qtbot import QtBot

from doorstop_edit.application import DoorstopEdit
from doorstop_edit.main import setup as main_setup
Expand All @@ -21,10 +22,12 @@ def setup_ctx(*args: Any, **kwds: Any) -> Iterator[Optional[DoorstopEdit]]:
app.quit()


def test_start_no_exceptions(qapp: QApplication) -> None:
def test_start_no_exceptions(qtbot: QtBot, qapp: QApplication) -> None:
qapp.sync()
time.sleep(1) # QApplication need some time between tests in this file (unclear why).
with setup_ctx(qapp, ["name"]) as app:
assert app is not None
qtbot.add_widget(app.window)


def test_arg_version(qapp: QApplication) -> None:
Expand Down

0 comments on commit 7e6e02e

Please sign in to comment.