Skip to content

Commit

Permalink
loop: improve tests + tune coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Feb 9, 2016
1 parent 21f4a1e commit 913910e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
38 changes: 38 additions & 0 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,41 @@ def throw_test(*_):

self.assert_is(self.loop.exc_type, Exception)
self.assert_equal(self.loop.exc_value.args[0], 'test')
self.loop.reset_exception()

self.loop.call_later(throw_test)

self.loop.run()

self.assert_is(self.loop.exc_type, Exception)
self.assert_equal(self.loop.exc_value.args[0], 'test')
self.loop.reset_exception()

def test_get_current_instantiate(self):
uv.Loop._thread_locals.loop = None
loop = uv.Loop.get_current()
self.assert_is(uv.Loop.get_current(), loop)
loop.close()

def test_default_exists(self):
uv.Loop.get_default()
self.assert_raises(RuntimeError, uv.Loop, default=True)

def test_closed(self):
self.loop.close()
self.assert_false(self.loop.alive)
with self.should_raise(uv.ClosedLoopError):
now = self.loop.now
self.assert_equal(self.loop.handles, set())
self.assert_raises(uv.ClosedLoopError, self.loop.fileno)
self.assert_raises(uv.ClosedLoopError, self.loop.update_time)
self.assert_raises(uv.ClosedLoopError, self.loop.get_timeout)
self.assert_raises(uv.ClosedLoopError, self.loop.run)
self.assert_is(self.loop.stop(), None)

@common.skip_platform('win32')
def test_fileno(self):
self.assert_greater(self.loop.fileno(), 0)

def test_poll_timeout(self):
self.assert_equal(self.loop.get_timeout(), 0)
8 changes: 4 additions & 4 deletions uv/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RunModes(common.Enumeration):
"""


def default_excepthook(loop, exc_type, exc_value, exc_traceback):
def default_excepthook(loop, exc_type, exc_value, exc_traceback): # pragma: no cover
"""
Default excepthook. Prints a traceback and stops the event loop to
prevent deadlocks and livelocks.
Expand Down Expand Up @@ -173,7 +173,7 @@ def __init__(self, buffer_size=2**16):
self.c_buffer = ffi.new('char[]', self.buffer_size)

def allocate(self, handle, suggested_size, uv_buffer):
if self.buffer_in_use:
if self.buffer_in_use: # pragma: no cover
# this should never happen because lib uv reads the data right
# before the execution of the read callback even if there are
# multiple sockets ready for reading
Expand Down Expand Up @@ -593,7 +593,7 @@ def on_wakeup(self):
callback, arguments, keywords = self.pending_callbacks.popleft()
try:
callback(*arguments, **keywords)
except BaseException:
except Exception:
self.handle_exception()
except IndexError:
pass
Expand All @@ -612,7 +612,7 @@ def handle_exception(self):
self.exc_type, self.exc_value, self.exc_traceback = sys.exc_info()
try:
self.excepthook(self, self.exc_type, self.exc_value, self.exc_traceback)
except BaseException:
except Exception: # pragma: no cover
# this should never happen during normal operation but if it does the
# program would be in an undefined state, so exit immediately
try:
Expand Down

0 comments on commit 913910e

Please sign in to comment.