Skip to content
Snippets Groups Projects
Unverified Commit 9d0f4043 authored by Piotr Maślanka's avatar Piotr Maślanka Committed by GitHub
Browse files

Merge pull request #11 from piotrmaslanka/Issue-10

Fixes #10
parents 5fa0a67e f3121b11
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,8 @@ class rethrow_as(object):
"""
# You can also provide just two exceptions
if len(pairs) == 2 and all(issubclass(p, BaseException) for p in pairs):
if len(pairs) == 2 and not isinstance(pairs[1], (tuple, list)) \
and all(issubclass(p, BaseException) for p in pairs):
self.mapping = {pairs[0]: pairs[1]}
else:
self.mapping = dict(pairs)
......
......@@ -39,4 +39,17 @@ class TestStuff(unittest.TestCase):
def lol():
raise ValueError()
self.assertRaises(NameError, lol)
\ No newline at end of file
self.assertRaises(NameError, lol)
def test_issue_10(self):
class WTFException1(Exception): pass
class WTFException2(Exception): pass
@rethrow_as((NameError, WTFException1),
(TypeError, WTFException2))
def provide(exc):
raise exc()
self.assertRaises(WTFException1, lambda: provide(NameError))
self.assertRaises(WTFException2, lambda: provide(TypeError))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment