Skip to content

Commit

Permalink
fix python 3 reraise
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Dec 11, 2015
1 parent ce0f9ea commit 8c1f8ad
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@

import uv

from uv.common import dummy_callback
from uv.common import dummy_callback, is_py3

PY2_RERAISE = '''
def reraise(exc_type, exc_value, exc_traceback):
raise exc_type, exc_value, exc_traceback
'''

if is_py3:
def reraise(exc_type, exc_value, exc_traceback):
raise exc_value.with_traceback(exc_traceback)
else:
exec(PY2_RERAISE)


class TestLoop(uv.Loop):
Expand All @@ -39,12 +50,13 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
self.exc_value = exc_value
self.exc_traceback = exc_traceback
self.stop()
return True

def run(self, mode=uv.RunMode.DEFAULT):
self.exc_type = None
result = super(TestLoop, self).run(mode)
if self.exc_type is not None:
raise self.exc_type, self.exc_value, self.exc_traceback
reraise(self.exc_type, self.exc_value, self.exc_traceback)
return result


Expand Down

0 comments on commit 8c1f8ad

Please sign in to comment.