Merge pull request #2065 from mgeisler/tox
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix Python 3.2 compatibility in tests
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 0d40d97, c8916a0 · Browse files · 2 files·+16 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+16 added−6 removed
- other:+16 added−6 removed
Provenance
- Commit
ddd748e- Tree
0396b72- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
0d40d97- Parent 2
c8916a0
2 files changed+16 added−6 removed
modified:docs/community/faq.rst+2 added
57 unmodified lines58 * Python 2.759 * Python 3.160 * Python 3.261 * Python 3.362+* Python 3.463 * PyPy 1.964+* PyPy 2.265 66 What are "hostname doesn't match" errors?67 -----------------------------------------68 19 unmodified linesmodified:test_requests.py+14 added-6 removed
14 unmodified lines15 import pytest16 from requests.adapters import HTTPAdapter17 from requests.auth import HTTPDigestAuth18 from requests.compat import (19- Morsel, cookielib, getproxies, str, urljoin, urlparse)19+ Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3)20 from requests.cookies import cookiejar_from_dict, morsel_to_cookie21 from requests.exceptions import InvalidURL, MissingSchema22 from requests.models import PreparedRequest, Response23 from requests.structures import CaseInsensitiveDict5 unmodified lines29 import StringIO30 except ImportError:31 import io as StringIO32 33+if is_py3:34+ def u(s):35+ return s36+else:37+ def u(s):38+ return s.decode('unicode-escape')39+40+41 HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')42 # Issue #1483: Make sure the URL always has a trailing slash43 HTTPBIN = HTTPBIN.rstrip('/') + '/'44 371 unmodified lines416 def test_conflicting_post_params(self):417 url = httpbin('post')418 with open('requirements.txt') as f:419 pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")412- pytest.raises(ValueError, "requests.post(url, data=u'[{\"some\": \"data\"}]', files={'some': f})")420+ pytest.raises(ValueError, "requests.post(url, data=u('[{\"some\": \"data\"}]'), files={'some': f})")421 422 def test_request_ok_set(self):423 r = requests.get(httpbin('status', '404'))424 assert not r.ok38 unmodified lines463 assert r.status_code == 200464 465 def test_unicode_multipart_post(self):466 r = requests.post(httpbin('post'),459- data={'stuff': u'ëlïxr'},467+ data={'stuff': u('ëlïxr')},468 files={'file': ('test_requests.py', open(__file__, 'rb'))})469 assert r.status_code == 200470 471 r = requests.post(httpbin('post'),464- data={'stuff': u'ëlïxr'.encode('utf-8')},472+ data={'stuff': u('ëlïxr').encode('utf-8')},473 files={'file': ('test_requests.py', open(__file__, 'rb'))})474 assert r.status_code == 200475 476 r = requests.post(httpbin('post'),18 unmodified lines495 assert b'name="b\'stuff\'"' not in prep.body496 497 def test_unicode_method_name(self):498 files = {'file': open('test_requests.py', 'rb')}491- r = requests.request(method=u'POST', url=httpbin('post'), files=files)499+ r = requests.request(method=u('POST'), url=httpbin('post'), files=files)500 assert r.status_code == 200501 502 def test_custom_content_type(self):503 r = requests.post(httpbin('post'),368 unmodified lines872 r = requests.Request('GET', url).prepare()873 assert r.url == url874 875 def test_header_keys_are_native(self):868- headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}876+ headers = {u('unicode'): 'blah', 'byte'.encode('ascii'): 'blah'}877 r = requests.Request('GET', httpbin('get'), headers=headers)878 p = r.prepare()879 880 # This is testing that they are builtin strings. A bit weird, but there494 unmodified lines