Merge pull request #1707 from canibanoglu/tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Modified the tests so that they use py.test convention
authored by Kenneth Reitz · committed by Kenneth Reitz · parents c4a7760, aa60b8e · Browse files · 1 file·+161 added−182 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+161 added−182 removed
- other:+161 added−182 removed
Provenance
- Commit
2d55425- Tree
712bc01- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
c4a7760- Parent 2
aa60b8e
1 file changed+161 added−182 removed
modified:test_requests.py+161 added-182 removed
55 unmodified lines56 requests.patch57 requests.post58 59 def test_invalid_url(self):60- self.assertRaises(MissingSchema, requests.get, 'hiwpefhipowhefopw')61- self.assertRaises(InvalidURL, requests.get, 'http://')60+ with pytest.raises(MissingSchema):61+ requests.get('hiwpefhipowhefopw')62+ with pytest.raises(InvalidURL):63+ requests.get('http://')64 65 def test_basic_building(self):66 req = requests.Request()67 req.url = 'http://kennethreitz.org/'4 unmodified lines72 assert pr.body == 'life=42'73 74 def test_no_content_length(self):75 get_req = requests.Request('GET', httpbin('get')).prepare()74- self.assertTrue('Content-Length' not in get_req.headers)76+ assert 'Content-Length' not in get_req.headers77 head_req = requests.Request('HEAD', httpbin('head')).prepare()76- self.assertTrue('Content-Length' not in head_req.headers)78+ assert 'Content-Length' not in head_req.headers79 80 def test_path_is_not_double_encoded(self):81 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()82 81- self.assertEqual(request.path_url, "/get/test%20case")83+ assert request.path_url == '/get/test%20case'84 85 def test_params_are_added_before_fragment(self):86 request = requests.Request('GET',87 "http://example.com/path#fragment", params={"a": "b"}).prepare()86- self.assertEqual(request.url,87- "http://example.com/path?a=b#fragment")88+ assert request.url == "http://example.com/path?a=b#fragment"89 request = requests.Request('GET',90 "http://example.com/path?key=value#fragment", params={"a": "b"}).prepare()90- self.assertEqual(request.url,91- "http://example.com/path?key=value&a=b#fragment")91+ assert request.url == "http://example.com/path?key=value&a=b#fragment"92 93 def test_mixed_case_scheme_acceptable(self):94 s = requests.Session()95 s.proxies = getproxies()3 unmodified lines99 for scheme in schemes:100 url = scheme + parts.netloc + parts.path101 r = requests.Request('GET', url)102 r = s.send(r.prepare())103- self.assertEqual(r.status_code, 200,104- "failed for scheme %s" % scheme)103+ assert r.status_code == 200, 'failed for scheme {0}'.format(scheme)104 105 def test_HTTP_200_OK_GET_ALTERNATIVE(self):106 r = requests.Request('GET', httpbin('get'))107 s = requests.Session()108 s.proxies = getproxies()109 110 r = s.send(r.prepare())111 113- self.assertEqual(r.status_code, 200)112+ assert r.status_code == 200113 114 def test_HTTP_302_ALLOW_REDIRECT_GET(self):115 r = requests.get(httpbin('redirect', '1'))117- self.assertEqual(r.status_code, 200)116+ assert r.status_code == 200117 118 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):119 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})120 # self.assertEqual(r.status_code, 200)2 unmodified lines123 heads = {'User-agent': 'Mozilla/5.0'}124 125 r = requests.get(httpbin('user-agent'), headers=heads)126 128- self.assertTrue(heads['User-agent'] in r.text)129- self.assertEqual(r.status_code, 200)127+ assert heads['User-agent'] in r.text128+ assert r.status_code == 200129 130 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):131 heads = {'User-agent': 'Mozilla/5.0'}132 133 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)135- self.assertEqual(r.status_code, 200)134+ assert r.status_code == 200135 136 def test_set_cookie_on_301(self):137 s = requests.session()138 url = httpbin('cookies/set?foo=bar')139 r = s.get(url)141- self.assertTrue(s.cookies['foo'] == 'bar')140+ assert s.cookies['foo'] == 'bar'141 142 def test_cookie_sent_on_redirect(self):143 s = requests.session()144 s.get(httpbin('cookies/set?foo=bar'))145 r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')147- self.assertTrue("Cookie" in r.json()["headers"])146+ assert 'Cookie' in r.json()['headers']147 148 def test_cookie_removed_on_expire(self):149 s = requests.session()150 s.get(httpbin('cookies/set?foo=bar'))152- self.assertTrue(s.cookies['foo'] == 'bar')151+ assert s.cookies['foo'] == 'bar'152 s.get(153 httpbin('response-headers'),154 params={155 'Set-Cookie':4 unmodified lines160 161 def test_cookie_quote_wrapped(self):162 s = requests.session()163 s.get(httpbin('cookies/set?foo="bar:baz"'))165- self.assertTrue(s.cookies['foo'] == '"bar:baz"')164+ assert s.cookies['foo'] == '"bar:baz"'165 166 def test_cookie_persists_via_api(self):167 s = requests.session()168 r = s.get(httpbin('redirect/1'), cookies={'foo':'bar'})170- self.assertTrue('foo' in r.request.headers['Cookie'])171- self.assertTrue('foo' in r.history[0].request.headers['Cookie'])169+ assert 'foo' in r.request.headers['Cookie']170+ assert 'foo' in r.history[0].request.headers['Cookie']171 172 def test_request_cookie_overrides_session_cookie(self):173 s = requests.session()174 s.cookies['foo'] = 'bar'16 unmodified lines191 def test_requests_in_history_are_not_overridden(self):192 resp = requests.get(httpbin('redirect/3'))193 urls = [r.url for r in resp.history]194 req_urls = [r.request.url for r in resp.history]196- self.assertEquals(urls, req_urls)195+ assert urls == req_urls196 197 def test_user_agent_transfers(self):198 199 heads = {200 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'201 }202 203 r = requests.get(httpbin('user-agent'), headers=heads)205- self.assertTrue(heads['User-agent'] in r.text)204+ assert heads['User-agent'] in r.text205 206 heads = {207 'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'208 }209 210 r = requests.get(httpbin('user-agent'), headers=heads)212- self.assertTrue(heads['user-agent'] in r.text)211+ assert heads['user-agent'] in r.text212 213 def test_HTTP_200_OK_HEAD(self):214 r = requests.head(httpbin('get'))216- self.assertEqual(r.status_code, 200)215+ assert r.status_code == 200216 217 def test_HTTP_200_OK_PUT(self):218 r = requests.put(httpbin('put'))220- self.assertEqual(r.status_code, 200)219+ assert r.status_code == 200220 221 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):222 auth = ('user', 'pass')223 url = httpbin('basic-auth', 'user', 'pass')224 225 r = requests.get(url, auth=auth)227- self.assertEqual(r.status_code, 200)226+ assert r.status_code == 200227 228 r = requests.get(url)230- self.assertEqual(r.status_code, 401)229+ assert r.status_code == 401230 231 s = requests.session()232 s.auth = auth233 r = s.get(url)235- self.assertEqual(r.status_code, 200)234+ assert r.status_code == 200235 236 def test_basicauth_with_netrc(self):237 auth = ('user', 'pass')238 wrong_auth = ('wronguser', 'wrongpass')4 unmodified lines243 requests.sessions.get_netrc_auth = get_netrc_auth_mock244 245 # Should use netrc and work.246 r = requests.get(url)248- self.assertEqual(r.status_code, 200)247+ assert r.status_code == 200248 249 # Given auth should override and fail.250 r = requests.get(url, auth=wrong_auth)252- self.assertEqual(r.status_code, 401)251+ assert r.status_code == 401252 253 s = requests.session()254 255 # Should use netrc and work.256 r = s.get(url)258- self.assertEqual(r.status_code, 200)257+ assert r.status_code == 200258 259 # Given auth should override and fail.260 s.auth = wrong_auth261 r = s.get(url)263- self.assertEqual(r.status_code, 401)262+ assert r.status_code == 401263 264 def test_DIGEST_HTTP_200_OK_GET(self):265 266 auth = HTTPDigestAuth('user', 'pass')267 url = httpbin('digest-auth', 'auth', 'user', 'pass')268 269 r = requests.get(url, auth=auth)271- self.assertEqual(r.status_code, 200)270+ assert r.status_code == 200271 272 r = requests.get(url)274- self.assertEqual(r.status_code, 401)273+ assert r.status_code == 401274 275 s = requests.session()276 s.auth = HTTPDigestAuth('user', 'pass')277 r = s.get(url)279- self.assertEqual(r.status_code, 200)278+ assert r.status_code == 200279 280 def test_DIGEST_AUTH_RETURNS_COOKIE(self):281 url = httpbin('digest-auth', 'auth', 'user', 'pass')282 auth = HTTPDigestAuth('user', 'pass')15 unmodified lines298 auth = HTTPDigestAuth('user', 'pass')299 url = httpbin('digest-auth', 'auth', 'user', 'pass')300 301 r = requests.get(url, auth=auth, stream=True)303- self.assertNotEqual(r.raw.read(), b'')302+ assert r.raw.read() != b''303 304 r = requests.get(url, auth=auth, stream=False)306- self.assertEqual(r.raw.read(), b'')305+ assert r.raw.read() == b''306 308-307 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):308 309 auth = HTTPDigestAuth('user', 'wrongpass')310 url = httpbin('digest-auth', 'auth', 'user', 'pass')311 312 r = requests.get(url, auth=auth)315- self.assertEqual(r.status_code, 401)313+ assert r.status_code == 401314 315 r = requests.get(url)318- self.assertEqual(r.status_code, 401)316+ assert r.status_code == 401317 318 s = requests.session()319 s.auth = auth320 r = s.get(url)323- self.assertEqual(r.status_code, 401)321+ assert r.status_code == 401322 323 def test_POSTBIN_GET_POST_FILES(self):324 325 url = httpbin('post')326 post1 = requests.post(url).raise_for_status()327 328 post1 = requests.post(url, data={'some': 'data'})331- self.assertEqual(post1.status_code, 200)329+ assert post1.status_code == 200330 331 with open('requirements.txt') as f:332 post2 = requests.post(url, files={'some': f})335- self.assertEqual(post2.status_code, 200)333+ assert post2.status_code == 200334 335 post4 = requests.post(url, data='[{"some": "json"}]')338- self.assertEqual(post4.status_code, 200)336+ assert post4.status_code == 200337 340- try:341- requests.post(url, files=['bad file data'])342- except ValueError:343- pass338+ with pytest.raises(ValueError):339+ requests.post(url, files = ['bad file data'])340 341 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):342 343 url = httpbin('post')344 post1 = requests.post(url).raise_for_status()345 346 post1 = requests.post(url, data={'some': 'data'})351- self.assertEqual(post1.status_code, 200)347+ assert post1.status_code == 200348 349 with open('requirements.txt') as f:350 post2 = requests.post(url, data={'some': 'data'}, files={'some': f})355- self.assertEqual(post2.status_code, 200)351+ assert post2.status_code == 200352 353 post4 = requests.post(url, data='[{"some": "json"}]')358- self.assertEqual(post4.status_code, 200)354+ assert post4.status_code == 200355 360- try:361- requests.post(url, files=['bad file data'])362- except ValueError:363- pass356+ with pytest.raises(ValueError):357+ requests.post(url, files = ['bad file data'])358 359 def test_conflicting_post_params(self):360 url = httpbin('post')361 with open('requirements.txt') as f:1 unmodified line363 pytest.raises(ValueError, "requests.post(url, data=u'[{\"some\": \"data\"}]', files={'some': f})")364 365 def test_request_ok_set(self):366 r = requests.get(httpbin('status', '404'))373- self.assertEqual(r.ok, False)367+ assert not r.ok368 369 def test_status_raising(self):370 r = requests.get(httpbin('status', '404'))377- self.assertRaises(requests.exceptions.HTTPError, r.raise_for_status)371+ with pytest.raises(requests.exceptions.HTTPError):372+ r.raise_for_status()373 374 r = requests.get(httpbin('status', '500'))380- self.assertFalse(r.ok)375+ assert not r.ok376 377 def test_decompress_gzip(self):378 r = requests.get(httpbin('gzip'))379 r.content.decode('ascii')11 unmodified lines391 392 def test_urlencoded_get_query_multivalued_param(self):393 394 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))400- self.assertEqual(r.status_code, 200)401- self.assertEqual(r.url, httpbin('get?test=foo&test=baz'))395+ assert r.status_code == 200396+ assert r.url == httpbin('get?test=foo&test=baz')397 398 def test_different_encodings_dont_break_post(self):399 r = requests.post(httpbin('post'),400 data={'stuff': json.dumps({'a': 123})},401 params={'blah': 'asdf1234'},402 files={'file': ('test_requests.py', open(__file__, 'rb'))})408- self.assertEqual(r.status_code, 200)403+ assert r.status_code == 200404 405 def test_unicode_multipart_post(self):406 r = requests.post(httpbin('post'),407 data={'stuff': u'ëlïxr'},408 files={'file': ('test_requests.py', open(__file__, 'rb'))})414- self.assertEqual(r.status_code, 200)409+ assert r.status_code == 200410 411 r = requests.post(httpbin('post'),412 data={'stuff': u'ëlïxr'.encode('utf-8')},413 files={'file': ('test_requests.py', open(__file__, 'rb'))})419- self.assertEqual(r.status_code, 200)414+ assert r.status_code == 200415 416 r = requests.post(httpbin('post'),417 data={'stuff': 'elixr'},418 files={'file': ('test_requests.py', open(__file__, 'rb'))})424- self.assertEqual(r.status_code, 200)419+ assert r.status_code == 200420 421 r = requests.post(httpbin('post'),422 data={'stuff': 'elixr'.encode('utf-8')},423 files={'file': ('test_requests.py', open(__file__, 'rb'))})429- self.assertEqual(r.status_code, 200)424+ assert r.status_code == 200425 426 def test_unicode_multipart_post_fieldnames(self):427 filename = os.path.splitext(__file__)[0] + '.py'428 r = requests.Request(method='POST',1 unmodified line430 data={'stuff'.encode('utf-8'): 'elixr'},431 files={'file': ('test_requests.py',432 open(filename, 'rb'))})433 prep = r.prepare()439- self.assertTrue(b'name="stuff"' in prep.body)440- self.assertFalse(b'name="b\'stuff\'"' in prep.body)434+ assert b'name="stuff"' in prep.body435+ assert b'name="b\'stuff\'"' not in prep.body436 437 def test_custom_content_type(self):438 r = requests.post(httpbin('post'),439 data={'stuff': json.dumps({'a': 123})},440 files={'file1': ('test_requests.py', open(__file__, 'rb')),441 'file2': ('test_requests', open(__file__, 'rb'),442 'text/py-content-type')})448- self.assertEqual(r.status_code, 200)449- self.assertTrue(b"text/py-content-type" in r.request.body)443+ assert r.status_code == 200444+ assert b"text/py-content-type" in r.request.body445 446 def test_hook_receives_request_arguments(self):447 def hook(resp, **kwargs):448 assert resp is not None12 unmodified lines461 s = requests.Session()462 s.proxies = getproxies()463 resp = s.send(prep)464 470- self.assertTrue(hasattr(resp, 'hook_working'))465+ assert hasattr(resp, 'hook_working')466 467 def test_prepared_from_session(self):468 class DummyAuth(requests.auth.AuthBase):469 def __call__(self, r):470 r.headers['Dummy-Auth-Test'] = 'dummy-auth-test-ok'471 return r472 473 req = requests.Request('GET', httpbin('headers'))479- self.assertEqual(req.auth, None)474+ assert not req.auth475 476 s = requests.Session()477 s.auth = DummyAuth()478 479 prep = s.prepare_request(req)480 resp = s.send(prep)481 487- self.assertTrue(resp.json()['headers']['Dummy-Auth-Test'], 'dummy-auth-test-ok')482+ assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'483 484 def test_links(self):485 r = requests.Response()486 r.headers = {15 unmodified lines502 'x-github-media-type': 'github.beta',503 'x-ratelimit-limit': '60',504 'x-ratelimit-remaining': '57'505 }511- self.assertEqual(r.links['next']['rel'], 'next')506+ assert r.links['next']['rel'] == 'next'507 508 def test_cookie_parameters(self):509 key = 'some_cookie'510 value = 'some_value'3 unmodified lines514 515 jar = requests.cookies.RequestsCookieJar()516 jar.set(key, value, secure=secure, domain=domain, rest=rest)517 523- self.assertEqual(len(jar), 1)524- self.assertTrue('some_cookie' in jar)518+ assert len(jar) == 1519+ assert 'some_cookie' in jar520 521 cookie = list(jar)[0]527- self.assertEqual(cookie.secure, secure)528- self.assertEqual(cookie.domain, domain)529- self.assertEqual(cookie._rest['HttpOnly'], rest['HttpOnly'])522+ assert cookie.secure == secure523+ assert cookie.domain == domain524+ assert cookie._rest['HttpOnly'] == rest['HttpOnly']525 526 def test_time_elapsed_blank(self):527 r = requests.get(httpbin('get'))528 td = r.elapsed529 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)530 * 10**6) / 10**6)536- self.assertTrue(total_seconds > 0.0)531+ assert total_seconds > 0.0532 533 def test_response_is_iterable(self):534 r = requests.Response()535 io = StringIO.StringIO('abc')2 unmodified lines538 def read_mock(amt, decode_content=None):539 return read_(amt)540 setattr(io, 'read', read_mock)541 r.raw = io547- self.assertTrue(next(iter(r)))542+ assert next(iter(r))543 io.close()544 545 def test_get_auth_from_url(self):546 url = 'http://user:pass@complex.url.com/path?query=yes'552- self.assertEqual(('user', 'pass'),553- requests.utils.get_auth_from_url(url))547+ assert ('user', 'pass') == requests.utils.get_auth_from_url(url)548 549 def test_cannot_send_unprepared_requests(self):550 r = requests.Request(url=HTTPBIN)557- self.assertRaises(ValueError, requests.Session().send, r)551+ with pytest.raises(ValueError):552+ requests.Session().send(r)553 554 def test_http_error(self):555 error = requests.exceptions.HTTPError()561- self.assertEqual(error.response, None)556+ assert not error.response557 response = requests.Response()558 error = requests.exceptions.HTTPError(response=response)564- self.assertEqual(error.response, response)559+ assert error.response == response560 error = requests.exceptions.HTTPError('message', response=response)566- self.assertEqual(str(error), 'message')567- self.assertEqual(error.response, response)561+ assert str(error) == 'message'562+ assert error.response == response563 564 def test_session_pickling(self):565 r = requests.Request('GET', httpbin('get'))566 s = requests.Session()1 unmodified line568 s = pickle.loads(pickle.dumps(s))569 s.proxies = getproxies()570 571 r = s.send(r.prepare())577- self.assertEqual(r.status_code, 200)572+ assert r.status_code == 200573 574 def test_fixes_1329(self):575 """576 Ensure that header updates are done case-insensitively.2 unmodified lines579 s.headers.update({'ACCEPT': 'BOGUS'})580 s.headers.update({'accept': 'application/json'})581 r = s.get(httpbin('get'))582 headers = r.request.headers588- self.assertEqual(589- headers['accept'],590- 'application/json'591- )592- self.assertEqual(593- headers['Accept'],594- 'application/json'595- )596- self.assertEqual(597- headers['ACCEPT'],598- 'application/json'599- )583+ assert headers['accept'] == 'application/json'584+ assert headers['Accept'] == 'application/json'585+ assert headers['ACCEPT'] == 'application/json'586 587 def test_uppercase_scheme_redirect(self):588 parts = urlparse(httpbin('html'))589 url = "HTTP://" + parts.netloc + parts.path590 r = requests.get(httpbin('redirect-to'), params={'url': url})605- self.assertEqual(r.status_code, 200)606- self.assertEqual(r.url.lower(), url.lower())591+ assert r.status_code == 200592+ assert r.url.lower() == url.lower()593 594 def test_transport_adapter_ordering(self):595 s = requests.Session()596 order = ['https://', 'http://']611- self.assertEqual(order, list(s.adapters))597+ assert order == list(s.adapters)598 s.mount('http://git', HTTPAdapter())599 s.mount('http://github', HTTPAdapter())600 s.mount('http://github.com', HTTPAdapter())601 s.mount('http://github.com/about/', HTTPAdapter())4 unmodified lines606 'http://git',607 'https://',608 'http://',609 ]624- self.assertEqual(order, list(s.adapters))610+ assert order == list(s.adapters)611 s.mount('http://gittip', HTTPAdapter())612 s.mount('http://gittip.com', HTTPAdapter())613 s.mount('http://gittip.com/about/', HTTPAdapter())614 order = [6 unmodified lines621 'http://git',622 'https://',623 'http://',624 ]639- self.assertEqual(order, list(s.adapters))625+ assert order == list(s.adapters)626 s2 = requests.Session()627 s2.adapters = {'http://': HTTPAdapter()}628 s2.mount('https://', HTTPAdapter())643- self.assertTrue('http://' in s2.adapters)644- self.assertTrue('https://' in s2.adapters)629+ assert 'http://' in s2.adapters630+ assert 'https://' in s2.adapters631 632 def test_header_remove_is_case_insensitive(self):633 # From issue #1321634 s = requests.Session()14 unmodified lines649 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',650 'exactly-------------sixty-----------three------------characters',651 )652 r = requests.Request('GET', url).prepare()667- self.assertEqual(r.url, url)653+ assert r.url == url654 655 def test_header_keys_are_native(self):656 headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}657 r = requests.Request('GET', httpbin('get'), headers=headers)658 p = r.prepare()659 660 # This is testing that they are builtin strings. A bit weird, but there661 # we go.676- self.assertTrue('unicode' in p.headers.keys())677- self.assertTrue('byte' in p.headers.keys())662+ assert 'unicode' in p.headers.keys()663+ assert 'byte' in p.headers.keys()664 665 def test_can_send_nonstring_objects_with_files(self):666 data = {'a': 0.0}667 files = {'b': 'foo'}668 r = requests.Request('POST', httpbin('post'), data=data, files=files)669 p = r.prepare()670 685- self.assertTrue('multipart/form-data' in p.headers['Content-Type'])671+ assert 'multipart/form-data' in p.headers['Content-Type']672 673 def test_autoset_header_values_are_native(self):674 data = 'this is a string'675 length = '16'676 req = requests.Request('POST', httpbin('post'), data=data)677 p = req.prepare()678 693- self.assertEqual(p.headers['Content-Length'], length)679+ assert p.headers['Content-Length'] == length680 695-681 class TestContentEncodingDetection(unittest.TestCase):682 683 def test_none(self):684 encodings = requests.utils.get_encodings_from_content('')700- self.assertEqual(len(encodings), 0)685+ assert not len(encodings)686 687 def test_html_charset(self):688 """HTML5 meta charset attribute"""689 content = '<meta charset="UTF-8">'690 encodings = requests.utils.get_encodings_from_content(content)706- self.assertEqual(len(encodings), 1)707- self.assertEqual(encodings[0], 'UTF-8')691+ assert len(encodings) == 1692+ assert encodings[0] == 'UTF-8'693 694 def test_html4_pragma(self):695 """HTML4 pragma directive"""696 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">'697 encodings = requests.utils.get_encodings_from_content(content)713- self.assertEqual(len(encodings), 1)714- self.assertEqual(encodings[0], 'UTF-8')698+ assert len(encodings) == 1699+ assert encodings[0] == 'UTF-8'700 701 def test_xhtml_pragma(self):702 """XHTML 1.x served with text/html MIME type"""703 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />'704 encodings = requests.utils.get_encodings_from_content(content)720- self.assertEqual(len(encodings), 1)721- self.assertEqual(encodings[0], 'UTF-8')705+ assert len(encodings) == 1706+ assert encodings[0] == 'UTF-8'707 708 def test_xml(self):709 """XHTML 1.x served as XML"""710 content = '<?xml version="1.0" encoding="UTF-8"?>'711 encodings = requests.utils.get_encodings_from_content(content)727- self.assertEqual(len(encodings), 1)728- self.assertEqual(encodings[0], 'UTF-8')712+ assert len(encodings) == 1713+ assert encodings[0] == 'UTF-8'714 715 def test_precedence(self):716 content = '''717 <?xml version="1.0" encoding="XML"?>718 <meta charset="HTML5">719 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />720 '''.strip()721 encodings = requests.utils.get_encodings_from_content(content)737- self.assertEqual(encodings, ['HTML5', 'HTML4', 'XML'])722+ assert encodings == ['HTML5', 'HTML4', 'XML']723 724 725 class TestCaseInsensitiveDict(unittest.TestCase):726 727 def test_mapping_init(self):728 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})744- self.assertEqual(len(cid), 2)745- self.assertTrue('foo' in cid)746- self.assertTrue('bar' in cid)729+ assert len(cid) == 2730+ assert 'foo' in cid731+ assert 'bar' in cid732 733 def test_iterable_init(self):734 cid = CaseInsensitiveDict([('Foo', 'foo'), ('BAr', 'bar')])750- self.assertEqual(len(cid), 2)751- self.assertTrue('foo' in cid)752- self.assertTrue('bar' in cid)735+ assert len(cid) == 2736+ assert 'foo' in cid737+ assert 'bar' in cid738 739 def test_kwargs_init(self):740 cid = CaseInsensitiveDict(FOO='foo', BAr='bar')756- self.assertEqual(len(cid), 2)757- self.assertTrue('foo' in cid)758- self.assertTrue('bar' in cid)741+ assert len(cid) == 2742+ assert 'foo' in cid743+ assert 'bar' in cid744 745 def test_docstring_example(self):746 cid = CaseInsensitiveDict()747 cid['Accept'] = 'application/json'763- self.assertEqual(cid['aCCEPT'], 'application/json')764- self.assertEqual(list(cid), ['Accept'])748+ assert cid['aCCEPT'] == 'application/json'749+ assert list(cid) == ['Accept']750 751 def test_len(self):752 cid = CaseInsensitiveDict({'a': 'a', 'b': 'b'})753 cid['A'] = 'a'769- self.assertEqual(len(cid), 2)754+ assert len(cid) == 2755 756 def test_getitem(self):757 cid = CaseInsensitiveDict({'Spam': 'blueval'})773- self.assertEqual(cid['spam'], 'blueval')774- self.assertEqual(cid['SPAM'], 'blueval')758+ assert cid['spam'] == 'blueval'759+ assert cid['SPAM'] == 'blueval'760 761 def test_fixes_649(self):762 """__setitem__ should behave case-insensitively."""763 cid = CaseInsensitiveDict()764 cid['spam'] = 'oneval'765 cid['Spam'] = 'twoval'766 cid['sPAM'] = 'redval'767 cid['SPAM'] = 'blueval'783- self.assertEqual(cid['spam'], 'blueval')784- self.assertEqual(cid['SPAM'], 'blueval')785- self.assertEqual(list(cid.keys()), ['SPAM'])768+ assert cid['spam'] == 'blueval'769+ assert cid['SPAM'] == 'blueval'770+ assert list(cid.keys()) == ['SPAM']771 772 def test_delitem(self):773 cid = CaseInsensitiveDict()774 cid['Spam'] = 'someval'775 del cid['sPam']791- self.assertFalse('spam' in cid)792- self.assertEqual(len(cid), 0)776+ assert 'spam' not in cid777+ assert len(cid) == 0778 779 def test_contains(self):780 cid = CaseInsensitiveDict()781 cid['Spam'] = 'someval'797- self.assertTrue('Spam' in cid)798- self.assertTrue('spam' in cid)799- self.assertTrue('SPAM' in cid)800- self.assertTrue('sPam' in cid)801- self.assertFalse('notspam' in cid)782+ assert 'Spam' in cid783+ assert 'spam' in cid784+ assert 'SPAM' in cid785+ assert 'sPam' in cid786+ assert 'notspam' not in cid787 788 def test_get(self):789 cid = CaseInsensitiveDict()790 cid['spam'] = 'oneval'791 cid['SPAM'] = 'blueval'807- self.assertEqual(cid.get('spam'), 'blueval')808- self.assertEqual(cid.get('SPAM'), 'blueval')809- self.assertEqual(cid.get('sPam'), 'blueval')810- self.assertEqual(cid.get('notspam', 'default'), 'default')792+ assert cid.get('spam') == 'blueval'793+ assert cid.get('SPAM') == 'blueval'794+ assert cid.get('sPam') == 'blueval'795+ assert cid.get('notspam', 'default') == 'default'796 797 def test_update(self):798 cid = CaseInsensitiveDict()799 cid['spam'] = 'blueval'800 cid.update({'sPam': 'notblueval'})816- self.assertEqual(cid['spam'], 'notblueval')801+ assert cid['spam'] == 'notblueval'802 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})803 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})819- self.assertEqual(len(cid), 2)820- self.assertEqual(cid['foo'], 'anotherfoo')821- self.assertEqual(cid['bar'], 'anotherbar')804+ assert len(cid) == 2805+ assert cid['foo'] == 'anotherfoo'806+ assert cid['bar'] == 'anotherbar'807 808 def test_update_retains_unchanged(self):809 cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})810 cid.update({'foo': 'newfoo'})826- self.assertEquals(cid['bar'], 'bar')811+ assert cid['bar'] == 'bar'812 813 def test_iter(self):814 cid = CaseInsensitiveDict({'Spam': 'spam', 'Eggs': 'eggs'})815 keys = frozenset(['Spam', 'Eggs'])831- self.assertEqual(frozenset(iter(cid)), keys)816+ assert frozenset(iter(cid)) == keys817 818 def test_equality(self):819 cid = CaseInsensitiveDict({'SPAM': 'blueval', 'Eggs': 'redval'})820 othercid = CaseInsensitiveDict({'spam': 'blueval', 'eggs': 'redval'})836- self.assertEqual(cid, othercid)821+ assert cid == othercid822 del othercid['spam']838- self.assertNotEqual(cid, othercid)839- self.assertEqual(cid, {'spam': 'blueval', 'eggs': 'redval'})823+ assert cid != othercid824+ assert cid == {'spam': 'blueval', 'eggs': 'redval'}825 826 def test_setdefault(self):827 cid = CaseInsensitiveDict({'Spam': 'blueval'})843- self.assertEqual(844- cid.setdefault('spam', 'notblueval'),845- 'blueval'846- )847- self.assertEqual(848- cid.setdefault('notspam', 'notblueval'),849- 'notblueval'850- )828+ assert cid.setdefault('spam', 'notblueval') == 'blueval'829+ assert cid.setdefault('notspam', 'notblueval') == 'notblueval'830 831 def test_lower_items(self):832 cid = CaseInsensitiveDict({833 'Accept': 'application/json',834 'user-Agent': 'requests',835 })836 keyset = frozenset(lowerkey for lowerkey, v in cid.lower_items())837 lowerkeyset = frozenset(['accept', 'user-agent'])859- self.assertEqual(keyset, lowerkeyset)838+ assert keyset == lowerkeyset839 840 def test_preserve_key_case(self):841 cid = CaseInsensitiveDict({842 'Accept': 'application/json',843 'user-Agent': 'requests',844 })845 keyset = frozenset(['Accept', 'user-Agent'])867- self.assertEqual(frozenset(i[0] for i in cid.items()), keyset)868- self.assertEqual(frozenset(cid.keys()), keyset)869- self.assertEqual(frozenset(cid), keyset)846+ assert frozenset(i[0] for i in cid.items()) == keyset847+ assert frozenset(cid.keys()) == keyset848+ assert frozenset(cid) == keyset849 850 def test_preserve_last_key_case(self):851 cid = CaseInsensitiveDict({852 'Accept': 'application/json',1 unmodified line854 })855 cid.update({'ACCEPT': 'application/json'})856 cid['USER-AGENT'] = 'requests'857 keyset = frozenset(['ACCEPT', 'USER-AGENT'])879- self.assertEqual(frozenset(i[0] for i in cid.items()), keyset)880- self.assertEqual(frozenset(cid.keys()), keyset)881- self.assertEqual(frozenset(cid), keyset)858+ assert frozenset(i[0] for i in cid.items()) == keyset859+ assert frozenset(cid.keys()) == keyset860+ assert frozenset(cid) == keyset861 862 863 class UtilsTestCase(unittest.TestCase):864 2 unmodified lines867 # uses StringIO or io.StringIO (see import above)868 from io import BytesIO869 from requests.utils import super_len870 892- self.assertEqual(super_len(StringIO.StringIO()), 0)893- self.assertEqual(super_len(StringIO.StringIO('with so much drama in the LBC')), 29)871+ assert super_len(StringIO.StringIO()) == 0872+ assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 29873 895- self.assertEqual(super_len(BytesIO()), 0)896- self.assertEqual(super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")), 40)874+ assert super_len(BytesIO()) == 0875+ assert super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 40876 877 try:878 import cStringIO879 except ImportError:880 pass881 else:903- self.assertEqual(super_len(cStringIO.StringIO('but some how, some way...')), 25)882+ assert super_len(cStringIO.StringIO('but some how, some way...')) == 25883 884 if __name__ == '__main__':885 unittest.main()