Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui testing - pairing session #542

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gridsync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from gridsync.core import Core
from gridsync.errors import FilesystemLockError

# qtreactor must be 'installed' after initializing QApplication but
# before running/importing any other Twisted code.
# See https://github.com/twisted/qt5reactor/blob/master/README.rst
from gridsync import qtreactor # pylint: disable=ungrouped-imports

class TahoeVersion(argparse.Action):
def __call__(
Expand Down Expand Up @@ -52,4 +56,6 @@ def main() -> Union[int, str]:


if __name__ == "__main__":
# Ignore mypy error 'Module has no attribute "install"'
qtreactor.install() # type: ignore
sys.exit(main())
18 changes: 10 additions & 8 deletions gridsync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
except AttributeError: # Not available in Qt6
pass

app = QApplication(sys.argv)

# qtreactor must be 'installed' after initializing QApplication but
# before running/importing any other Twisted code.
# See https://github.com/twisted/qt5reactor/blob/master/README.rst
from gridsync import qtreactor # pylint: disable=ungrouped-imports
# from gridsync import qtreactor # pylint: disable=ungrouped-imports

# Ignore mypy error 'Module has no attribute "install"'
qtreactor.install() # type: ignore
# qtreactor.install() # type: ignore

# pylint: disable=wrong-import-order
from twisted.internet import reactor
Expand All @@ -79,8 +78,6 @@
from gridsync.tor import get_tor
from gridsync.types import TwistedDeferred

app.setWindowIcon(QIcon(resource(settings["application"]["tray_icon"])))


class DequeHandler(logging.Handler):
def __init__(self, deque: collections.deque) -> None:
Expand Down Expand Up @@ -184,6 +181,7 @@ def _get_executable_versions(self) -> TwistedDeferred[None]:

@inlineCallbacks
def start_gateways(self) -> TwistedDeferred[None]:
print ("hey look at me")
nodedirs = get_nodedirs(config_dir)
if nodedirs:
minimize_preference = get_preference("startup", "minimize")
Expand Down Expand Up @@ -272,16 +270,20 @@ def start(self) -> None:
)
lock.acquire()

reactor.run() # type: ignore
lock.release()

def start_async(self, reactor) -> None:
logging.debug("Core starting with args: %s", self.args)
logging.debug("Loaded config.txt settings: %s", settings)

reactor.qApp.setWindowIcon(QIcon(resource(settings["application"]["tray_icon"])))

self.show_message()

self.gui.show_systray()

reactor.callLater(0, self.start_gateways) # type: ignore
reactor.addSystemEventTrigger( # type: ignore
"before", "shutdown", self.stop_gateways
)
reactor.run() # type: ignore
lock.release()
)
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ async def tahoe_client(tmp_path_factory, tahoe_server):
def reactor():
return Mock()

@pytest.fixture()
def qt_reactor():
from twisted.internet import reactor
from qt5reactor import QtReactor
assert isinstance(reactor, QtReactor)
return reactor

# def pytest_configure(config):
# import pytest_twisted
# import gridsync.qtreactor
# pytest_twisted.reactor_installers["gridsync-qtreactor"] = gridsync.qtreactor.install

def _tahoe(tmpdir_factory, reactor):
client = Tahoe(
Expand Down
67 changes: 67 additions & 0 deletions tests/gui/test_charter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-

from socket import timeout
from time import sleep

from unittest.mock import MagicMock

import pytest
# from qtpy.QtWidgets import QApplication
from twisted.python.filepath import FilePath

from qtpy.QtCore import Qt

from gridsync.core import Core


from gridsync.gui import Gui

from argparse import Namespace


def _test_basics(qtbot):
"""
Basic test that works more like a sanity check to ensure we are setting up a QApplication
properly and are able to display a simple event_recorder.
"""
from pytestqt.qt_compat import qt_api
assert qt_api.QtWidgets.QApplication.instance() is not None
widget = qt_api.QtWidgets.QWidget()
qtbot.addWidget(widget)
widget.setWindowTitle("W1")
widget.show()

assert widget.isVisible()
assert widget.windowTitle() == "W1"


def _test_with_common_gui_addressing(qtbot):
gui = Gui(MagicMock()) ## TBD: Do not use mocks
window = gui.main_window
window.show()
qtbot.waitExposed(window)
#qtbot.mouseClick(window.toolbar.combo_box, Qt.MouseButton.LeftButton)
# window.toolbar.combo_box.setCurrentIndex(1)
# window.toolbar.export_action_triggered.emit() # XXX: meh, we want to click instead of emitting signals.
# qtbot.wait(9000) # milliseconds, just so we can click around in the window a bit


def _test_recover_from_key(qtbot):
gui = Gui(MagicMock()) # TBD: Do not use mocks
gui.main_window.show_welcome_dialog()
wd = gui.main_window.welcome_dialog
qtbot.addWidget(wd)
qtbot.mouseClick(wd.restore_link, Qt.MouseButton.LeftButton)

### XXX How to type some text into the file chooser dialoge
### without changing the gridsync source code?

qtbot.wait(9000) # milliseconds, just so we can click around in the window a bit



def test_start_welcomescreen(qtbot, qt_reactor):
core = Core(Namespace(debug = False))
assert core.gui.welcome_dialog is not None
with qtbot.waitActive(core.gui.welcome_dialog):
core.start_async(qt_reactor)
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ deps =
-r{toxinidir}/requirements/{env:QT_API:pyqt5}.txt
-r{toxinidir}/requirements/test.txt
commands =
{envpython} -m pytest {posargs}
{envpython} -m pip install qt5reactor
{envpython} -m pytest --reactor qt5reactor {posargs}
passenv = *


Expand Down