Skip to content

Commit

Permalink
style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harvimt committed Jan 2, 2016
1 parent 30e555b commit 652ecda
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
7 changes: 4 additions & 3 deletions quamash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -104,6 +105,7 @@ def wait(self):

@with_logger
class QThreadExecutor:

"""
ThreadExecutor that produces QThreads.
Expand Down Expand Up @@ -225,6 +227,7 @@ class Signaler(QtCore.QObject):

@with_logger
class QEventLoop(_baseclass):

"""
Implementation of asyncio event loop that uses the Qt Event loop.
Expand Down Expand Up @@ -404,7 +407,6 @@ def add_reader(self, fd, callback, *args):

def remove_reader(self, fd):
"""Remove reader callback."""

if self.is_closed():
return

Expand Down Expand Up @@ -441,7 +443,6 @@ def add_writer(self, fd, callback, *args):

def remove_writer(self, fd):
"""Remove writer callback."""

if self.is_closed():
return

Expand Down
11 changes: 7 additions & 4 deletions quamash/_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions quamash/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


class _ProactorEventLoop(asyncio.ProactorEventLoop):

"""Proactor based event loop."""

def __init__(self):
Expand Down Expand Up @@ -166,6 +167,7 @@ def run(self):

@with_logger
class _EventPoller(QtCore.QObject):

"""Polling of events in separate thread."""

sig_events = QtCore.Signal(list)
Expand Down
10 changes: 8 additions & 2 deletions tests/test_qeventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def executor(request):


class TestCanRunTasksInExecutor:

"""
Test Cases Concerning running jobs in Executors.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -415,21 +418,24 @@ 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."""
client_sock, srv_sock = 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."""
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 652ecda

Please sign in to comment.