aboutsummaryrefslogtreecommitdiff
path: root/test/test_exceptions.py
blob: e20649b8f31ccf34c9e24f0497ba50d36eb282cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest
import pickle

from urllib3.exceptions import (HTTPError, MaxRetryError, LocationParseError,
                                ClosedPoolError, EmptyPoolError,
                                HostChangedError, ReadTimeoutError,
                                ConnectTimeoutError)
from urllib3.connectionpool import HTTPConnectionPool



class TestPickle(unittest.TestCase):

    def cycle(self, item):
        return pickle.loads(pickle.dumps(item))

    def test_exceptions(self):
        assert self.cycle(HTTPError(None))
        assert self.cycle(MaxRetryError(None, None, None))
        assert self.cycle(LocationParseError(None))
        assert self.cycle(ConnectTimeoutError(None))

    def test_exceptions_with_objects(self):
        assert self.cycle(HTTPError('foo'))
        assert self.cycle(MaxRetryError(HTTPConnectionPool('localhost'),
                                        '/', None))
        assert self.cycle(LocationParseError('fake location'))
        assert self.cycle(ClosedPoolError(HTTPConnectionPool('localhost'),
                                          None))
        assert self.cycle(EmptyPoolError(HTTPConnectionPool('localhost'),
                                         None))
        assert self.cycle(HostChangedError(HTTPConnectionPool('localhost'),
                                           '/', None))
        assert self.cycle(ReadTimeoutError(HTTPConnectionPool('localhost'),
                                              '/', None))