[Python-checkins] cpython: Fix Issue 15743 - improve urllib tests by removing deprecated method usages.

senthil.kumaran python-checkins at python.org
Mon Aug 20 22:46:26 CEST 2012


http://hg.python.org/cpython/rev/9b28dff66ac3
changeset:   78685:9b28dff66ac3
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Mon Aug 20 13:43:59 2012 -0700
summary:
  Fix Issue 15743 - improve urllib tests by removing deprecated method usages. Patch by Jeff Knupp.

files:
  Lib/test/test_urllib2.py |  64 ++++++++++++++-------------
  Misc/NEWS                |   3 +
  2 files changed, 36 insertions(+), 31 deletions(-)


diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -622,10 +622,10 @@
         with self.assertWarns(DeprecationWarning):
             req.add_data("data")
         with self.assertWarns(DeprecationWarning):
+            req.get_data()
+        with self.assertWarns(DeprecationWarning):
             req.has_data()
         with self.assertWarns(DeprecationWarning):
-            req.get_data()
-        with self.assertWarns(DeprecationWarning):
             req.get_host()
         with self.assertWarns(DeprecationWarning):
             req.get_selector()
@@ -633,6 +633,8 @@
             req.is_unverifiable()
         with self.assertWarns(DeprecationWarning):
             req.get_origin_req_host()
+        with self.assertWarns(DeprecationWarning):
+            req.get_type()
 
 
 def sanepathname2url(path):
@@ -989,8 +991,8 @@
         newreq = h.http_request(req)
         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())
+        self.assertEqual(req.origin_req_host, "example.com")
+        self.assertFalse(req.unverifiable)
         newr = h.http_response(req, r)
         self.assertIs(cj.ec_req, req)
         self.assertIs(cj.ec_r, r)
@@ -1022,7 +1024,7 @@
                 try:
                     self.assertEqual(o.req.get_method(), "GET")
                 except AttributeError:
-                    self.assertFalse(o.req.has_data())
+                    self.assertFalse(o.req.data)
 
                 # now it's a GET, there should not be headers regarding content
                 # (possibly dragged from before being a POST)
@@ -1138,9 +1140,9 @@
         handlers = add_ordered_mock_handlers(o, meth_spec)
 
         req = Request("http://acme.example.com/")
-        self.assertEqual(req.get_host(), "acme.example.com")
+        self.assertEqual(req.host, "acme.example.com")
         r = o.open(req)
-        self.assertEqual(req.get_host(), "proxy.example.com:3128")
+        self.assertEqual(req.host, "proxy.example.com:3128")
 
         self.assertEqual([(handlers[0], "http_open")],
                          [tup[0:2] for tup in o.calls])
@@ -1151,13 +1153,13 @@
         ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
         o.add_handler(ph)
         req = Request("http://www.perl.org/")
-        self.assertEqual(req.get_host(), "www.perl.org")
+        self.assertEqual(req.host, "www.perl.org")
         r = o.open(req)
-        self.assertEqual(req.get_host(), "proxy.example.com")
+        self.assertEqual(req.host, "proxy.example.com")
         req = Request("http://www.python.org")
-        self.assertEqual(req.get_host(), "www.python.org")
+        self.assertEqual(req.host, "www.python.org")
         r = o.open(req)
-        self.assertEqual(req.get_host(), "www.python.org")
+        self.assertEqual(req.host, "www.python.org")
         del os.environ['no_proxy']
 
     def test_proxy_no_proxy_all(self):
@@ -1166,9 +1168,9 @@
         ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
         o.add_handler(ph)
         req = Request("http://www.python.org")
-        self.assertEqual(req.get_host(), "www.python.org")
+        self.assertEqual(req.host, "www.python.org")
         r = o.open(req)
-        self.assertEqual(req.get_host(), "www.python.org")
+        self.assertEqual(req.host, "www.python.org")
         del os.environ['no_proxy']
 
 
@@ -1182,9 +1184,9 @@
         handlers = add_ordered_mock_handlers(o, meth_spec)
 
         req = Request("https://www.example.com/")
-        self.assertEqual(req.get_host(), "www.example.com")
+        self.assertEqual(req.host, "www.example.com")
         r = o.open(req)
-        self.assertEqual(req.get_host(), "proxy.example.com:3128")
+        self.assertEqual(req.host, "proxy.example.com:3128")
         self.assertEqual([(handlers[0], "https_open")],
                          [tup[0:2] for tup in o.calls])
 
@@ -1197,7 +1199,7 @@
         req = Request("https://www.example.com/")
         req.add_header("Proxy-Authorization","FooBar")
         req.add_header("User-Agent","Grail")
-        self.assertEqual(req.get_host(), "www.example.com")
+        self.assertEqual(req.host, "www.example.com")
         self.assertIsNone(req._tunnel_host)
         r = o.open(req)
         # Verify Proxy-Authorization gets tunneled to request.
@@ -1208,7 +1210,7 @@
         self.assertIn(("User-Agent","Grail"),
                       https_handler.httpconn.req_headers)
         self.assertIsNotNone(req._tunnel_host)
-        self.assertEqual(req.get_host(), "proxy.example.com:3128")
+        self.assertEqual(req.host, "proxy.example.com:3128")
         self.assertEqual(req.get_header("Proxy-authorization"),"FooBar")
 
     # TODO: This should be only for OSX
@@ -1445,11 +1447,11 @@
         self.assertEqual("POST", self.post.get_method())
         self.assertEqual("GET", self.get.get_method())
 
-    def test_add_data(self):
-        self.assertFalse(self.get.has_data())
+    def test_data(self):
+        self.assertFalse(self.get.data)
         self.assertEqual("GET", self.get.get_method())
-        self.get.add_data("spam")
-        self.assertTrue(self.get.has_data())
+        self.get.data = "spam"
+        self.assertTrue(self.get.data)
         self.assertEqual("POST", self.get.get_method())
 
     def test_get_full_url(self):
@@ -1457,36 +1459,36 @@
                          self.get.get_full_url())
 
     def test_selector(self):
-        self.assertEqual("/~jeremy/", self.get.get_selector())
+        self.assertEqual("/~jeremy/", self.get.selector)
         req = Request("http://www.python.org/")
-        self.assertEqual("/", req.get_selector())
+        self.assertEqual("/", req.selector)
 
     def test_get_type(self):
-        self.assertEqual("http", self.get.get_type())
+        self.assertEqual("http", self.get.type)
 
     def test_get_host(self):
-        self.assertEqual("www.python.org", self.get.get_host())
+        self.assertEqual("www.python.org", self.get.host)
 
     def test_get_host_unquote(self):
         req = Request("http://www.%70ython.org/")
-        self.assertEqual("www.python.org", req.get_host())
+        self.assertEqual("www.python.org", req.host)
 
     def test_proxy(self):
         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())
-        self.assertEqual("www.perl.org", self.get.get_host())
+        self.assertEqual("www.python.org", self.get.origin_req_host)
+        self.assertEqual("www.perl.org", self.get.host)
 
     def test_wrapped_url(self):
         req = Request("<URL:http://www.python.org>")
-        self.assertEqual("www.python.org", req.get_host())
+        self.assertEqual("www.python.org", req.host)
 
     def test_url_fragment(self):
         req = Request("http://www.python.org/?qs=query#fragment=true")
-        self.assertEqual("/?qs=query", req.get_selector())
+        self.assertEqual("/?qs=query", req.selector)
         req = Request("http://www.python.org/#fun=true")
-        self.assertEqual("/", req.get_selector())
+        self.assertEqual("/", req.selector)
 
         # Issue 11703: geturl() omits fragment in the original URL.
         url = 'http://docs.python.org/library/urllib2.html#OK'
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -86,6 +86,9 @@
 Tests
 -----
 
+- Issue #15743: Remove the deprecated method usage in urllib tests. Patch by
+  Jeff Knupp.
+
 - Issue #15615: Add some tests for the json module's handling of invalid
   input data.  Patch by Kushal Das.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list