This commit was manufactured by cvs2svn to create tag 'r211c1'.
[python/dscho.git] / Lib / test / test_urlparse.py
blob20336bc7081867c8fac28bbbb7a02a3706299c3b
1 import urlparse
3 errors = 0
5 RFC1808_BASE = "http://a/b/c/d;p?q#f"
7 def checkJoin(relurl, expected):
8 global errors
9 result = urlparse.urljoin(RFC1808_BASE, relurl)
10 print "%-13s = %r" % (relurl, result)
11 if result != expected:
12 errors += 1
13 print "urljoin(%r, %r)" % (RFC1808_BASE, relurl)
14 print ("expected %r,\n"
15 " got %r") % (expected, result)
17 print "urlparse.urljoin() tests"
18 print
20 # "normal" cases from RFC 1808:
21 checkJoin('g:h', 'g:h')
22 checkJoin('g', 'http://a/b/c/g')
23 checkJoin('./g', 'http://a/b/c/g')
24 checkJoin('g/', 'http://a/b/c/g/')
25 checkJoin('/g', 'http://a/g')
26 checkJoin('//g', 'http://g')
27 checkJoin('?y', 'http://a/b/c/d;p?y')
28 checkJoin('g?y', 'http://a/b/c/g?y')
29 checkJoin('g?y/./x', 'http://a/b/c/g?y/./x')
30 checkJoin('#s', 'http://a/b/c/d;p?q#s')
31 checkJoin('g#s', 'http://a/b/c/g#s')
32 checkJoin('g#s/./x', 'http://a/b/c/g#s/./x')
33 checkJoin('g?y#s', 'http://a/b/c/g?y#s')
34 checkJoin(';x', 'http://a/b/c/d;x')
35 checkJoin('g;x', 'http://a/b/c/g;x')
36 checkJoin('g;x?y#s', 'http://a/b/c/g;x?y#s')
37 checkJoin('.', 'http://a/b/c/')
38 checkJoin('./', 'http://a/b/c/')
39 checkJoin('..', 'http://a/b/')
40 checkJoin('../', 'http://a/b/')
41 checkJoin('../g', 'http://a/b/g')
42 checkJoin('../..', 'http://a/')
43 checkJoin('../../', 'http://a/')
44 checkJoin('../../g', 'http://a/g')
46 # "abnormal" cases from RFC 1808:
47 checkJoin('', 'http://a/b/c/d;p?q#f')
48 checkJoin('../../../g', 'http://a/../g')
49 checkJoin('../../../../g', 'http://a/../../g')
50 checkJoin('/./g', 'http://a/./g')
51 checkJoin('/../g', 'http://a/../g')
52 checkJoin('g.', 'http://a/b/c/g.')
53 checkJoin('.g', 'http://a/b/c/.g')
54 checkJoin('g..', 'http://a/b/c/g..')
55 checkJoin('..g', 'http://a/b/c/..g')
56 checkJoin('./../g', 'http://a/b/g')
57 checkJoin('./g/.', 'http://a/b/c/g/')
58 checkJoin('g/./h', 'http://a/b/c/g/h')
59 checkJoin('g/../h', 'http://a/b/c/h')
61 # RFC 1808 and RFC 1630 disagree on these (according to RFC 1808),
62 # so we'll not actually run these tests (which expect 1808 behavior).
63 #checkJoin('http:g', 'http:g')
64 #checkJoin('http:', 'http:')
66 print errors, "errors"