diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-08-08 16:16:07 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-08-08 16:16:07 (GMT) |
commit | 419e384601c6af03feddace9c0254e7f3920b141 (patch) | |
tree | 188283fdd726f6559125812b4c55bb29d15120ea /Lib/test/test_urllib2.py | |
parent | 1f594ad424311fc3fb558a9ddfb126c5c9a0287e (diff) | |
download | cpython-419e384601c6af03feddace9c0254e7f3920b141.zip cpython-419e384601c6af03feddace9c0254e7f3920b141.tar.gz cpython-419e384601c6af03feddace9c0254e7f3920b141.tar.bz2 |
Use unittest specific methods for some urllib test cases. And replace urllib2 with urllib.request in comments.
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r-- | Lib/test/test_urllib2.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 02dc83c..5a168ee 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -41,7 +41,7 @@ class TrivialTests(unittest.TestCase): ('a="b\\"c", d="e\\,f", g="h\\\\i"', ['a="b"c"', 'd="e,f"', 'g="h\\i"'])] for string, list in tests: - self.assertEquals(urllib.request.parse_http_list(string), list) + self.assertEqual(urllib.request.parse_http_list(string), list) def test_request_headers_dict(): @@ -743,9 +743,9 @@ class HandlerTests(unittest.TestCase): h.file_open(req) # XXXX remove OSError when bug fixed except (urllib.error.URLError, OSError): - self.assertTrue(not ftp) + self.assertFalse(ftp) else: - self.assertTrue(o.req is req) + self.assertIs(o.req, req) self.assertEqual(req.type, "ftp") self.assertEqual(req.type is "ftp", ftp) @@ -848,19 +848,19 @@ class HandlerTests(unittest.TestCase): # all 2xx are passed through r = MockResponse(200, "OK", {}, "", url) newr = h.http_response(req, r) - self.assertTrue(r is newr) - self.assertTrue(not hasattr(o, "proto")) # o.error not called + self.assertIs(r, newr) + self.assertFalse(hasattr(o, "proto")) # o.error not called r = MockResponse(202, "Accepted", {}, "", url) newr = h.http_response(req, r) - self.assertTrue(r is newr) - self.assertTrue(not hasattr(o, "proto")) # o.error not called + self.assertIs(r, newr) + self.assertFalse(hasattr(o, "proto")) # o.error not called r = MockResponse(206, "Partial content", {}, "", url) newr = h.http_response(req, r) - self.assertTrue(r is newr) - self.assertTrue(not hasattr(o, "proto")) # o.error not called + self.assertIs(r, newr) + self.assertFalse(hasattr(o, "proto")) # o.error not called # anything else calls o.error (and MockOpener returns None, here) r = MockResponse(502, "Bad gateway", {}, "", url) - self.assertTrue(h.http_response(req, r) is None) + self.assertIsNone(h.http_response(req, r)) self.assertEqual(o.proto, "http") # o.error called self.assertEqual(o.args, (req, r, 502, "Bad gateway", {})) @@ -872,12 +872,14 @@ class HandlerTests(unittest.TestCase): req = Request("http://example.com/") r = MockResponse(200, "OK", {}, "") newreq = h.http_request(req) - self.assertTrue(cj.ach_req is req is newreq) - self.assertEquals(req.get_origin_req_host(), "example.com") - self.assertTrue(not req.is_unverifiable()) + self.assertIs(cj.ach_req, req) + self.assertIs(cj.ach_req, newreq) + self.assertEqual(req.get_origin_req_host(), "example.com") + self.assertFalse(req.is_unverifiable()) newr = h.http_response(req, r) - self.assertTrue(cj.ec_req is req) - self.assertTrue(cj.ec_r is r is newr) + self.assertIs(cj.ec_req, req) + self.assertIs(cj.ec_r, r) + self.assertIs(r, newr) def test_redirect(self): from_url = "http://example.com/a.html" @@ -905,7 +907,7 @@ class HandlerTests(unittest.TestCase): try: self.assertEqual(o.req.get_method(), "GET") except AttributeError: - self.assertTrue(not o.req.has_data()) + self.assertFalse(o.req.has_data()) # now it's a GET, there should not be headers regarding content # (possibly dragged from before being a POST) @@ -964,7 +966,7 @@ class HandlerTests(unittest.TestCase): cp = urllib.request.HTTPCookieProcessor(cj) o = build_test_opener(hh, hdeh, hrh, cp) o.open("http://www.example.com/") - self.assertTrue(not hh.req.has_header("Cookie")) + self.assertFalse(hh.req.has_header("Cookie")) def test_proxy(self): o = OpenerDirector() @@ -1198,11 +1200,8 @@ class MiscTests(unittest.TestCase): self.opener_has_handler(o, MyOtherHTTPHandler) def opener_has_handler(self, opener, handler_class): - for h in opener.handlers: - if h.__class__ == handler_class: - break - else: - self.assertTrue(False) + self.assertTrue(any(h.__class__ == handler_class + for h in opener.handlers)) class RequestTests(unittest.TestCase): @@ -1217,7 +1216,7 @@ class RequestTests(unittest.TestCase): self.assertEqual("GET", self.get.get_method()) def test_add_data(self): - self.assertTrue(not self.get.has_data()) + self.assertFalse(self.get.has_data()) self.assertEqual("GET", self.get.get_method()) self.get.add_data("spam") self.assertTrue(self.get.has_data()) @@ -1243,7 +1242,7 @@ class RequestTests(unittest.TestCase): self.assertEqual("www.python.org", req.get_host()) def test_proxy(self): - self.assertTrue(not self.get.has_proxy()) + self.assertFalse(self.get.has_proxy()) self.get.set_proxy("www.perl.org", "http") self.assertTrue(self.get.has_proxy()) self.assertEqual("www.python.org", self.get.get_origin_req_host()) |