From f738769d34268866dec391c65dffe7832e7bd16a Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 20 Feb 2021 23:38:45 +0200 Subject: [PATCH] Add TestBase.take_screenshot(window=None) in bitmessageqt.tests: it shows specified window (or the main window), execs the app and saves screenshot in png file in the appdata with full test name in the file name. Used it in TestUISignaler.test_updateStatusBar and TestSupport. --- src/bitmessageqt/tests/main.py | 21 ++++++++++++++++++--- src/bitmessageqt/tests/support.py | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/tests/main.py b/src/bitmessageqt/tests/main.py index b3aa67fa..cbe809f3 100644 --- a/src/bitmessageqt/tests/main.py +++ b/src/bitmessageqt/tests/main.py @@ -2,6 +2,7 @@ import Queue import sys +import os import unittest from PyQt4 import QtCore, QtGui @@ -23,6 +24,22 @@ class TestBase(unittest.TestCase): self.window = bitmessageqt.MyForm() self.window.appIndicatorInit(self.app) + def take_screenshot(self, window=None): + """Take a screenshot of the *window* or main window if not set""" + def save_screenshot(): + """Save screenshot and quit app clause""" + screenshot = QtGui.QPixmap.grabWindow( + self.app.desktop().winId()) + screenshot.save(os.path.join( + bitmessageqt.state.appdata, '%s.png' % self.id())) + self.app.quit() + + timer = QtCore.QTimer() + timer.timeout.connect(save_screenshot) + timer.start(200) + (window or self.window).show() + self.app.exec_() + def tearDown(self): # self.app.deleteLater() while True: @@ -55,6 +72,4 @@ class TestUISignaler(TestBase): _translate("test", "Testing updateStatusBar..."), 1) )) - QtCore.QTimer.singleShot(60, self.app.quit) - self.app.exec_() - # self.app.processEvents(QtCore.QEventLoop.AllEvents, 60) + self.take_screenshot() diff --git a/src/bitmessageqt/tests/support.py b/src/bitmessageqt/tests/support.py index ba28b73a..fcce6a4c 100644 --- a/src/bitmessageqt/tests/support.py +++ b/src/bitmessageqt/tests/support.py @@ -31,3 +31,5 @@ class TestSupport(TestBase): ui.lineEditSubject.text(), self.SUPPORT_SUBJECT) self.assertIn( sys.version, ui.textEditMessage.toPlainText()) + + self.take_screenshot()