onionshare/desktop/tests/conftest.py

45 lines
1.1 KiB
Python
Raw Normal View History

import sys
import os
from datetime import datetime, timedelta
from PySide6 import QtTest
2021-04-30 14:38:23 -04:00
# Force tests to look for resources in the source code tree
sys.onionshare_dev_mode = True
# Let OnionShare know the tests are running, to avoid colliding with settings files
sys.onionshare_test_mode = True
@staticmethod
def qWait(t, qtapp):
end = datetime.now() + timedelta(milliseconds=t)
while datetime.now() < end:
qtapp.processEvents()
# Monkeypatch qWait, although PySide6 has it
# https://stackoverflow.com/questions/17960159/qwait-analogue-in-pyside
QtTest.QTest.qWait = qWait
# Allow importing onionshare_cli from the source tree
sys.path.insert(
0,
os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"cli",
),
)
# Create common and qtapp singletons
from onionshare_cli.common import Common
from onionshare import Application
common = Common(verbose=True)
qtapp = Application(common)
2019-10-13 00:01:25 -04:00
# Attach them to sys, so GuiBaseTest can retrieve them
sys.onionshare_common = common
sys.onionshare_qtapp = qtapp