summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-01-05 05:57:04 (GMT)
committerFred Drake <fdrake@acm.org>2001-01-05 05:57:04 (GMT)
commita4d18a008f3908c92940e635d787c56f19cfca80 (patch)
tree722f46a1095867c21c6aa7de2f5b8e9538ca6c5a /Lib/test
parent867952f6e437270cc906af34dba28a9b580ec265 (diff)
downloadcpython-a4d18a008f3908c92940e635d787c56f19cfca80.zip
cpython-a4d18a008f3908c92940e635d787c56f19cfca80.tar.gz
cpython-a4d18a008f3908c92940e635d787c56f19cfca80.tar.bz2
Add test cases based on RFC 1808. So now we actually have a test suite
the urljoin() function, which exercises the urlparse() and urlunparse() functions as side effects. (Moshe, why did we have perfectly empty tests checked in for this?)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/output/test_urlparse40
-rw-r--r--Lib/test/test_urlparse.py66
2 files changed, 106 insertions, 0 deletions
diff --git a/Lib/test/output/test_urlparse b/Lib/test/output/test_urlparse
index 612eb5c..ca71729 100644
--- a/Lib/test/output/test_urlparse
+++ b/Lib/test/output/test_urlparse
@@ -1 +1,41 @@
test_urlparse
+urlparse.urljoin() tests
+
+g:h = 'g:h'
+g = 'http://a/b/c/g'
+./g = 'http://a/b/c/g'
+g/ = 'http://a/b/c/g/'
+/g = 'http://a/g'
+//g = 'http://g'
+?y = 'http://a/b/c/d;p?y'
+g?y = 'http://a/b/c/g?y'
+g?y/./x = 'http://a/b/c/g?y/./x'
+#s = 'http://a/b/c/d;p?q#s'
+g#s = 'http://a/b/c/g#s'
+g#s/./x = 'http://a/b/c/g#s/./x'
+g?y#s = 'http://a/b/c/g?y#s'
+;x = 'http://a/b/c/d;x'
+g;x = 'http://a/b/c/g;x'
+g;x?y#s = 'http://a/b/c/g;x?y#s'
+. = 'http://a/b/c/'
+./ = 'http://a/b/c/'
+.. = 'http://a/b/'
+../ = 'http://a/b/'
+../g = 'http://a/b/g'
+../.. = 'http://a/'
+../../ = 'http://a/'
+../../g = 'http://a/g'
+ = 'http://a/b/c/d;p?q#f'
+../../../g = 'http://a/../g'
+../../../../g = 'http://a/../../g'
+/./g = 'http://a/./g'
+/../g = 'http://a/../g'
+g. = 'http://a/b/c/g.'
+.g = 'http://a/b/c/.g'
+g.. = 'http://a/b/c/g..'
+..g = 'http://a/b/c/..g'
+./../g = 'http://a/b/g'
+./g/. = 'http://a/b/c/g/'
+g/./h = 'http://a/b/c/g/h'
+g/../h = 'http://a/b/c/h'
+0 errors
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index e69de29..20336bc 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -0,0 +1,66 @@
+import urlparse
+
+errors = 0
+
+RFC1808_BASE = "http://a/b/c/d;p?q#f"
+
+def checkJoin(relurl, expected):
+ global errors
+ result = urlparse.urljoin(RFC1808_BASE, relurl)
+ print "%-13s = %r" % (relurl, result)
+ if result != expected:
+ errors += 1
+ print "urljoin(%r, %r)" % (RFC1808_BASE, relurl)
+ print ("expected %r,\n"
+ " got %r") % (expected, result)
+
+print "urlparse.urljoin() tests"
+print
+
+# "normal" cases from RFC 1808:
+checkJoin('g:h', 'g:h')
+checkJoin('g', 'http://a/b/c/g')
+checkJoin('./g', 'http://a/b/c/g')
+checkJoin('g/', 'http://a/b/c/g/')
+checkJoin('/g', 'http://a/g')
+checkJoin('//g', 'http://g')
+checkJoin('?y', 'http://a/b/c/d;p?y')
+checkJoin('g?y', 'http://a/b/c/g?y')
+checkJoin('g?y/./x', 'http://a/b/c/g?y/./x')
+checkJoin('#s', 'http://a/b/c/d;p?q#s')
+checkJoin('g#s', 'http://a/b/c/g#s')
+checkJoin('g#s/./x', 'http://a/b/c/g#s/./x')
+checkJoin('g?y#s', 'http://a/b/c/g?y#s')
+checkJoin(';x', 'http://a/b/c/d;x')
+checkJoin('g;x', 'http://a/b/c/g;x')
+checkJoin('g;x?y#s', 'http://a/b/c/g;x?y#s')
+checkJoin('.', 'http://a/b/c/')
+checkJoin('./', 'http://a/b/c/')
+checkJoin('..', 'http://a/b/')
+checkJoin('../', 'http://a/b/')
+checkJoin('../g', 'http://a/b/g')
+checkJoin('../..', 'http://a/')
+checkJoin('../../', 'http://a/')
+checkJoin('../../g', 'http://a/g')
+
+# "abnormal" cases from RFC 1808:
+checkJoin('', 'http://a/b/c/d;p?q#f')
+checkJoin('../../../g', 'http://a/../g')
+checkJoin('../../../../g', 'http://a/../../g')
+checkJoin('/./g', 'http://a/./g')
+checkJoin('/../g', 'http://a/../g')
+checkJoin('g.', 'http://a/b/c/g.')
+checkJoin('.g', 'http://a/b/c/.g')
+checkJoin('g..', 'http://a/b/c/g..')
+checkJoin('..g', 'http://a/b/c/..g')
+checkJoin('./../g', 'http://a/b/g')
+checkJoin('./g/.', 'http://a/b/c/g/')
+checkJoin('g/./h', 'http://a/b/c/g/h')
+checkJoin('g/../h', 'http://a/b/c/h')
+
+# RFC 1808 and RFC 1630 disagree on these (according to RFC 1808),
+# so we'll not actually run these tests (which expect 1808 behavior).
+#checkJoin('http:g', 'http:g')
+#checkJoin('http:', 'http:')
+
+print errors, "errors"