Skip to content

Commit 584b8ec

Browse files
committed
Move SignalEmittedError / CallbackCalledTwiceError to pytestqt.exceptions
Preparation for avoiding early wait_signal.py imports, but also seems more consistent.
1 parent ef0f5cd commit 584b8ec

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

docs/wait_callback.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Anything following the ``with`` block will be run only after the callback has be
2626

2727
If the callback doesn't get called during the given timeout,
2828
:class:`qtbot.TimeoutError <pytestqt.exceptions.TimeoutError>` is raised. If it is called more than once,
29-
:class:`qtbot.CallbackCalledTwiceError <pytestqt.wait_signal.CallbackCalledTwiceError>` is raised.
29+
:class:`qtbot.CallbackCalledTwiceError <pytestqt.exceptions.CallbackCalledTwiceError>` is raised.
3030

3131
raising parameter
3232
-----------------

src/pytestqt/exceptions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,22 @@ class ScreenshotError(Exception):
116116
117117
Access via ``qtbot.ScreenshotError``.
118118
"""
119+
120+
121+
class SignalEmittedError(Exception):
122+
"""
123+
.. versionadded:: 1.11
124+
125+
The exception thrown by :meth:`pytestqt.qtbot.QtBot.assertNotEmitted` if a
126+
signal was emitted unexpectedly.
127+
"""
128+
129+
130+
class CallbackCalledTwiceError(Exception):
131+
"""
132+
.. versionadded:: 3.1
133+
134+
The exception thrown by :meth:`pytestqt.qtbot.QtBot.waitCallback` if a
135+
callback was called twice.
136+
"""
137+

src/pytestqt/qtbot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
import weakref
33
import warnings
44

5-
from pytestqt.exceptions import TimeoutError, ScreenshotError
5+
from pytestqt.exceptions import (
6+
TimeoutError,
7+
ScreenshotError,
8+
SignalEmittedError,
9+
CallbackCalledTwiceError,
10+
)
611
from pytestqt.qt_compat import qt_api
712
from pytestqt.wait_signal import (
813
SignalBlocker,
914
MultiSignalBlocker,
1015
SignalEmittedSpy,
11-
SignalEmittedError,
1216
CallbackBlocker,
13-
CallbackCalledTwiceError,
1417
)
1518

1619

src/pytestqt/wait_signal.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import functools
22

3-
from pytestqt.exceptions import TimeoutError
3+
from pytestqt.exceptions import (
4+
TimeoutError,
5+
SignalEmittedError,
6+
CallbackCalledTwiceError,
7+
)
48
from pytestqt.qt_compat import qt_api
59

610

@@ -710,24 +714,6 @@ def __exit__(self, type, value, traceback):
710714
self.wait()
711715

712716

713-
class SignalEmittedError(Exception):
714-
"""
715-
.. versionadded:: 1.11
716-
717-
The exception thrown by :meth:`pytestqt.qtbot.QtBot.assertNotEmitted` if a
718-
signal was emitted unexpectedly.
719-
"""
720-
721-
722-
class CallbackCalledTwiceError(Exception):
723-
"""
724-
.. versionadded:: 3.1
725-
726-
The exception thrown by :meth:`pytestqt.qtbot.QtBot.waitCallback` if a
727-
callback was called twice.
728-
"""
729-
730-
731717
def _silent_disconnect(signal, slot):
732718
"""Disconnects a signal from a slot, ignoring errors. Sometimes
733719
Qt might disconnect a signal automatically for unknown reasons.

tests/test_wait_signal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import sys
66

77
from pytestqt.qt_compat import qt_api
8-
from pytestqt.wait_signal import (
8+
from pytestqt.wait_signal import SignalAndArgs
9+
from pytestqt.exceptions import (
910
SignalEmittedError,
1011
TimeoutError,
11-
SignalAndArgs,
1212
CallbackCalledTwiceError,
1313
)
1414

0 commit comments

Comments
 (0)