blob: 20336bc7081867c8fac28bbbb7a02a3706299c3b [file] [log] [blame]
Fred Drakea4d18a02001-01-05 05:57:04 +00001import urlparse
2
3errors = 0
4
5RFC1808_BASE = "http://a/b/c/d;p?q#f"
6
7def 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)
16
17print "urlparse.urljoin() tests"
18print
19
20# "normal" cases from RFC 1808:
21checkJoin('g:h', 'g:h')
22checkJoin('g', 'http://a/b/c/g')
23checkJoin('./g', 'http://a/b/c/g')
24checkJoin('g/', 'http://a/b/c/g/')
25checkJoin('/g', 'http://a/g')
26checkJoin('//g', 'http://g')
27checkJoin('?y', 'http://a/b/c/d;p?y')
28checkJoin('g?y', 'http://a/b/c/g?y')
29checkJoin('g?y/./x', 'http://a/b/c/g?y/./x')
30checkJoin('#s', 'http://a/b/c/d;p?q#s')
31checkJoin('g#s', 'http://a/b/c/g#s')
32checkJoin('g#s/./x', 'http://a/b/c/g#s/./x')
33checkJoin('g?y#s', 'http://a/b/c/g?y#s')
34checkJoin(';x', 'http://a/b/c/d;x')
35checkJoin('g;x', 'http://a/b/c/g;x')
36checkJoin('g;x?y#s', 'http://a/b/c/g;x?y#s')
37checkJoin('.', 'http://a/b/c/')
38checkJoin('./', 'http://a/b/c/')
39checkJoin('..', 'http://a/b/')
40checkJoin('../', 'http://a/b/')
41checkJoin('../g', 'http://a/b/g')
42checkJoin('../..', 'http://a/')
43checkJoin('../../', 'http://a/')
44checkJoin('../../g', 'http://a/g')
45
46# "abnormal" cases from RFC 1808:
47checkJoin('', 'http://a/b/c/d;p?q#f')
48checkJoin('../../../g', 'http://a/../g')
49checkJoin('../../../../g', 'http://a/../../g')
50checkJoin('/./g', 'http://a/./g')
51checkJoin('/../g', 'http://a/../g')
52checkJoin('g.', 'http://a/b/c/g.')
53checkJoin('.g', 'http://a/b/c/.g')
54checkJoin('g..', 'http://a/b/c/g..')
55checkJoin('..g', 'http://a/b/c/..g')
56checkJoin('./../g', 'http://a/b/g')
57checkJoin('./g/.', 'http://a/b/c/g/')
58checkJoin('g/./h', 'http://a/b/c/g/h')
59checkJoin('g/../h', 'http://a/b/c/h')
60
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:')
65
66print errors, "errors"