summaryrefslogtreecommitdiff
path: root/test/test_exceptions.py
diff options
context:
space:
mode:
authorAlex Chan <alex@alexwlchan.net>2017-06-05 12:15:49 +0100
committerAlex Chan <alex@alexwlchan.net>2017-06-05 12:15:49 +0100
commit9f7c3de476f81cb0c877e4cbbb0365fb662718b2 (patch)
tree13223eec45f1e395a7c02cfb6d3609e34c6c93b8 /test/test_exceptions.py
parent8e0edf4185cd5d9e7d91a1cb4f674c3aaffbadb2 (diff)
downloadurllib3-9f7c3de476f81cb0c877e4cbbb0365fb662718b2.tar.gz
Rewrite test_exceptions.py to be pytest-style
Diffstat (limited to 'test/test_exceptions.py')
-rw-r--r--test/test_exceptions.py60
1 files changed, 22 insertions, 38 deletions
diff --git a/test/test_exceptions.py b/test/test_exceptions.py
index beb538b3..2eb3e75b 100644
--- a/test/test_exceptions.py
+++ b/test/test_exceptions.py
@@ -1,6 +1,7 @@
-import unittest
import pickle
+import pytest
+
from urllib3.exceptions import (HTTPError, MaxRetryError, LocationParseError,
ClosedPoolError, EmptyPoolError,
HostChangedError, ReadTimeoutError,
@@ -8,46 +9,29 @@ from urllib3.exceptions import (HTTPError, MaxRetryError, LocationParseError,
from urllib3.connectionpool import HTTPConnectionPool
-class TestPickle(unittest.TestCase):
-
- def verify_pickling(self, item):
- return pickle.loads(pickle.dumps(item))
-
- def test_exceptions(self):
- assert self.verify_pickling(HTTPError(None))
- assert self.verify_pickling(MaxRetryError(None, None, None))
- assert self.verify_pickling(LocationParseError(None))
- assert self.verify_pickling(ConnectTimeoutError(None))
-
- def test_exceptions_with_objects(self):
- assert self.verify_pickling(
- HTTPError('foo'))
-
- assert self.verify_pickling(
- HTTPError('foo', IOError('foo')))
-
- assert self.verify_pickling(
- MaxRetryError(HTTPConnectionPool('localhost'), '/', None))
-
- assert self.verify_pickling(
- LocationParseError('fake location'))
-
- assert self.verify_pickling(
- ClosedPoolError(HTTPConnectionPool('localhost'), None))
-
- assert self.verify_pickling(
- EmptyPoolError(HTTPConnectionPool('localhost'), None))
-
- assert self.verify_pickling(
- HostChangedError(HTTPConnectionPool('localhost'), '/', None))
+class TestPickle(object):
- assert self.verify_pickling(
- ReadTimeoutError(HTTPConnectionPool('localhost'), '/', None))
+ @pytest.mark.parametrize('exception', [
+ HTTPError(None),
+ MaxRetryError(None, None, None),
+ LocationParseError(None),
+ ConnectTimeoutError(None),
+ HTTPError('foo'),
+ HTTPError('foo', IOError('foo')),
+ MaxRetryError(HTTPConnectionPool('localhost'), '/', None),
+ LocationParseError('fake location'),
+ ClosedPoolError(HTTPConnectionPool('localhost'), None),
+ EmptyPoolError(HTTPConnectionPool('localhost'), None),
+ HostChangedError(HTTPConnectionPool('localhost'), '/', None),
+ ReadTimeoutError(HTTPConnectionPool('localhost'), '/', None),
+ ])
+ def test_exceptions(self, exception):
+ assert pickle.loads(pickle.dumps(exception))
-class TestFormat(unittest.TestCase):
+class TestFormat(object):
def test_header_parsing_errors(self):
hpe = HeaderParsingError('defects', 'unparsed_data')
- self.assertTrue('defects' in str(hpe))
- self.assertTrue('unparsed_data' in str(hpe))
+ assert 'defects' in str(hpe)
+ assert 'unparsed_data' in str(hpe)