source: sasview/src/sas/qtgui/UnitTesting/TestUtils.py @ 47471ec

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 47471ec was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[53c771e]1from PyQt5.QtCore import *
2from PyQt5.QtGui import *
3from PyQt5.QtWidgets import *
4from PyQt5.QtTest import *
[db5cd8d]5import inspect
[f721030]6
[db5cd8d]7def WarningTestNotImplemented(method_name=None):
8    """
9    Prints warning about a non-implemented test.
10    Test name retrieved from stack trace.
11    """
12    if method_name is not None:
[7fb471d]13        print(("\nWARNING: %s needs implementing!"%method_name))
[db5cd8d]14    else:
[092a3d9]15        (frame, filename, line_number,
[db5cd8d]16            function_name, lines, index) = inspect.getouterframes(inspect.currentframe())[1]
[7fb471d]17        print(("\nWARNING: %s needs implementing!"%function_name))
[87cc73a]18
[f721030]19class QtSignalSpy(QObject):
20    """
21    Helper class for testing Qt signals.
22    """
23    def __init__(self, widget, signal, parent=None):
24        """
25        """
26        super(QtSignalSpy, self).__init__(parent)
27
[488c49d]28        self._recorder = {}
[f721030]29        self._count = 0
[488c49d]30        self._signal = []
[f721030]31
32        # Assign our own slot to the emitted signal
[5032ea68]33        try:
34            if isinstance(signal, pyqtBoundSignal):
35                signal.connect(self.slot)
36            elif hasattr(widget, signal):
37                getattr(widget, signal).connect(self.slot)
38            else:
39                widget.signal.connect(slot)
[488c49d]40        except AttributeError:
41            msg = "Wrong construction of QtSignalSpy instance"
[7fb471d]42            raise RuntimeError(msg)
[f721030]43
44    def slot(self, *args, **kwargs):
45        """
46        Record emitted signal.
47        """
[488c49d]48        self._recorder[self._count] = {
[f721030]49            'args'   : args,
50            'kwargs' : kwargs,
51            }
52
53        self._count += 1
54        self._signal = [args, kwargs]
55
56    def signal(self, index=None):
[cee5c78]57        if index is None:
[f721030]58            return self._signal
59        else:
60            return self._signal[index]
61
62    def count(self):
63        return self._count
64
65    def called(self):
[488c49d]66        return self._recorder
Note: See TracBrowser for help on using the repository browser.