diff options
author | Fred Drake <fdrake@acm.org> | 2002-10-16 21:02:36 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-10-16 21:02:36 (GMT) |
commit | 707056580f7bdc95304f036787db192fe9054155 (patch) | |
tree | 49969339d8b31656b7d03d520c428e62fb6b31f2 /Lib | |
parent | 68077210c2588241fc5e4e16d83c083fa4103108 (diff) | |
download | cpython-707056580f7bdc95304f036787db192fe9054155.zip cpython-707056580f7bdc95304f036787db192fe9054155.tar.gz cpython-707056580f7bdc95304f036787db192fe9054155.tar.bz2 |
Make sure we test urlsplit() / urlunsplit() directly, rather than
guessing that urlparse() / urlunparse() use them.
Add tests of urldefrag().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urlparse.py | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 39f50e4..7d7f458 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -9,29 +9,42 @@ RFC2396_BASE = "http://a/b/c/d;p?q" class UrlParseTestCase(unittest.TestCase): def test_frags(self): - for url, expected in [('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')), - (RFC1808_BASE, - ('http', 'a', '/b/c/d', 'p', 'q', 'f')), - ('file:///tmp/junk.txt', - ('file', '', '/tmp/junk.txt', '', '', '')), - ]: + 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')), + ('file:///tmp/junk.txt', + ('file', '', '/tmp/junk.txt', '', '', ''), + ('file', '', '/tmp/junk.txt', '', '')), + ]: result = urlparse.urlparse(url) - self.assertEqual(result, expected) + 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 checkJoin(self, base, relurl, expected): self.assertEqual(urlparse.urljoin(base, relurl), expected, (base, relurl, expected)) def test_unparse_parse(self): for u in ['Python', './Python']: + self.assertEqual(urlparse.urlunsplit(urlparse.urlsplit(u)), u) self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u) def test_RFC1808(self): @@ -128,6 +141,21 @@ class UrlParseTestCase(unittest.TestCase): self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x') + def test_urldefrag(self): + for url, defrag, frag in [ + ('http://python.org#frag', 'http://python.org', 'frag'), + ('http://python.org', 'http://python.org', ''), + ('http://python.org/#frag', 'http://python.org/', 'frag'), + ('http://python.org/', 'http://python.org/', ''), + ('http://python.org/?q#frag', 'http://python.org/?q', 'frag'), + ('http://python.org/?q', 'http://python.org/?q', ''), + ('http://python.org/p#frag', 'http://python.org/p', 'frag'), + ('http://python.org/p?q', 'http://python.org/p?q', ''), + (RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'), + (RFC2396_BASE, 'http://a/b/c/d;p?q', ''), + ]: + self.assertEqual(urlparse.urldefrag(url), (defrag, frag)) + def test_main(): test_support.run_unittest(UrlParseTestCase) |