diff --git a/quamash/__init__.py b/quamash/__init__.py index fb883a3..ee8e45c 100644 --- a/quamash/__init__.py +++ b/quamash/__init__.py @@ -57,8 +57,9 @@ @with_logger class _QThreadWorker(QtCore.QThread): + """ - Read from the queue. + Read jobs from the queue and then execute them. For use by the QThreadExecutor """ @@ -104,6 +105,7 @@ def wait(self): @with_logger class QThreadExecutor: + """ ThreadExecutor that produces QThreads. @@ -225,6 +227,7 @@ class Signaler(QtCore.QObject): @with_logger class QEventLoop(_baseclass): + """ Implementation of asyncio event loop that uses the Qt Event loop. @@ -404,7 +407,6 @@ def add_reader(self, fd, callback, *args): def remove_reader(self, fd): """Remove reader callback.""" - if self.is_closed(): return @@ -441,7 +443,6 @@ def add_writer(self, fd, callback, *args): def remove_writer(self, fd): """Remove writer callback.""" - if self.is_closed(): return diff --git a/quamash/_unix.py b/quamash/_unix.py index d50054b..fafed92 100644 --- a/quamash/_unix.py +++ b/quamash/_unix.py @@ -16,7 +16,8 @@ def _fileobj_to_fd(fileobj): - """Return a file descriptor from a file object. + """ + Return a file descriptor from a file object. Parameters: fileobj -- file object or file descriptor @@ -32,14 +33,15 @@ def _fileobj_to_fd(fileobj): else: try: fd = int(fileobj.fileno()) - except (AttributeError, TypeError, ValueError): - raise ValueError("Invalid file object: {!r}".format(fileobj)) from None + except (AttributeError, TypeError, ValueError) as ex: + raise ValueError("Invalid file object: {!r}".format(fileobj)) from ex if fd < 0: raise ValueError("Invalid file descriptor: {}".format(fd)) return fd class _SelectorMapping(collections.Mapping): + """Mapping of file objects to selector keys.""" def __init__(self, selector): @@ -170,7 +172,8 @@ def get_map(self): return self.__map def _key_from_fd(self, fd): - """Return the key associated to a given file descriptor. + """ + Return the key associated to a given file descriptor. Parameters: fd -- file descriptor diff --git a/quamash/_windows.py b/quamash/_windows.py index 18afe81..f442a63 100644 --- a/quamash/_windows.py +++ b/quamash/_windows.py @@ -22,6 +22,7 @@ class _ProactorEventLoop(asyncio.ProactorEventLoop): + """Proactor based event loop.""" def __init__(self): @@ -166,6 +167,7 @@ def run(self): @with_logger class _EventPoller(QtCore.QObject): + """Polling of events in separate thread.""" sig_events = QtCore.Signal(list) diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py index 3adafc7..a7098c7 100644 --- a/tests/test_qeventloop.py +++ b/tests/test_qeventloop.py @@ -88,6 +88,7 @@ def executor(request): class TestCanRunTasksInExecutor: + """ Test Cases Concerning running jobs in Executors. @@ -399,6 +400,7 @@ def can_read(): assert got_msg is None, 'Should not have received a read notification' + def test_remove_reader_after_closing(loop, sock_pair): """Verify that we can remove a reader callback from an event loop.""" client_sock, srv_sock = sock_pair @@ -407,6 +409,7 @@ def test_remove_reader_after_closing(loop, sock_pair): 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 @@ -415,13 +418,15 @@ def test_remove_writer_after_closing(loop, sock_pair): loop.close() loop.remove_writer(client_sock.fileno()) + 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) + 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.""" @@ -429,7 +434,8 @@ def test_add_writer_after_closing(loop, sock_pair): loop.close() with pytest.raises(RuntimeError): - loop.add_writer(client_sock.fileno(), lambda:None) + 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.""" diff --git a/tox.ini b/tox.ini index ca5d531..64bd23f 100644 --- a/tox.ini +++ b/tox.ini @@ -46,5 +46,5 @@ commands=py.test --cov quamash [flake8] max-complexity=15 -ignore=D1,W191,E501,E402,E704,E701 +ignore=D1,W191,E501,E402,E704,E701,D211 exclude=build,.git,__pycache__,wheelhouse,htmlcov,dist,.cache,*.egg-info,appveyor