[Python-checkins] python/dist/src/Lib/test test_urlparse.py, 1.13,
1.13.4.1
jlgijsbers at users.sourceforge.net
jlgijsbers at users.sourceforge.net
Sun Jan 9 16:32:40 CET 2005
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29436/test
Modified Files:
Tag: release24-maint
test_urlparse.py
Log Message:
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
treat '?' as a delimiter. Previously, the 'network location' (<authority> in
RFC 2396) would become 'www.example.com?query=spam', while RFC 2396 does not
allow a '?' in <authority>. See bug #548176 for further discussion.
Index: test_urlparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_urlparse.py,v
retrieving revision 1.13
retrieving revision 1.13.4.1
diff -u -d -r1.13 -r1.13.4.1
--- test_urlparse.py 12 Oct 2003 04:38:06 -0000 1.13
+++ test_urlparse.py 9 Jan 2005 15:32:37 -0000 1.13.4.1
@@ -8,20 +8,22 @@
RFC2396_BASE = "http://a/b/c/d;p?q"
class UrlParseTestCase(unittest.TestCase):
- def test_frags(self):
- for url, parsed, split in [
- ('http://www.python.org',
- ('http', 'www.python.org', '', '', '', ''),
- ('http', 'www.python.org', '', '', '')),
- ('http://www.python.org#abc',
- ('http', 'www.python.org', '', '', '', 'abc'),
- ('http', 'www.python.org', '', '', 'abc')),
- ('http://www.python.org/#abc',
- ('http', 'www.python.org', '/', '', '', 'abc'),
- ('http', 'www.python.org', '/', '', 'abc')),
- (RFC1808_BASE,
- ('http', 'a', '/b/c/d', 'p', 'q', 'f'),
- ('http', 'a', '/b/c/d;p', 'q', 'f')),
+
+ def checkRoundtrips(self, url, parsed, split):
+ result = urlparse.urlparse(url)
+ self.assertEqual(result, parsed)
+ # put it back together and it should be the same
+ result2 = urlparse.urlunparse(result)
+ self.assertEqual(result2, url)
+
+ # check the roundtrip using urlsplit() as well
+ result = urlparse.urlsplit(url)
+ self.assertEqual(result, split)
+ result2 = urlparse.urlunsplit(result)
+ self.assertEqual(result2, url)
+
+ def test_roundtrips(self):
+ testcases = [
('file:///tmp/junk.txt',
('file', '', '/tmp/junk.txt', '', '', ''),
('file', '', '/tmp/junk.txt', '', '')),
@@ -29,20 +31,41 @@
('imap', 'mail.python.org', '/mbox1', '', '', ''),
('imap', 'mail.python.org', '/mbox1', '', '')),
('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf',
- ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '', ''),
- ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '')),
- ]:
- result = urlparse.urlparse(url)
- self.assertEqual(result, parsed)
- # put it back together and it should be the same
- result2 = urlparse.urlunparse(result)
- self.assertEqual(result2, url)
+ ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
+ '', '', ''),
+ ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
+ '', '')),
+ ]
+ for url, parsed, split in testcases:
+ self.checkRoundtrips(url, parsed, split)
- # check the roundtrip using urlsplit() as well
- result = urlparse.urlsplit(url)
- self.assertEqual(result, split)
- result2 = urlparse.urlunsplit(result)
- self.assertEqual(result2, url)
+ def test_http_roundtrips(self):
+ # urlparse.urlsplit treats 'http:' as an optimized special case,
+ # so we test both 'http:' and 'https:' in all the following.
+ # Three cheers for white box knowledge!
+ testcases = [
+ ('://www.python.org',
+ ('www.python.org', '', '', '', ''),
+ ('www.python.org', '', '', '')),
+ ('://www.python.org#abc',
+ ('www.python.org', '', '', '', 'abc'),
+ ('www.python.org', '', '', 'abc')),
+ ('://www.python.org?q=abc',
+ ('www.python.org', '', '', 'q=abc', ''),
+ ('www.python.org', '', 'q=abc', '')),
+ ('://www.python.org/#abc',
+ ('www.python.org', '/', '', '', 'abc'),
+ ('www.python.org', '/', '', 'abc')),
+ ('://a/b/c/d;p?q#f',
+ ('a', '/b/c/d', 'p', 'q', 'f'),
+ ('a', '/b/c/d;p', 'q', 'f')),
+ ]
+ for scheme in ('http', 'https'):
+ for url, parsed, split in testcases:
+ url = scheme + url
+ parsed = (scheme,) + parsed
+ split = (scheme,) + split
+ self.checkRoundtrips(url, parsed, split)
def checkJoin(self, base, relurl, expected):
self.assertEqual(urlparse.urljoin(base, relurl), expected,
More information about the Python-checkins
mailing list