Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_urlparse.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | bf384111b3b3 |
| children |
| rev | line source |
|---|---|
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
1 import urlparse |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
2 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
3 errors = 0 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
4 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
5 RFC1808_BASE = "http://a/b/c/d;p?q#f" |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
6 |
| 22378 | 7 for url, expected in [('http://www.python.org', |
| 8 ('http', 'www.python.org', '', '', '', '')), | |
| 9 ('http://www.python.org#abc', | |
| 10 ('http', 'www.python.org', '', '', '', 'abc')), | |
| 11 ('http://www.python.org/#abc', | |
| 12 ('http', 'www.python.org', '/', '', '', 'abc')), | |
| 13 (RFC1808_BASE, | |
| 14 ('http', 'a', '/b/c/d', 'p', 'q', 'f')), | |
|
25622
a0005d26773d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25426
diff
changeset
|
15 ('file:///tmp/junk.txt', |
|
a0005d26773d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25426
diff
changeset
|
16 ('file', '', '/tmp/junk.txt', '', '', '')), |
| 22378 | 17 ]: |
| 18 result = urlparse.urlparse(url) | |
| 19 print "%-13s = %r" % (url, result) | |
| 20 if result != expected: | |
| 21 errors += 1 | |
| 22 print "urlparse(%r)" % url | |
| 23 print ("expected %r,\n" | |
| 24 " got %r") % (expected, result) | |
| 25426 | 25 # put it back together and it should be the same |
| 26 result2 = urlparse.urlunparse(result) | |
| 27 assert(result2 == url) | |
| 22378 | 28 print |
| 29 | |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
30 def checkJoin(relurl, expected): |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
31 global errors |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
32 result = urlparse.urljoin(RFC1808_BASE, relurl) |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
33 print "%-13s = %r" % (relurl, result) |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
34 if result != expected: |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
35 errors += 1 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
36 print "urljoin(%r, %r)" % (RFC1808_BASE, relurl) |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
37 print ("expected %r,\n" |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
38 " got %r") % (expected, result) |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
39 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
40 print "urlparse.urljoin() tests" |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
41 print |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
42 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
43 # "normal" cases from RFC 1808: |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
44 checkJoin('g:h', 'g:h') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
45 checkJoin('g', 'http://a/b/c/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
46 checkJoin('./g', 'http://a/b/c/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
47 checkJoin('g/', 'http://a/b/c/g/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
48 checkJoin('/g', 'http://a/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
49 checkJoin('//g', 'http://g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
50 checkJoin('?y', 'http://a/b/c/d;p?y') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
51 checkJoin('g?y', 'http://a/b/c/g?y') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
52 checkJoin('g?y/./x', 'http://a/b/c/g?y/./x') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
53 checkJoin('#s', 'http://a/b/c/d;p?q#s') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
54 checkJoin('g#s', 'http://a/b/c/g#s') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
55 checkJoin('g#s/./x', 'http://a/b/c/g#s/./x') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
56 checkJoin('g?y#s', 'http://a/b/c/g?y#s') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
57 checkJoin(';x', 'http://a/b/c/d;x') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
58 checkJoin('g;x', 'http://a/b/c/g;x') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
59 checkJoin('g;x?y#s', 'http://a/b/c/g;x?y#s') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
60 checkJoin('.', 'http://a/b/c/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
61 checkJoin('./', 'http://a/b/c/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
62 checkJoin('..', 'http://a/b/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
63 checkJoin('../', 'http://a/b/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
64 checkJoin('../g', 'http://a/b/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
65 checkJoin('../..', 'http://a/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
66 checkJoin('../../', 'http://a/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
67 checkJoin('../../g', 'http://a/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
68 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
69 # "abnormal" cases from RFC 1808: |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
70 checkJoin('', 'http://a/b/c/d;p?q#f') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
71 checkJoin('../../../g', 'http://a/../g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
72 checkJoin('../../../../g', 'http://a/../../g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
73 checkJoin('/./g', 'http://a/./g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
74 checkJoin('/../g', 'http://a/../g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
75 checkJoin('g.', 'http://a/b/c/g.') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
76 checkJoin('.g', 'http://a/b/c/.g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
77 checkJoin('g..', 'http://a/b/c/g..') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
78 checkJoin('..g', 'http://a/b/c/..g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
79 checkJoin('./../g', 'http://a/b/g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
80 checkJoin('./g/.', 'http://a/b/c/g/') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
81 checkJoin('g/./h', 'http://a/b/c/g/h') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
82 checkJoin('g/../h', 'http://a/b/c/h') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
83 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
84 # RFC 1808 and RFC 1630 disagree on these (according to RFC 1808), |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
85 # so we'll not actually run these tests (which expect 1808 behavior). |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
86 #checkJoin('http:g', 'http:g') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
87 #checkJoin('http:', 'http:') |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
88 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
89 print errors, "errors" |
|
25787
bf384111b3b3
Backporting urlparse.py:1.34, test_urlparse.py:1.8:
Guido van Rossum <guido@python.org>
parents:
25622
diff
changeset
|
90 |
|
bf384111b3b3
Backporting urlparse.py:1.34, test_urlparse.py:1.8:
Guido van Rossum <guido@python.org>
parents:
25622
diff
changeset
|
91 # One more test backported from 2.3 |
|
bf384111b3b3
Backporting urlparse.py:1.34, test_urlparse.py:1.8:
Guido van Rossum <guido@python.org>
parents:
25622
diff
changeset
|
92 for u in ['Python', './Python']: |
|
bf384111b3b3
Backporting urlparse.py:1.34, test_urlparse.py:1.8:
Guido van Rossum <guido@python.org>
parents:
25622
diff
changeset
|
93 if urlparse.urlunparse(urlparse.urlparse(u)) != u: |
|
bf384111b3b3
Backporting urlparse.py:1.34, test_urlparse.py:1.8:
Guido van Rossum <guido@python.org>
parents:
25622
diff
changeset
|
94 print "*** urlparse/urlunparse failure for", `u` |
