blob: 16bc1332f5da7d29d7ac7f363e3ae24438812ee4 [file] [log] [blame]
Skip Montanaro6ec967d2002-03-23 05:32:10 +00001#! /usr/bin/env python
2
Benjamin Petersonee8712c2008-05-20 21:35:26 +00003from test import support
Skip Montanaro6ec967d2002-03-23 05:32:10 +00004import unittest
Jeremy Hylton1afc1692008-06-18 20:49:58 +00005import urllib.parse
Fred Drakea4d18a02001-01-05 05:57:04 +00006
Fred Drakea4d18a02001-01-05 05:57:04 +00007RFC1808_BASE = "http://a/b/c/d;p?q#f"
Skip Montanaro6ec967d2002-03-23 05:32:10 +00008RFC2396_BASE = "http://a/b/c/d;p?q"
Facundo Batista23e38562008-08-14 16:55:14 +00009RFC3986_BASE = "http://a/b/c/d;p?q"
Fred Drakea4d18a02001-01-05 05:57:04 +000010
Facundo Batistac469d4c2008-09-03 22:49:01 +000011# A list of test cases. Each test case is a a two-tuple that contains
12# a string with the query and a dictionary with the expected result.
13
14parse_qsl_test_cases = [
15 ("", []),
16 ("&", []),
17 ("&&", []),
18 ("=", [('', '')]),
19 ("=a", [('', 'a')]),
20 ("a", [('a', '')]),
21 ("a=", [('a', '')]),
22 ("a=", [('a', '')]),
23 ("&a=b", [('a', 'b')]),
24 ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]),
25 ("a=1&a=2", [('a', '1'), ('a', '2')]),
26]
27
Skip Montanaro6ec967d2002-03-23 05:32:10 +000028class UrlParseTestCase(unittest.TestCase):
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000029
30 def checkRoundtrips(self, url, parsed, split):
Jeremy Hylton1afc1692008-06-18 20:49:58 +000031 result = urllib.parse.urlparse(url)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000032 self.assertEqual(result, parsed)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000033 t = (result.scheme, result.netloc, result.path,
34 result.params, result.query, result.fragment)
35 self.assertEqual(t, parsed)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000036 # put it back together and it should be the same
Jeremy Hylton1afc1692008-06-18 20:49:58 +000037 result2 = urllib.parse.urlunparse(result)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000038 self.assertEqual(result2, url)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000039 self.assertEqual(result2, result.geturl())
40
41 # the result of geturl() is a fixpoint; we can always parse it
42 # again to get the same result:
Jeremy Hylton1afc1692008-06-18 20:49:58 +000043 result3 = urllib.parse.urlparse(result.geturl())
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000044 self.assertEqual(result3.geturl(), result.geturl())
45 self.assertEqual(result3, result)
46 self.assertEqual(result3.scheme, result.scheme)
47 self.assertEqual(result3.netloc, result.netloc)
48 self.assertEqual(result3.path, result.path)
49 self.assertEqual(result3.params, result.params)
50 self.assertEqual(result3.query, result.query)
51 self.assertEqual(result3.fragment, result.fragment)
52 self.assertEqual(result3.username, result.username)
53 self.assertEqual(result3.password, result.password)
54 self.assertEqual(result3.hostname, result.hostname)
55 self.assertEqual(result3.port, result.port)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000056
57 # check the roundtrip using urlsplit() as well
Jeremy Hylton1afc1692008-06-18 20:49:58 +000058 result = urllib.parse.urlsplit(url)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000059 self.assertEqual(result, split)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000060 t = (result.scheme, result.netloc, result.path,
61 result.query, result.fragment)
62 self.assertEqual(t, split)
Jeremy Hylton1afc1692008-06-18 20:49:58 +000063 result2 = urllib.parse.urlunsplit(result)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000064 self.assertEqual(result2, url)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000065 self.assertEqual(result2, result.geturl())
66
67 # check the fixpoint property of re-parsing the result of geturl()
Jeremy Hylton1afc1692008-06-18 20:49:58 +000068 result3 = urllib.parse.urlsplit(result.geturl())
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000069 self.assertEqual(result3.geturl(), result.geturl())
70 self.assertEqual(result3, result)
71 self.assertEqual(result3.scheme, result.scheme)
72 self.assertEqual(result3.netloc, result.netloc)
73 self.assertEqual(result3.path, result.path)
74 self.assertEqual(result3.query, result.query)
75 self.assertEqual(result3.fragment, result.fragment)
76 self.assertEqual(result3.username, result.username)
77 self.assertEqual(result3.password, result.password)
78 self.assertEqual(result3.hostname, result.hostname)
79 self.assertEqual(result3.port, result.port)
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000080
Facundo Batistac469d4c2008-09-03 22:49:01 +000081 def test_qsl(self):
82 for orig, expect in parse_qsl_test_cases:
83 result = urllib.parse.parse_qsl(orig, keep_blank_values=True)
84 self.assertEqual(result, expect, "Error parsing %s" % repr(orig))
85
86
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000087 def test_roundtrips(self):
88 testcases = [
Fred Drake70705652002-10-16 21:02:36 +000089 ('file:///tmp/junk.txt',
90 ('file', '', '/tmp/junk.txt', '', '', ''),
91 ('file', '', '/tmp/junk.txt', '', '')),
Neal Norwitz68b539e2003-01-06 06:58:31 +000092 ('imap://mail.python.org/mbox1',
93 ('imap', 'mail.python.org', '/mbox1', '', '', ''),
94 ('imap', 'mail.python.org', '/mbox1', '', '')),
Skip Montanarof09b88e2003-01-06 20:27:03 +000095 ('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf',
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +000096 ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
97 '', '', ''),
98 ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
99 '', '')),
Fred Drake50747fc2005-07-29 15:56:32 +0000100 ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/',
101 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
102 '', '', ''),
103 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
104 '', ''))
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +0000105 ]
106 for url, parsed, split in testcases:
107 self.checkRoundtrips(url, parsed, split)
Michael W. Hudsonbd3e7712002-03-18 13:06:00 +0000108
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +0000109 def test_http_roundtrips(self):
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000110 # urllib.parse.urlsplit treats 'http:' as an optimized special case,
Johannes Gijsbers41e4faa2005-01-09 15:29:10 +0000111 # so we test both 'http:' and 'https:' in all the following.
112 # Three cheers for white box knowledge!
113 testcases = [
114 ('://www.python.org',
115 ('www.python.org', '', '', '', ''),
116 ('www.python.org', '', '', '')),
117 ('://www.python.org#abc',
118 ('www.python.org', '', '', '', 'abc'),
119 ('www.python.org', '', '', 'abc')),
120 ('://www.python.org?q=abc',
121 ('www.python.org', '', '', 'q=abc', ''),
122 ('www.python.org', '', 'q=abc', '')),
123 ('://www.python.org/#abc',
124 ('www.python.org', '/', '', '', 'abc'),
125 ('www.python.org', '/', '', 'abc')),
126 ('://a/b/c/d;p?q#f',
127 ('a', '/b/c/d', 'p', 'q', 'f'),
128 ('a', '/b/c/d;p', 'q', 'f')),
129 ]
130 for scheme in ('http', 'https'):
131 for url, parsed, split in testcases:
132 url = scheme + url
133 parsed = (scheme,) + parsed
134 split = (scheme,) + split
135 self.checkRoundtrips(url, parsed, split)
Fred Drake70705652002-10-16 21:02:36 +0000136
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000137 def checkJoin(self, base, relurl, expected):
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000138 self.assertEqual(urllib.parse.urljoin(base, relurl), expected,
Guido van Rossumbbc05682002-10-14 19:59:54 +0000139 (base, relurl, expected))
140
141 def test_unparse_parse(self):
142 for u in ['Python', './Python']:
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000143 self.assertEqual(urllib.parse.urlunsplit(urllib.parse.urlsplit(u)), u)
144 self.assertEqual(urllib.parse.urlunparse(urllib.parse.urlparse(u)), u)
Fred Drakea4d18a02001-01-05 05:57:04 +0000145
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000146 def test_RFC1808(self):
147 # "normal" cases from RFC 1808:
148 self.checkJoin(RFC1808_BASE, 'g:h', 'g:h')
149 self.checkJoin(RFC1808_BASE, 'g', 'http://a/b/c/g')
150 self.checkJoin(RFC1808_BASE, './g', 'http://a/b/c/g')
151 self.checkJoin(RFC1808_BASE, 'g/', 'http://a/b/c/g/')
152 self.checkJoin(RFC1808_BASE, '/g', 'http://a/g')
153 self.checkJoin(RFC1808_BASE, '//g', 'http://g')
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000154 self.checkJoin(RFC1808_BASE, 'g?y', 'http://a/b/c/g?y')
155 self.checkJoin(RFC1808_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x')
156 self.checkJoin(RFC1808_BASE, '#s', 'http://a/b/c/d;p?q#s')
157 self.checkJoin(RFC1808_BASE, 'g#s', 'http://a/b/c/g#s')
158 self.checkJoin(RFC1808_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
159 self.checkJoin(RFC1808_BASE, 'g?y#s', 'http://a/b/c/g?y#s')
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000160 self.checkJoin(RFC1808_BASE, 'g;x', 'http://a/b/c/g;x')
161 self.checkJoin(RFC1808_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s')
162 self.checkJoin(RFC1808_BASE, '.', 'http://a/b/c/')
163 self.checkJoin(RFC1808_BASE, './', 'http://a/b/c/')
164 self.checkJoin(RFC1808_BASE, '..', 'http://a/b/')
165 self.checkJoin(RFC1808_BASE, '../', 'http://a/b/')
166 self.checkJoin(RFC1808_BASE, '../g', 'http://a/b/g')
167 self.checkJoin(RFC1808_BASE, '../..', 'http://a/')
168 self.checkJoin(RFC1808_BASE, '../../', 'http://a/')
169 self.checkJoin(RFC1808_BASE, '../../g', 'http://a/g')
Fred Drakea4d18a02001-01-05 05:57:04 +0000170
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000171 # "abnormal" cases from RFC 1808:
172 self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f')
173 self.checkJoin(RFC1808_BASE, '../../../g', 'http://a/../g')
174 self.checkJoin(RFC1808_BASE, '../../../../g', 'http://a/../../g')
175 self.checkJoin(RFC1808_BASE, '/./g', 'http://a/./g')
176 self.checkJoin(RFC1808_BASE, '/../g', 'http://a/../g')
177 self.checkJoin(RFC1808_BASE, 'g.', 'http://a/b/c/g.')
178 self.checkJoin(RFC1808_BASE, '.g', 'http://a/b/c/.g')
179 self.checkJoin(RFC1808_BASE, 'g..', 'http://a/b/c/g..')
180 self.checkJoin(RFC1808_BASE, '..g', 'http://a/b/c/..g')
181 self.checkJoin(RFC1808_BASE, './../g', 'http://a/b/g')
182 self.checkJoin(RFC1808_BASE, './g/.', 'http://a/b/c/g/')
183 self.checkJoin(RFC1808_BASE, 'g/./h', 'http://a/b/c/g/h')
184 self.checkJoin(RFC1808_BASE, 'g/../h', 'http://a/b/c/h')
Fred Drakea4d18a02001-01-05 05:57:04 +0000185
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000186 # RFC 1808 and RFC 1630 disagree on these (according to RFC 1808),
187 # so we'll not actually run these tests (which expect 1808 behavior).
188 #self.checkJoin(RFC1808_BASE, 'http:g', 'http:g')
189 #self.checkJoin(RFC1808_BASE, 'http:', 'http:')
Fred Drakea4d18a02001-01-05 05:57:04 +0000190
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000191 def test_RFC2396(self):
192 # cases from RFC 2396
Fred Drakea4d18a02001-01-05 05:57:04 +0000193
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000194
195 self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
196 self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g')
197 self.checkJoin(RFC2396_BASE, './g', 'http://a/b/c/g')
198 self.checkJoin(RFC2396_BASE, 'g/', 'http://a/b/c/g/')
199 self.checkJoin(RFC2396_BASE, '/g', 'http://a/g')
200 self.checkJoin(RFC2396_BASE, '//g', 'http://g')
201 self.checkJoin(RFC2396_BASE, 'g?y', 'http://a/b/c/g?y')
202 self.checkJoin(RFC2396_BASE, '#s', 'http://a/b/c/d;p?q#s')
203 self.checkJoin(RFC2396_BASE, 'g#s', 'http://a/b/c/g#s')
204 self.checkJoin(RFC2396_BASE, 'g?y#s', 'http://a/b/c/g?y#s')
205 self.checkJoin(RFC2396_BASE, 'g;x', 'http://a/b/c/g;x')
206 self.checkJoin(RFC2396_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s')
207 self.checkJoin(RFC2396_BASE, '.', 'http://a/b/c/')
208 self.checkJoin(RFC2396_BASE, './', 'http://a/b/c/')
209 self.checkJoin(RFC2396_BASE, '..', 'http://a/b/')
210 self.checkJoin(RFC2396_BASE, '../', 'http://a/b/')
211 self.checkJoin(RFC2396_BASE, '../g', 'http://a/b/g')
212 self.checkJoin(RFC2396_BASE, '../..', 'http://a/')
213 self.checkJoin(RFC2396_BASE, '../../', 'http://a/')
214 self.checkJoin(RFC2396_BASE, '../../g', 'http://a/g')
215 self.checkJoin(RFC2396_BASE, '', RFC2396_BASE)
216 self.checkJoin(RFC2396_BASE, '../../../g', 'http://a/../g')
217 self.checkJoin(RFC2396_BASE, '../../../../g', 'http://a/../../g')
218 self.checkJoin(RFC2396_BASE, '/./g', 'http://a/./g')
219 self.checkJoin(RFC2396_BASE, '/../g', 'http://a/../g')
220 self.checkJoin(RFC2396_BASE, 'g.', 'http://a/b/c/g.')
221 self.checkJoin(RFC2396_BASE, '.g', 'http://a/b/c/.g')
222 self.checkJoin(RFC2396_BASE, 'g..', 'http://a/b/c/g..')
223 self.checkJoin(RFC2396_BASE, '..g', 'http://a/b/c/..g')
224 self.checkJoin(RFC2396_BASE, './../g', 'http://a/b/g')
225 self.checkJoin(RFC2396_BASE, './g/.', 'http://a/b/c/g/')
226 self.checkJoin(RFC2396_BASE, 'g/./h', 'http://a/b/c/g/h')
227 self.checkJoin(RFC2396_BASE, 'g/../h', 'http://a/b/c/h')
228 self.checkJoin(RFC2396_BASE, 'g;x=1/./y', 'http://a/b/c/g;x=1/y')
229 self.checkJoin(RFC2396_BASE, 'g;x=1/../y', 'http://a/b/c/y')
230 self.checkJoin(RFC2396_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x')
231 self.checkJoin(RFC2396_BASE, 'g?y/../x', 'http://a/b/c/g?y/../x')
232 self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
233 self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
234
Facundo Batista23e38562008-08-14 16:55:14 +0000235 #The following scenarios have been updated in RFC3986
236 #self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
237 #self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
238
239 def test_RFC3986(self):
240 self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
241 self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
242
Fred Drake70705652002-10-16 21:02:36 +0000243 def test_urldefrag(self):
244 for url, defrag, frag in [
245 ('http://python.org#frag', 'http://python.org', 'frag'),
246 ('http://python.org', 'http://python.org', ''),
247 ('http://python.org/#frag', 'http://python.org/', 'frag'),
248 ('http://python.org/', 'http://python.org/', ''),
249 ('http://python.org/?q#frag', 'http://python.org/?q', 'frag'),
250 ('http://python.org/?q', 'http://python.org/?q', ''),
251 ('http://python.org/p#frag', 'http://python.org/p', 'frag'),
252 ('http://python.org/p?q', 'http://python.org/p?q', ''),
253 (RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'),
254 (RFC2396_BASE, 'http://a/b/c/d;p?q', ''),
255 ]:
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000256 self.assertEqual(urllib.parse.urldefrag(url), (defrag, frag))
Fred Drake70705652002-10-16 21:02:36 +0000257
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000258 def test_urlsplit_attributes(self):
259 url = "HTTP://WWW.PYTHON.ORG/doc/#frag"
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000260 p = urllib.parse.urlsplit(url)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000261 self.assertEqual(p.scheme, "http")
262 self.assertEqual(p.netloc, "WWW.PYTHON.ORG")
263 self.assertEqual(p.path, "/doc/")
264 self.assertEqual(p.query, "")
265 self.assertEqual(p.fragment, "frag")
266 self.assertEqual(p.username, None)
267 self.assertEqual(p.password, None)
268 self.assertEqual(p.hostname, "www.python.org")
269 self.assertEqual(p.port, None)
270 # geturl() won't return exactly the original URL in this case
271 # since the scheme is always case-normalized
272 #self.assertEqual(p.geturl(), url)
273
274 url = "http://User:Pass@www.python.org:080/doc/?query=yes#frag"
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000275 p = urllib.parse.urlsplit(url)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000276 self.assertEqual(p.scheme, "http")
277 self.assertEqual(p.netloc, "User:Pass@www.python.org:080")
278 self.assertEqual(p.path, "/doc/")
279 self.assertEqual(p.query, "query=yes")
280 self.assertEqual(p.fragment, "frag")
281 self.assertEqual(p.username, "User")
282 self.assertEqual(p.password, "Pass")
283 self.assertEqual(p.hostname, "www.python.org")
284 self.assertEqual(p.port, 80)
285 self.assertEqual(p.geturl(), url)
286
Christian Heimesfaf2f632008-01-06 16:59:19 +0000287 # Addressing issue1698, which suggests Username can contain
288 # "@" characters. Though not RFC compliant, many ftp sites allow
289 # and request email addresses as usernames.
290
291 url = "http://User@example.com:Pass@www.python.org:080/doc/?query=yes#frag"
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000292 p = urllib.parse.urlsplit(url)
Christian Heimesfaf2f632008-01-06 16:59:19 +0000293 self.assertEqual(p.scheme, "http")
294 self.assertEqual(p.netloc, "User@example.com:Pass@www.python.org:080")
295 self.assertEqual(p.path, "/doc/")
296 self.assertEqual(p.query, "query=yes")
297 self.assertEqual(p.fragment, "frag")
298 self.assertEqual(p.username, "User@example.com")
299 self.assertEqual(p.password, "Pass")
300 self.assertEqual(p.hostname, "www.python.org")
301 self.assertEqual(p.port, 80)
302 self.assertEqual(p.geturl(), url)
303
304
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000305 def test_attributes_bad_port(self):
306 """Check handling of non-integer ports."""
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000307 p = urllib.parse.urlsplit("http://www.example.net:foo")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308 self.assertEqual(p.netloc, "www.example.net:foo")
309 self.assertRaises(ValueError, lambda: p.port)
310
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000311 p = urllib.parse.urlparse("http://www.example.net:foo")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000312 self.assertEqual(p.netloc, "www.example.net:foo")
313 self.assertRaises(ValueError, lambda: p.port)
314
315 def test_attributes_without_netloc(self):
316 # This example is straight from RFC 3261. It looks like it
317 # should allow the username, hostname, and port to be filled
318 # in, but doesn't. Since it's a URI and doesn't use the
319 # scheme://netloc syntax, the netloc and related attributes
320 # should be left empty.
321 uri = "sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15"
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000322 p = urllib.parse.urlsplit(uri)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000323 self.assertEqual(p.netloc, "")
324 self.assertEqual(p.username, None)
325 self.assertEqual(p.password, None)
326 self.assertEqual(p.hostname, None)
327 self.assertEqual(p.port, None)
328 self.assertEqual(p.geturl(), uri)
329
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000330 p = urllib.parse.urlparse(uri)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000331 self.assertEqual(p.netloc, "")
332 self.assertEqual(p.username, None)
333 self.assertEqual(p.password, None)
334 self.assertEqual(p.hostname, None)
335 self.assertEqual(p.port, None)
336 self.assertEqual(p.geturl(), uri)
337
Christian Heimesfaf2f632008-01-06 16:59:19 +0000338 def test_noslash(self):
339 # Issue 1637: http://foo.com?query is legal
Jeremy Hylton1afc1692008-06-18 20:49:58 +0000340 self.assertEqual(urllib.parse.urlparse("http://example.com?blahblah=/foo"),
Christian Heimesfaf2f632008-01-06 16:59:19 +0000341 ('http', 'example.com', '', '', 'blahblah=/foo', ''))
342
Facundo Batista2ac5de22008-07-07 18:24:11 +0000343 def test_usingsys(self):
344 # Issue 3314: sys module is used in the error
345 self.assertRaises(TypeError, urllib.parse.urlencode, "foo")
346
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000347def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000348 support.run_unittest(UrlParseTestCase)
Skip Montanaro6ec967d2002-03-23 05:32:10 +0000349
350if __name__ == "__main__":
351 test_main()