[f721030] | 1 | from PyQt4.QtCore import * |
---|
| 2 | from PyQt4.QtGui import * |
---|
| 3 | from PyQt4.QtTest import * |
---|
[db5cd8d] | 4 | import inspect |
---|
[f721030] | 5 | |
---|
[db5cd8d] | 6 | def 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: |
---|
[092a3d9] | 14 | (frame, filename, line_number, |
---|
[db5cd8d] | 15 | function_name, lines, index) = inspect.getouterframes(inspect.currentframe())[1] |
---|
| 16 | print("\nWARNING: %s needs implementing!"%function_name) |
---|
[87cc73a] | 17 | |
---|
[f721030] | 18 | class 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 | |
---|
[488c49d] | 27 | self._recorder = {} |
---|
[f721030] | 28 | self._count = 0 |
---|
[488c49d] | 29 | self._signal = [] |
---|
[f721030] | 30 | |
---|
| 31 | # Assign our own slot to the emitted signal |
---|
[5032ea68] | 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) |
---|
[488c49d] | 39 | except AttributeError: |
---|
| 40 | msg = "Wrong construction of QtSignalSpy instance" |
---|
| 41 | raise RuntimeError, msg |
---|
[f721030] | 42 | |
---|
| 43 | def slot(self, *args, **kwargs): |
---|
| 44 | """ |
---|
| 45 | Record emitted signal. |
---|
| 46 | """ |
---|
[488c49d] | 47 | self._recorder[self._count] = { |
---|
[f721030] | 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 == 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): |
---|
[488c49d] | 65 | return self._recorder |
---|