diff options
author | uu4k <t.shimizu1115@gmail.com> | 2018-03-28 16:18:18 +0900 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2018-03-29 23:26:37 +0300 |
commit | a49b5a9c92265735f1fd8c318105234aecdf51e4 (patch) | |
tree | d431a4476fc28d371b85f4474a5b580e4c3b876b /tests | |
parent | 013682ef34f85d711b999eee57b6723bde09a291 (diff) | |
download | httplib2-a49b5a9c92265735f1fd8c318105234aecdf51e4.tar.gz |
proxy: py3 NameError basestring
https://github.com/httplib2/httplib2/pull/100
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 14 | ||||
-rw-r--r-- | tests/test_proxy.py | 14 |
2 files changed, 21 insertions, 7 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index 6cac5fd..1af0720 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -24,17 +24,19 @@ from six.moves import http_client, queue @contextlib.contextmanager def assert_raises(exc_type): + def _name(t): + return getattr(t, '__name__', None) or str(t) + + if not isinstance(exc_type, tuple): + exc_type = (exc_type,) + names = ', '.join(map(_name, exc_type)) + try: yield except exc_type: pass else: - name = str(exc_type) - try: - name = exc_type.__name__ - except AttributeError: - pass - assert False, 'Expected exception {0}'.format(name) + assert False, 'Expected exception(s) {0}'.format(names) class BufferedReader(object): diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 3f1622e..4007868 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -3,8 +3,10 @@ Each test must be run in separate process. Must use pytest --forked or similar technique. ''' import httplib2 +import mock import os -# import tests +import socket +import tests def test_from_url(): @@ -78,3 +80,13 @@ def test_headers(): headers = {'key0': 'val0', 'key1': 'val1'} pi = httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP, 'localhost', 1234, proxy_headers=headers) assert pi.proxy_headers == headers + + +def test_github_100_socks_basestring(): + # https://github.com/httplib2/httplib2/pull/100 + # NameError: name 'basestring' is not defined + # TODO: replace invalid address with dummy local server + http = httplib2.Http(proxy_info=httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP, '255.255.255.255', 8001)) + with tests.assert_raises(httplib2.ServerNotFoundError): + with mock.patch('socket.socket.connect', side_effect=socket.gaierror): + http.request('http://255.255.255.255/', 'GET') |