summaryrefslogtreecommitdiff
path: root/tests/test_exceptions.py
diff options
context:
space:
mode:
authorBob Halley <halley@play-bow.org>2015-05-21 05:41:26 -0700
committerBob Halley <halley@play-bow.org>2015-05-21 05:41:26 -0700
commit1616939677dd1115539519fe645b15abf4623bb1 (patch)
treee19e6a9f4ddc835c6b208b3f8f194378538853f5 /tests/test_exceptions.py
parent0b8ae7fd1107f330f94afc03311f233d51968a66 (diff)
parenta6ab3bb6a89c03be48dd2d88f1e4575c5d8166c4 (diff)
downloaddnspython-1616939677dd1115539519fe645b15abf4623bb1.tar.gz
Merge pull request #98 from encukou/python3-parametrized-exceptions
Python3 parametrized exceptions
Diffstat (limited to 'tests/test_exceptions.py')
-rw-r--r--tests/test_exceptions.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
index 3fd7331..90a6af4 100644
--- a/tests/test_exceptions.py
+++ b/tests/test_exceptions.py
@@ -18,6 +18,12 @@ import unittest
from dns.exception import DNSException
+
+class FormatedError(DNSException):
+ fmt = "Custom format: {parameter}"
+ supp_kwargs = set(['parameter'])
+
+
class ExceptionTestCase(unittest.TestCase):
def test_custom_message(self):
@@ -33,6 +39,24 @@ class ExceptionTestCase(unittest.TestCase):
except DNSException as ex:
self.assertEqual(ex.__class__.__doc__, str(ex))
+ def test_formatted_error(self):
+ """Exceptions with explicit format has to respect it."""
+ params = {'parameter': 'value'}
+ try:
+ raise FormatedError(**params)
+ except FormatedError as ex:
+ msg = FormatedError.fmt.format(**params)
+ self.assertEqual(msg, str(ex))
+
+ def test_kwargs_only(self):
+ """Kwargs cannot be combined with args."""
+ with self.assertRaises(AssertionError):
+ raise FormatedError(1, a=2)
+
+ def test_kwargs_unsupported(self):
+ """Only supported kwargs are accepted."""
+ with self.assertRaises(AssertionError):
+ raise FormatedError(unsupported=2)
if __name__ == '__main__':
unittest.main()