Repository: piotrmaslanka/satella

Issue:
Bad rethrow_as
```python
    @rethrow_as((UnicodeDecodeError, ConfigurationMalformed),
                (json.JSONDecodeError, ConfigurationMalformed))
    @rethrow_as(ValueError, ConfigurationMalformed)
    @rethrow_as(binascii.Error, ConfigurationMalformed)
    @rethrow_as(TypeError, ConfigurationError)
    def provide(self):
        return json.loads(self.root, encoding=self.encoding)
```

breaks it by treating two first pairs in a wrong way

Discussion:

Patch:
diff --git a/satella/coding/recast_exceptions.py b/satella/coding/recast_exceptions.py
index bf164db4..32e4e1c8 100644
--- a/satella/coding/recast_exceptions.py
+++ b/satella/coding/recast_exceptions.py
@@ -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)


Test patch:
diff --git a/tests/test_coding/test_rethrow.py b/tests/test_coding/test_rethrow.py
index ce17f722..80dd8ec6 100644
--- a/tests/test_coding/test_rethrow.py
+++ b/tests/test_coding/test_rethrow.py
@@ -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))