various pep-8 cleanups; remove unsused imports; remove unused variables
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jeff Knupp · committed by Jeff Knupp · parent 3ee781b · Browse files · 1 file·+71 added−48 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+71 added−48 removed
- other:+71 added−48 removed
Provenance
- Commit
e2c4da7- Tree
56d12e9- Author
Jeff Knupp <jknupp@appnexus.com>- Committer
Jeff Knupp <jknupp@appnexus.com>- Parent
3ee781b
1 file changed+71 added−48 removed
modified:test_requests.py+71 added-48 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(408+ url, 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 3 unmodified lines459 assert r.status_code == 200460 assert r.url == httpbin('get?test=foo&test=baz')461 462 def test_different_encodings_dont_break_post(self):463+ r = requests.post(459- 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+ httpbin('post'),465+ data={'stuff': json.dumps({'a': 123})},466+ params={'blah': 'asdf1234'},467+ files={'file': ('test_requests.py', open(__file__, 'rb'))})468 assert r.status_code == 200469 470 def test_unicode_multipart_post(self):471+ r = requests.post(466- r = requests.post(httpbin('post'),467- data={'stuff': u('ëlïxr')},468- files={'file': ('test_requests.py', open(__file__, 'rb'))})472+ httpbin('post'),473+ data={'stuff': u('ëlïxr')},474+ files={'file': ('test_requests.py', open(__file__, 'rb'))})475 assert r.status_code == 200476 477+ r = requests.post(471- r = requests.post(httpbin('post'),472- data={'stuff': u('ëlïxr').encode('utf-8')},473- files={'file': ('test_requests.py', open(__file__, 'rb'))})478+ httpbin('post'),479+ data={'stuff': u('ëlïxr').encode('utf-8')},480+ files={'file': ('test_requests.py', open(__file__, 'rb'))})481 assert r.status_code == 200482 483+ r = requests.post(476- r = requests.post(httpbin('post'),477- data={'stuff': 'elixr'},478- files={'file': ('test_requests.py', open(__file__, 'rb'))})484+ httpbin('post'),485+ data={'stuff': 'elixr'},486+ files={'file': ('test_requests.py', open(__file__, 'rb'))})487 assert r.status_code == 200488 489+ r = requests.post(481- r = requests.post(httpbin('post'),482- data={'stuff': 'elixr'.encode('utf-8')},483- files={'file': ('test_requests.py', open(__file__, 'rb'))})490+ httpbin('post'),491+ data={'stuff': 'elixr'.encode('utf-8')},492+ files={'file': ('test_requests.py', open(__file__, 'rb'))})493 assert r.status_code == 200494 495 def test_unicode_multipart_post_fieldnames(self):496 filename = os.path.splitext(__file__)[0] + '.py'7 unmodified lines504 assert b'name="b\'stuff\'"' not in prep.body505 506 def test_unicode_method_name(self):507 files = {'file': open('test_requests.py', 'rb')}499- r = requests.request(method=u('POST'), url=httpbin('post'), files=files)508+ r = requests.request(509+ method=u('POST'), url=httpbin('post'), files=files)510 assert r.status_code == 200511 512 def test_custom_content_type(self):513+ 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')})514+ httpbin('post'),515+ data={'stuff': json.dumps({'a': 123})},516+ files={'file1': ('test_requests.py', open(__file__, 'rb')),517+ 'file2': ('test_requests', open(__file__, 'rb'),518+ 'text/py-content-type')})519 assert r.status_code == 200520 assert b"text/py-content-type" in r.request.body521 522 def test_hook_receives_request_arguments(self):50 unmodified lines573 574 prep = s.prepare_request(req)575 resp = s.send(prep)576 566- assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'577+ assert resp.json()['headers'][578+ 'Dummy-Auth-Test'] == 'dummy-auth-test-ok'579 580 def test_links(self):581 r = requests.Response()582 r.headers = {122 unmodified lines705 assert items == list(items)706 # make sure one can use items multiple times707 assert list(items) == list(items)708 697-709 def test_time_elapsed_blank(self):710 r = requests.get(httpbin('get'))711 td = r.elapsed712 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)159 unmodified lines872 s.params['foo'] = 'bar'873 r = s.get(httpbin('get'), params={'FOO': 'bar'})874 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}875 865-876 def test_long_authinfo_in_url(self):877 url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(878 'E8A3BE87-9E3F-4620-8858-95478E385B5B',879 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',146 unmodified lines1026 1027 class TestCaseInsensitiveDict(unittest.TestCase):1028 1029 def test_mapping_init(self):1020- cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1030+ cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1031 assert len(cid) == 21032 assert 'foo' in cid1033 assert 'bar' in cid1034 65 unmodified lines1100 cid = CaseInsensitiveDict()1101 cid['spam'] = 'blueval'1102 cid.update({'sPam': 'notblueval'})1103 assert cid['spam'] == 'notblueval'1094- cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1104+ cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1105 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})1106 assert len(cid) == 21107 assert cid['foo'] == 'anotherfoo'1108 assert cid['bar'] == 'anotherbar'61 unmodified lines1170 from io import BytesIO1171 from requests.utils import super_len1172 1173 assert super_len(StringIO.StringIO()) == 01174+ assert super_len(1164- assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 291175+ StringIO.StringIO('with so much drama in the LBC')) == 291176 1177 assert super_len(BytesIO()) == 01178+ assert super_len(1167- assert super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 401179+ BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 401180 1181 try:1182 import cStringIO1183 except ImportError:1184 pass1185 else:1174- assert super_len(cStringIO.StringIO('but some how, some way...')) == 251186+ assert super_len(1187+ cStringIO.StringIO('but some how, some way...')) == 251188 1189 def test_get_environ_proxies_ip_ranges(self):1177- """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1190+ """Ensures that IP addresses are correctly matches with ranges1191+ in no_proxy variable."""1192 from requests.utils import get_environ_proxies1193 os.environ['no_proxy'] = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"1194 assert get_environ_proxies('http://192.168.0.1:5000/') == {}1195 assert get_environ_proxies('http://192.168.0.1/') == {}2 unmodified lines1198 assert get_environ_proxies('http://192.168.1.1:5000/') != {}1199 assert get_environ_proxies('http://192.168.1.1/') != {}1200 1201 def test_get_environ_proxies(self):1188- """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1202+ """Ensures that IP addresses are correctly matches with ranges1203+ in no_proxy variable."""1204 from requests.utils import get_environ_proxies1205 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/') == {}1206+ assert get_environ_proxies(1207+ 'http://localhost.localdomain:5000/v1.0/') == {}1208 assert get_environ_proxies('http://www.requests.com/') != {}1209 1210 def test_is_ipv4_address(self):1211 from requests.utils import is_ipv4_address17 unmodified lines1229 assert address_in_network('192.168.1.1', '192.168.1.0/24')1230 assert not address_in_network('172.16.0.1', '192.168.1.0/24')1231 1232 def test_get_auth_from_url(self):1217- """ Ensures that username and password in well-encoded URI as per RFC 3986 are correclty extracted """1233+ """Ensures that username and password in well-encoded URI as per1234+ RFC 3986 are correclty extracted."""1235 from requests.utils import get_auth_from_url1236 from requests.compat import quote1237 percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "1238 url_address = "request.com/url.html#test"1222- url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address1239+ url = "http://" + quote(1240+ percent_encoding_test_chars, '') + ':' + quote(1241+ percent_encoding_test_chars, '') + '@' + url_address1242 (username, password) = get_auth_from_url(url)1243 assert username == percent_encoding_test_chars1244 assert password == percent_encoding_test_chars1245 58 unmodified lines1304 1305 class TestTimeout:1306 def test_stream_timeout(self):1307 try:1289- r = requests.get('https://httpbin.org/delay/10', timeout=5.0)1308+ requests.get('https://httpbin.org/delay/10', timeout=5.0)1309 except requests.exceptions.Timeout as e:1310 assert 'Read timed out' in e.args[0].args[0]1311 1312 58 unmodified lines1371 1372 @pytest.fixture1373 def list_of_tuples():1374 return [1356- (('a', 'b'), ('c', 'd')),1357- (('c', 'd'), ('a', 'b')),1358- (('a', 'b'), ('c', 'd'), ('e', 'f')),1359- ]1375+ (('a', 'b'), ('c', 'd')),1376+ (('c', 'd'), ('a', 'b')),1377+ (('a', 'b'), ('c', 'd'), ('e', 'f')),1378+ ]1379 1380 1381 def test_data_argument_accepts_tuples(list_of_tuples):1382 """9 unmodified lines1392 hooks=default_hooks()1393 )1394 assert p.body == urlencode(data)1395 1396+1397 def assert_copy(p, p_copy):1398 for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):1399 assert getattr(p, attr) == getattr(p_copy, attr)1400 1401+1402 def test_prepared_request_empty_copy():1403 p = PreparedRequest()1404 assert_copy(p, p.copy())1405 1406+1407 def test_prepared_request_no_cookies_copy():1408 p = PreparedRequest()1409 p.prepare(1410 method='GET',2 unmodified lines1413 hooks=default_hooks()1414 )1415 assert_copy(p, p.copy())1416 1417+1418 def test_prepared_request_complete_copy():1419 p = PreparedRequest()1420 p.prepare(1421 method='GET',9 unmodified lines