[Pkg-bitcoin-commits] [python-quamash] 261/269: Check closed in add fds
Jonas Smedegaard
dr at jones.dk
Fri Nov 24 11:26:42 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository python-quamash.
commit 30e555b9162515318cf01baec075a7826fa4b3a8
Author: Inso <insomniak.fr at gmail.com>
Date: Wed Dec 23 11:43:03 2015 +0100
Check closed in add fds
---
quamash/__init__.py | 3 +++
tests/test_qeventloop.py | 35 ++++++++++++++++++++++++-----------
2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/quamash/__init__.py b/quamash/__init__.py
index 13b2e43..fb883a3 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -381,6 +381,8 @@ class QEventLoop(_baseclass):
def add_reader(self, fd, callback, *args):
"""Register a callback for when a file descriptor is ready for reading."""
+ self._check_closed()
+
try:
existing = self._read_notifiers[fd]
except KeyError:
@@ -417,6 +419,7 @@ class QEventLoop(_baseclass):
def add_writer(self, fd, callback, *args):
"""Register a callback for when a file descriptor is ready for writing."""
+ self._check_closed()
try:
existing = self._write_notifiers[fd]
except KeyError:
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 5e0cbb4..3adafc7 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -399,24 +399,37 @@ def test_can_remove_reader(loop, sock_pair):
assert got_msg is None, 'Should not have received a read notification'
-def test_can_remove_reader_after_closing(loop, sock_pair):
+def test_remove_reader_after_closing(loop, sock_pair):
"""Verify that we can remove a reader callback from an event loop."""
- def can_read():
- data = srv_sock.recv(1)
- if len(data) != 1:
- return
+ client_sock, srv_sock = sock_pair
- nonlocal got_msg
- got_msg = data
+ loop.add_reader(srv_sock.fileno(), lambda: None)
+ loop.close()
+ loop.remove_reader(srv_sock.fileno())
+def test_remove_writer_after_closing(loop, sock_pair):
+ """Verify that we can remove a reader callback from an event loop."""
client_sock, srv_sock = sock_pair
- got_msg = None
- loop.add_reader(srv_sock.fileno(), can_read)
+ loop.add_writer(client_sock.fileno(), lambda: None)
loop.close()
- loop.remove_reader(srv_sock.fileno())
+ loop.remove_writer(client_sock.fileno())
- assert got_msg is None, 'Should not have received a read notification'
+def test_add_reader_after_closing(loop, sock_pair):
+ """Verify that we can remove a reader callback from an event loop."""
+ client_sock, srv_sock = sock_pair
+
+ loop.close()
+ with pytest.raises(RuntimeError):
+ loop.add_reader(srv_sock.fileno(), lambda:None)
+
+def test_add_writer_after_closing(loop, sock_pair):
+ """Verify that we can remove a reader callback from an event loop."""
+ client_sock, srv_sock = sock_pair
+
+ loop.close()
+ with pytest.raises(RuntimeError):
+ loop.add_writer(client_sock.fileno(), lambda:None)
def test_can_add_writer(loop, sock_pair):
"""Verify that we can add a writer callback to an event loop."""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git
More information about the Pkg-bitcoin-commits
mailing list