1 | from PyQt5.QtCore import * |
---|
2 | from PyQt5.QtGui import * |
---|
3 | from PyQt5.QtWidgets import * |
---|
4 | from PyQt5.QtTest import * |
---|
5 | import inspect |
---|
6 | |
---|
7 | def 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: |
---|
13 | print(("\nWARNING: %s needs implementing!"%method_name)) |
---|
14 | else: |
---|
15 | (frame, filename, line_number, |
---|
16 | function_name, lines, index) = inspect.getouterframes(inspect.currentframe())[1] |
---|
17 | print(("\nWARNING: %s needs implementing!"%function_name)) |
---|
18 | |
---|
19 | class 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 | |
---|
28 | self._recorder = {} |
---|
29 | self._count = 0 |
---|
30 | self._signal = [] |
---|
31 | |
---|
32 | # Assign our own slot to the emitted signal |
---|
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) |
---|
40 | except AttributeError: |
---|
41 | msg = "Wrong construction of QtSignalSpy instance" |
---|
42 | raise RuntimeError(msg) |
---|
43 | |
---|
44 | def slot(self, *args, **kwargs): |
---|
45 | """ |
---|
46 | Record emitted signal. |
---|
47 | """ |
---|
48 | self._recorder[self._count] = { |
---|
49 | 'args' : args, |
---|
50 | 'kwargs' : kwargs, |
---|
51 | } |
---|
52 | |
---|
53 | self._count += 1 |
---|
54 | self._signal = [args, kwargs] |
---|
55 | |
---|
56 | def signal(self, index=None): |
---|
57 | if index is None: |
---|
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): |
---|
66 | return self._recorder |
---|