Add quit function and code fixes
This commit is contained in:
parent
6b0ce5d1ae
commit
ea2e11ced8
|
@ -1,3 +1,4 @@
|
|||
"""Generate Address for tests"""
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
||||
|
@ -83,6 +84,7 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase):
|
|||
QTest.qWait(100)
|
||||
print(
|
||||
"\n Test Fail :--> Address Generatation Failed with passphrase"
|
||||
" or Taking too much time to generate address \n")
|
||||
" or Taking too much time to generate address \n"
|
||||
)
|
||||
self.assertTrue(False, " \n Test Fail :--> Address Generatation Failed with passphrase")
|
||||
return 0
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Add address in the subscription list"""
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
||||
|
@ -12,6 +13,8 @@ from testloader import BitmessageTestCase
|
|||
|
||||
|
||||
class BitmessageTest_AddSubscription(BitmessageTestCase):
|
||||
"""Add address to list"""
|
||||
|
||||
def test_subscription(self):
|
||||
"""Test for subscription functionality"""
|
||||
QTest.qWait(500)
|
||||
|
@ -46,7 +49,8 @@ class BitmessageTest_AddSubscription(BitmessageTestCase):
|
|||
if shared.isAddressInMySubscriptionsList(address):
|
||||
print(
|
||||
"\n Test Fail :--> You cannot add the same address to your subscriptions twice."
|
||||
" Perhaps rename the existing one if you want. \n")
|
||||
" Perhaps rename the existing one if you want. \n"
|
||||
)
|
||||
QTest.qWait(500)
|
||||
return 0
|
||||
self.myapp.addSubscription(address, label)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Trigger dialog"""
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from PyQt4.QtTest import QTest
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Tests for blackwhitelist"""
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
||||
|
@ -39,6 +40,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase):
|
|||
pass
|
||||
|
||||
def checkblacklist(self, myapp):
|
||||
"""fill blacklist and whitelist fields"""
|
||||
# pylint: disable=too-many-statements
|
||||
QTest.qWait(1000)
|
||||
self.dialog.lineEditLabel.setText("")
|
||||
|
@ -96,10 +98,13 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase):
|
|||
QTest.qWait(100)
|
||||
print(
|
||||
"\n Test Fail :--> You cannot add the same address to your list twice."
|
||||
" Perhaps rename the existing one if you want. \n")
|
||||
" Perhaps rename the existing one if you want. \n"
|
||||
)
|
||||
self.assertTrue(
|
||||
False, "\n Test Fail :--> You cannot add the same address to your list twice."
|
||||
" Perhaps rename the existing one if you want.")
|
||||
False,
|
||||
"\n Test Fail :--> You cannot add the same address to your list twice."
|
||||
" Perhaps rename the existing one if you want.",
|
||||
)
|
||||
return 0
|
||||
else:
|
||||
QTest.qWait(100)
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
"""Tests for changs Tab"""
|
||||
from PyQt4.QtTest import QTest
|
||||
|
||||
from testloader import BitmessageTestCase
|
||||
|
||||
|
||||
class BitmessageTest_ChansTest(BitmessageTestCase):
|
||||
"""Switch to chans and test"""
|
||||
|
||||
def test_chans(self):
|
||||
"""Switch to chans window and test"""
|
||||
QTest.qWait(1200)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Test for message send"""
|
||||
import random
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
@ -23,7 +24,7 @@ class BitmessageTest_MessageTesting(BitmessageTestCase):
|
|||
self.myapp.ui.comboBoxSendFrom.setCurrentIndex(
|
||||
random.randrange(1, len(BMConfigParser().addresses()) + 1)
|
||||
)
|
||||
QTest.qWait(800)
|
||||
QTest.qWait(1000)
|
||||
rand_address = choice(BMConfigParser().addresses())
|
||||
random_address = ""
|
||||
for x in range(len(rand_address)):
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
"""Test for network window"""
|
||||
from PyQt4.QtTest import QTest
|
||||
|
||||
from testloader import BitmessageTestCase
|
||||
|
||||
|
||||
class BitmessageTest_NetworkTest(BitmessageTestCase):
|
||||
"""Switch to network tab and test"""
|
||||
|
||||
def test_network(self):
|
||||
"""Switch to network window and test"""
|
||||
"""Switch to network window"""
|
||||
QTest.qWait(1000)
|
||||
self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus)
|
||||
QTest.qWait(1200)
|
||||
|
|
101
src/graphicaltesting/test_quit.py
Normal file
101
src/graphicaltesting/test_quit.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
"""Quits the application"""
|
||||
import time
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
import bitmessageqt.sound
|
||||
import shared
|
||||
import shutdown
|
||||
from bitmessageqt import settingsmixin
|
||||
from bmconfigparser import BMConfigParser
|
||||
from debug import logger
|
||||
from network.stats import pendingDownload, pendingUpload
|
||||
from proofofwork import getPowType
|
||||
from testloader import BitmessageTestCase
|
||||
from tr import _translate
|
||||
|
||||
|
||||
class BitmessageTest_QuitTest(BitmessageTestCase):
|
||||
"""Quit the bitmessage qt application"""
|
||||
|
||||
def test_quitapplication(self):
|
||||
"""wait for pow and shutdown the application"""
|
||||
if self.myapp.quitAccepted and not self.myapp.wait:
|
||||
return
|
||||
|
||||
self.myapp.show()
|
||||
self.myapp.raise_()
|
||||
self.myapp.activateWindow()
|
||||
|
||||
waitForPow = True
|
||||
waitForConnection = False
|
||||
waitForSync = False
|
||||
if getPowType() == "python" and (bitmessageqt.powQueueSize() > 0 or pendingUpload() > 0):
|
||||
waitForPow = False
|
||||
if pendingDownload() > 0:
|
||||
self.myapp.wait = waitForSync = True
|
||||
if shared.statusIconColor == "red" and not BMConfigParser().safeGetBoolean(
|
||||
"bitmessagesettings", "dontconnect"
|
||||
):
|
||||
waitForConnection = True
|
||||
self.myapp.wait = waitForSync = True
|
||||
self.myapp.quitAccepted = True
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down PyBitmessage... %1%").arg(0))
|
||||
if waitForConnection:
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for network connection..."))
|
||||
while shared.statusIconColor == "red":
|
||||
time.sleep(0.5)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
if waitForSync:
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for finishing synchronisation..."))
|
||||
while pendingDownload() > 0:
|
||||
time.sleep(0.5)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
if waitForPow:
|
||||
maxWorkerQueue = 0
|
||||
curWorkerQueue = bitmessageqt.powQueueSize()
|
||||
while curWorkerQueue > 0:
|
||||
curWorkerQueue = bitmessageqt.powQueueSize()
|
||||
if curWorkerQueue > maxWorkerQueue:
|
||||
maxWorkerQueue = curWorkerQueue
|
||||
if curWorkerQueue > 0:
|
||||
self.myapp.updateStatusBar(
|
||||
_translate("MainWindow", "Waiting for PoW to finish... %1%").arg(
|
||||
50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue
|
||||
)
|
||||
)
|
||||
time.sleep(0.5)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down Pybitmessage... %1%").arg(50))
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
if maxWorkerQueue > 0:
|
||||
time.sleep(0.5)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for objects to be sent... %1%").arg(50))
|
||||
maxPendingUpload = max(1, pendingUpload())
|
||||
while pendingUpload() > 1:
|
||||
self.myapp.updateStatusBar(
|
||||
_translate("MainWindow", "Waiting for objects to be sent... %1%").arg(
|
||||
int(50 + 20 * (pendingUpload() / maxPendingUpload))
|
||||
)
|
||||
)
|
||||
time.sleep(0.5)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Saving settings... %1%").arg(70))
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
self.myapp.saveSettings()
|
||||
for attr, obj in self.myapp.ui.__dict__.iteritems():
|
||||
if hasattr(obj, "__class__") and isinstance(obj, settingsmixin.SettingsMixin):
|
||||
saveMethod = getattr(obj, "saveSettings", None)
|
||||
if callable(saveMethod):
|
||||
obj.saveSettings()
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down core... %1%").arg(80))
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000)
|
||||
shutdown.doCleanShutdown()
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Stopping notifications... %1%").arg(90))
|
||||
self.myapp.tray.hide()
|
||||
self.myapp.updateStatusBar(_translate("MainWindow", "Shutdown imminent... %1%").arg(100))
|
||||
logger.info("Shutdown complete")
|
||||
QtGui.qApp.closeAllWindows()
|
|
@ -1,3 +1,4 @@
|
|||
"""Tests for setting window"""
|
||||
import random
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
@ -11,6 +12,8 @@ from testloader import BitmessageTestCase
|
|||
|
||||
|
||||
class BitmessageTest_SettingWindowTest(BitmessageTestCase):
|
||||
"""Switch to setting tab and test"""
|
||||
|
||||
def test_settingwindow(self):
|
||||
"""Triggers the setting window"""
|
||||
self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox)
|
||||
|
@ -56,7 +59,7 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase):
|
|||
dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}")
|
||||
QTest.qWait(50)
|
||||
dialog.languageComboBox.setStyleSheet("")
|
||||
dialog.languageComboBox.setCurrentIndex(6)
|
||||
dialog.languageComboBox.setCurrentIndex(5)
|
||||
QTest.qWait(1000)
|
||||
ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok)
|
||||
QTest.mouseClick(ok_btn, Qt.LeftButton)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Trigger Test"""
|
||||
import unittest
|
||||
|
||||
import test_addressgeneration
|
||||
|
@ -7,24 +8,29 @@ import test_chans
|
|||
import test_messagesend
|
||||
import test_networkstatus
|
||||
import test_settingwindow
|
||||
import test_quit
|
||||
from testloader import BitmessageTestCase
|
||||
|
||||
|
||||
def test_initialize(myapp):
|
||||
"""Test Loader"""
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_messagesend.BitmessageTest_MessageTesting, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_chans.BitmessageTest_ChansTest, myapp=myapp))
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(
|
||||
test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp))
|
||||
suite.addTest(
|
||||
BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)
|
||||
)
|
||||
suite.addTest(
|
||||
BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)
|
||||
)
|
||||
suite.addTest(
|
||||
BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)
|
||||
)
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp))
|
||||
suite.addTest(
|
||||
BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)
|
||||
)
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(test_chans.BitmessageTest_ChansTest, myapp=myapp))
|
||||
suite.addTest(
|
||||
BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)
|
||||
)
|
||||
suite.addTest(BitmessageTestCase.bitmessage_testloader(test_quit.BitmessageTest_QuitTest, myapp=myapp))
|
||||
unittest.TextTestRunner().run(suite)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Load Test"""
|
||||
import unittest
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import state
|
||||
import os
|
||||
import shutil
|
||||
|
||||
if __name__ == "__main__":
|
||||
APPNAME = "PyBitmessage"
|
||||
if os.path.isdir(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))):
|
||||
shutil.rmtree(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/")))
|
||||
else:
|
||||
pass
|
||||
import state
|
||||
state.qttesting = True
|
||||
print(" --------------------------------- Graphical Qt Testing --------------------------------- ")
|
||||
from bitmessagemain import main
|
||||
|
|
Loading…
Reference in New Issue
Block a user