summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2014-04-14 16:32:20 -0400
committerSenthil Kumaran <senthil@uthcode.com>2014-04-14 16:32:20 -0400
commitd8e24f1f716d32237f780e31c45431c5c458ff26 (patch)
treeea4ff5051faee077db392b3b670e05f0baa72c0c /Lib/test
parent01bafdcccc4ab653f70379a58a3183fac36e7132 (diff)
downloadcpython-git-d8e24f1f716d32237f780e31c45431c5c458ff26.tar.gz
Convert urllib.request parse_proxy doctests to unittests.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_urllib2.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 6272105e2a..6b73723a6e 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -10,7 +10,7 @@ import sys
import urllib.request
# The proxy bypass method imported below has logic specific to the OSX
# proxy config data structure but is testable on all platforms.
-from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf
+from urllib.request import Request, OpenerDirector, _parse_proxy, _proxy_bypass_macosx_sysconf
from urllib.parse import urlparse
import urllib.error
@@ -1467,6 +1467,43 @@ class MiscTests(unittest.TestCase):
expected_errmsg = 'HTTP Error %s: %s' % (err.code, err.msg)
self.assertEqual(str(err), expected_errmsg)
+ def test_parse_proxy(self):
+ parse_proxy_test_cases = [
+ ('proxy.example.com',
+ (None, None, None, 'proxy.example.com')),
+ ('proxy.example.com:3128',
+ (None, None, None, 'proxy.example.com:3128')),
+ ('proxy.example.com', (None, None, None, 'proxy.example.com')),
+ ('proxy.example.com:3128',
+ (None, None, None, 'proxy.example.com:3128')),
+ # The authority component may optionally include userinfo
+ # (assumed to be # username:password):
+ ('joe:password@proxy.example.com',
+ (None, 'joe', 'password', 'proxy.example.com')),
+ ('joe:password@proxy.example.com:3128',
+ (None, 'joe', 'password', 'proxy.example.com:3128')),
+ #Examples with URLS
+ ('http://proxy.example.com/',
+ ('http', None, None, 'proxy.example.com')),
+ ('http://proxy.example.com:3128/',
+ ('http', None, None, 'proxy.example.com:3128')),
+ ('http://joe:password@proxy.example.com/',
+ ('http', 'joe', 'password', 'proxy.example.com')),
+ ('http://joe:password@proxy.example.com:3128',
+ ('http', 'joe', 'password', 'proxy.example.com:3128')),
+ # Everything after the authority is ignored
+ ('ftp://joe:password@proxy.example.com/rubbish:3128',
+ ('ftp', 'joe', 'password', 'proxy.example.com')),
+ # Test for no trailing '/' case
+ ('http://joe:password@proxy.example.com',
+ ('http', 'joe', 'password', 'proxy.example.com'))
+ ]
+
+ for tc, expected in parse_proxy_test_cases:
+ self.assertEqual(_parse_proxy(tc), expected)
+
+ self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
+
class RequestTests(unittest.TestCase):
class PutRequest(Request):
method='PUT'