Merge pull request #2088 from jeffknupp/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
various pep-8 cleanups; remove unsused imports; remove unused variables
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 3ee781b, bff65f4 · Browse files · 1 file·+61 added−43 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+61 added−43 removed
- other:+61 added−43 removed
Provenance
- Commit
743ce81- Tree
9ed0bb6- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
3ee781b- Parent 2
bff65f4
1 file changed+61 added−43 removed
modified:test_requests.py+61 added-43 removed
17 unmodified lines18 from requests.compat import (19 Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3, builtin_str)20 from requests.cookies import cookiejar_from_dict, morsel_to_cookie21 from requests.exceptions import InvalidURL, MissingSchema22-from requests.models import PreparedRequest, Response22+from requests.models import PreparedRequest23 from requests.structures import CaseInsensitiveDict24 from requests.sessions import SessionRedirectMixin25-from requests.models import PreparedRequest, urlencode25+from requests.models import urlencode26 from requests.hooks import default_hooks27 28 try:29 import StringIO122 unmodified lines152 153 def test_set_cookie_on_301(self):154 s = requests.session()155 url = httpbin('cookies/set?foo=bar')156- r = s.get(url)156+ s.get(url)157 assert s.cookies['foo'] == 'bar'158 159 def test_cookie_sent_on_redirect(self):160 s = requests.session()51 unmodified lines212 assert s.cookies is cj213 214 def test_param_cookiejar_works(self):215 cj = cookielib.CookieJar()216- cookiejar_from_dict({'foo' : 'bar'}, cj)216+ cookiejar_from_dict({'foo': 'bar'}, cj)217 s = requests.session()218 r = s.get(httpbin('cookies'), cookies=cj)219 # Make sure the cookie was sent220 assert r.json()['cookies']['foo'] == 'bar'171 unmodified lines392 post4 = requests.post(url, data='[{"some": "json"}]')393 assert post4.status_code == 200394 395 with pytest.raises(ValueError):396- requests.post(url, files = ['bad file data'])396+ requests.post(url, files=['bad file data'])397 398 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):399 400 url = httpbin('post')2 unmodified lines403 post1 = requests.post(url, data={'some': 'data'})404 assert post1.status_code == 200405 406 with open('requirements.txt') as f:407- post2 = requests.post(url, data={'some': 'data'}, files={'some': f})407+ post2 = requests.post(url,408+ data={'some': 'data'}, files={'some': f})409 assert post2.status_code == 200410 411 post4 = requests.post(url, data='[{"some": "json"}]')412 assert post4.status_code == 200413 414 with pytest.raises(ValueError):414- requests.post(url, files = ['bad file data'])415+ requests.post(url, files=['bad file data'])416 417 def test_conflicting_post_params(self):418 url = httpbin('post')419 with open('requirements.txt') as f:24 unmodified lines444 requests.get(url, params={'foo': 'foo'})445 requests.get(httpbin('ø'), params={'foo': 'foo'})446 447 def test_unicode_header_name(self):447- requests.put(httpbin('put'), headers={str('Content-Type'): 'application/octet-stream'}, data='\xff') # compat.str is unicode.448+ requests.put(449+ httpbin('put'),450+ headers={str('Content-Type'): 'application/octet-stream'},451+ data='\xff') # compat.str is unicode.452 453 def test_pyopenssl_redirect(self):454 requests.get('https://httpbin.org/status/301')455 4 unmodified lines460 assert r.url == httpbin('get?test=foo&test=baz')461 462 def test_different_encodings_dont_break_post(self):463 r = requests.post(httpbin('post'),460- data={'stuff': json.dumps({'a': 123})},461- params={'blah': 'asdf1234'},462- files={'file': ('test_requests.py', open(__file__, 'rb'))})464+ data={'stuff': json.dumps({'a': 123})},465+ params={'blah': 'asdf1234'},466+ files={'file': ('test_requests.py', open(__file__, 'rb'))})467 assert r.status_code == 200468 469 def test_unicode_multipart_post(self):470 r = requests.post(httpbin('post'),467- data={'stuff': u('ëlïxr')},468- files={'file': ('test_requests.py', open(__file__, 'rb'))})471+ data={'stuff': u('ëlïxr')},472+ files={'file': ('test_requests.py', open(__file__, 'rb'))})473 assert r.status_code == 200474 475 r = requests.post(httpbin('post'),472- data={'stuff': u('ëlïxr').encode('utf-8')},473- files={'file': ('test_requests.py', open(__file__, 'rb'))})476+ data={'stuff': u('ëlïxr').encode('utf-8')},477+ files={'file': ('test_requests.py', open(__file__, 'rb'))})478 assert r.status_code == 200479 480 r = requests.post(httpbin('post'),477- data={'stuff': 'elixr'},478- files={'file': ('test_requests.py', open(__file__, 'rb'))})481+ data={'stuff': 'elixr'},482+ files={'file': ('test_requests.py', open(__file__, 'rb'))})483 assert r.status_code == 200484 485 r = requests.post(httpbin('post'),482- data={'stuff': 'elixr'.encode('utf-8')},483- files={'file': ('test_requests.py', open(__file__, 'rb'))})486+ data={'stuff': 'elixr'.encode('utf-8')},487+ files={'file': ('test_requests.py', open(__file__, 'rb'))})488 assert r.status_code == 200489 490 def test_unicode_multipart_post_fieldnames(self):491 filename = os.path.splitext(__file__)[0] + '.py'7 unmodified lines499 assert b'name="b\'stuff\'"' not in prep.body500 501 def test_unicode_method_name(self):502 files = {'file': open('test_requests.py', 'rb')}499- r = requests.request(method=u('POST'), url=httpbin('post'), files=files)503+ r = requests.request(504+ method=u('POST'), url=httpbin('post'), files=files)505 assert r.status_code == 200506 507 def test_custom_content_type(self):508+ r = requests.post(503- r = requests.post(httpbin('post'),504- data={'stuff': json.dumps({'a': 123})},505- files={'file1': ('test_requests.py', open(__file__, 'rb')),506- 'file2': ('test_requests', open(__file__, 'rb'),507- 'text/py-content-type')})509+ httpbin('post'),510+ data={'stuff': json.dumps({'a': 123})},511+ files={'file1': ('test_requests.py', open(__file__, 'rb')),512+ 'file2': ('test_requests', open(__file__, 'rb'),513+ 'text/py-content-type')})514 assert r.status_code == 200515 assert b"text/py-content-type" in r.request.body516 517 def test_hook_receives_request_arguments(self):50 unmodified lines568 569 prep = s.prepare_request(req)570 resp = s.send(prep)571 566- assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'572+ assert resp.json()['headers'][573+ 'Dummy-Auth-Test'] == 'dummy-auth-test-ok'574 575 def test_links(self):576 r = requests.Response()577 r.headers = {122 unmodified lines700 assert items == list(items)701 # make sure one can use items multiple times702 assert list(items) == list(items)703 697-704 def test_time_elapsed_blank(self):705 r = requests.get(httpbin('get'))706 td = r.elapsed707 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)159 unmodified lines867 s.params['foo'] = 'bar'868 r = s.get(httpbin('get'), params={'FOO': 'bar'})869 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}870 865-871 def test_long_authinfo_in_url(self):872 url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(873 'E8A3BE87-9E3F-4620-8858-95478E385B5B',874 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',146 unmodified lines1021 1022 class TestCaseInsensitiveDict(unittest.TestCase):1023 1024 def test_mapping_init(self):1020- cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1025+ cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1026 assert len(cid) == 21027 assert 'foo' in cid1028 assert 'bar' in cid1029 65 unmodified lines1095 cid = CaseInsensitiveDict()1096 cid['spam'] = 'blueval'1097 cid.update({'sPam': 'notblueval'})1098 assert cid['spam'] == 'notblueval'1094- cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1099+ cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1100 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})1101 assert len(cid) == 21102 assert cid['foo'] == 'anotherfoo'1103 assert cid['bar'] == 'anotherbar'61 unmodified lines1165 from io import BytesIO1166 from requests.utils import super_len1167 1168 assert super_len(StringIO.StringIO()) == 01169+ assert super_len(1164- assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 291170+ StringIO.StringIO('with so much drama in the LBC')) == 291171 1172 assert super_len(BytesIO()) == 01173+ assert super_len(1167- assert super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 401174+ BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 401175 1176 try:1177 import cStringIO1178 except ImportError:1179 pass1180 else:1174- assert super_len(cStringIO.StringIO('but some how, some way...')) == 251181+ assert super_len(1182+ cStringIO.StringIO('but some how, some way...')) == 251183 1184 def test_get_environ_proxies_ip_ranges(self):1177- """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1185+ """Ensures that IP addresses are correctly matches with ranges1186+ in no_proxy variable."""1187 from requests.utils import get_environ_proxies1188 os.environ['no_proxy'] = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"1189 assert get_environ_proxies('http://192.168.0.1:5000/') == {}1190 assert get_environ_proxies('http://192.168.0.1/') == {}2 unmodified lines1193 assert get_environ_proxies('http://192.168.1.1:5000/') != {}1194 assert get_environ_proxies('http://192.168.1.1/') != {}1195 1196 def test_get_environ_proxies(self):1188- """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1197+ """Ensures that IP addresses are correctly matches with ranges1198+ in no_proxy variable."""1199 from requests.utils import get_environ_proxies1200 os.environ['no_proxy'] = "127.0.0.1,localhost.localdomain,192.168.0.0/24,172.16.1.1"1191- assert get_environ_proxies('http://localhost.localdomain:5000/v1.0/') == {}1201+ assert get_environ_proxies(1202+ 'http://localhost.localdomain:5000/v1.0/') == {}1203 assert get_environ_proxies('http://www.requests.com/') != {}1204 1205 def test_is_ipv4_address(self):1206 from requests.utils import is_ipv4_address17 unmodified lines1224 assert address_in_network('192.168.1.1', '192.168.1.0/24')1225 assert not address_in_network('172.16.0.1', '192.168.1.0/24')1226 1227 def test_get_auth_from_url(self):1217- """ Ensures that username and password in well-encoded URI as per RFC 3986 are correclty extracted """1228+ """Ensures that username and password in well-encoded URI as per1229+ RFC 3986 are correclty extracted."""1230 from requests.utils import get_auth_from_url1231 from requests.compat import quote1232 percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "1233 url_address = "request.com/url.html#test"1222- url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address1234+ url = "http://" + quote(1235+ percent_encoding_test_chars, '') + ':' + quote(1236+ percent_encoding_test_chars, '') + '@' + url_address1237 (username, password) = get_auth_from_url(url)1238 assert username == percent_encoding_test_chars1239 assert password == percent_encoding_test_chars1240 58 unmodified lines1299 1300 class TestTimeout:1301 def test_stream_timeout(self):1302 try:1289- r = requests.get('https://httpbin.org/delay/10', timeout=5.0)1303+ requests.get('https://httpbin.org/delay/10', timeout=5.0)1304 except requests.exceptions.Timeout as e:1305 assert 'Read timed out' in e.args[0].args[0]1306 1307 58 unmodified lines1366 1367 @pytest.fixture1368 def list_of_tuples():1369 return [1356- (('a', 'b'), ('c', 'd')),1357- (('c', 'd'), ('a', 'b')),1358- (('a', 'b'), ('c', 'd'), ('e', 'f')),1359- ]1370+ (('a', 'b'), ('c', 'd')),1371+ (('c', 'd'), ('a', 'b')),1372+ (('a', 'b'), ('c', 'd'), ('e', 'f')),1373+ ]1374 1375 1376 def test_data_argument_accepts_tuples(list_of_tuples):1377 """9 unmodified lines1387 hooks=default_hooks()1388 )1389 assert p.body == urlencode(data)1390 1391+1392 def assert_copy(p, p_copy):1393 for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):1394 assert getattr(p, attr) == getattr(p_copy, attr)1395 1396+1397 def test_prepared_request_empty_copy():1398 p = PreparedRequest()1399 assert_copy(p, p.copy())1400 1401+1402 def test_prepared_request_no_cookies_copy():1403 p = PreparedRequest()1404 p.prepare(1405 method='GET',2 unmodified lines1408 hooks=default_hooks()1409 )1410 assert_copy(p, p.copy())1411 1412+1413 def test_prepared_request_complete_copy():1414 p = PreparedRequest()1415 p.prepare(1416 method='GET',9 unmodified lines