source: sasview/src/sas/qtgui/UnitTesting/TestUtils.py @ 7fb471d

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 7fb471d was 7fb471d, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Update for unit tests and minor functionality quirks

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