Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6ec967d0
Commit
6ec967d0
authored
Mar 23, 2002
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
converted to use unittest
parent
b1ba6b00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
74 deletions
+116
-74
Lib/test/test_urlparse.py
Lib/test/test_urlparse.py
+116
-74
No files found.
Lib/test/test_urlparse.py
View file @
6ec967d0
import
urlparse
#! /usr/bin/env python
errors
=
0
import
test_support
import
unittest
import
urlparse
RFC1808_BASE
=
"http://a/b/c/d;p?q#f"
RFC2396_BASE
=
"http://a/b/c/d;p?q"
for
url
,
expected
in
[(
'http://www.python.org'
,
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'
)),
...
...
@@ -14,71 +19,108 @@ for url, expected in [('http://www.python.org',
(
'http'
,
'a'
,
'/b/c/d'
,
'p'
,
'q'
,
'f'
)),
]:
result
=
urlparse
.
urlparse
(
url
)
print
"%-13s = %r"
%
(
url
,
result
)
if
result
!=
expected
:
errors
+=
1
print
"urlparse(%r)"
%
url
print
(
"expected %r,
\
n
"
" got %r"
)
%
(
expected
,
result
)
print
self
.
assertEqual
(
result
,
expected
)
def
checkJoin
(
self
,
base
,
relurl
,
expected
):
self
.
assertEqual
(
urlparse
.
urljoin
(
base
,
relurl
),
expected
)
def
test_RFC1808
(
self
):
# "normal" cases from RFC 1808:
self
.
checkJoin
(
RFC1808_BASE
,
'g:h'
,
'g:h'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g'
,
'http://a/b/c/g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'./g'
,
'http://a/b/c/g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g/'
,
'http://a/b/c/g/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'/g'
,
'http://a/g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'//g'
,
'http://g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'?y'
,
'http://a/b/c/d;p?y'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g?y'
,
'http://a/b/c/g?y'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g?y/./x'
,
'http://a/b/c/g?y/./x'
)
self
.
checkJoin
(
RFC1808_BASE
,
'#s'
,
'http://a/b/c/d;p?q#s'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g#s'
,
'http://a/b/c/g#s'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g#s/./x'
,
'http://a/b/c/g#s/./x'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g?y#s'
,
'http://a/b/c/g?y#s'
)
self
.
checkJoin
(
RFC1808_BASE
,
';x'
,
'http://a/b/c/d;x'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g;x'
,
'http://a/b/c/g;x'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g;x?y#s'
,
'http://a/b/c/g;x?y#s'
)
self
.
checkJoin
(
RFC1808_BASE
,
'.'
,
'http://a/b/c/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'./'
,
'http://a/b/c/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'..'
,
'http://a/b/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../'
,
'http://a/b/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../g'
,
'http://a/b/g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../..'
,
'http://a/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../../'
,
'http://a/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../../g'
,
'http://a/g'
)
# "abnormal" cases from RFC 1808:
self
.
checkJoin
(
RFC1808_BASE
,
''
,
'http://a/b/c/d;p?q#f'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../../../g'
,
'http://a/../g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'../../../../g'
,
'http://a/../../g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'/./g'
,
'http://a/./g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'/../g'
,
'http://a/../g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g.'
,
'http://a/b/c/g.'
)
self
.
checkJoin
(
RFC1808_BASE
,
'.g'
,
'http://a/b/c/.g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g..'
,
'http://a/b/c/g..'
)
self
.
checkJoin
(
RFC1808_BASE
,
'..g'
,
'http://a/b/c/..g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'./../g'
,
'http://a/b/g'
)
self
.
checkJoin
(
RFC1808_BASE
,
'./g/.'
,
'http://a/b/c/g/'
)
self
.
checkJoin
(
RFC1808_BASE
,
'g/./h'
,
'http://a/b/c/g/h'
)
self
.
checkJoin
(
RFC1808_BASE
,
'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).
#self.checkJoin(RFC1808_BASE, 'http:g', 'http:g')
#self.checkJoin(RFC1808_BASE, 'http:', 'http:')
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
)
def
test_RFC2396
(
self
):
# cases from RFC 2396
print
"urlparse.urljoin() tests"
print
### urlparse.py as of v 1.32 fails on these two
#self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
#self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
# "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'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g:h'
,
'g:h'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g'
,
'http://a/b/c/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'./g'
,
'http://a/b/c/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g/'
,
'http://a/b/c/g/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'/g'
,
'http://a/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'//g'
,
'http://g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g?y'
,
'http://a/b/c/g?y'
)
self
.
checkJoin
(
RFC2396_BASE
,
'#s'
,
'http://a/b/c/d;p?q#s'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g#s'
,
'http://a/b/c/g#s'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g?y#s'
,
'http://a/b/c/g?y#s'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g;x'
,
'http://a/b/c/g;x'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g;x?y#s'
,
'http://a/b/c/g;x?y#s'
)
self
.
checkJoin
(
RFC2396_BASE
,
'.'
,
'http://a/b/c/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'./'
,
'http://a/b/c/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'..'
,
'http://a/b/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../'
,
'http://a/b/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../g'
,
'http://a/b/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../..'
,
'http://a/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../../'
,
'http://a/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../../g'
,
'http://a/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
''
,
RFC2396_BASE
)
self
.
checkJoin
(
RFC2396_BASE
,
'../../../g'
,
'http://a/../g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'../../../../g'
,
'http://a/../../g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'/./g'
,
'http://a/./g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'/../g'
,
'http://a/../g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g.'
,
'http://a/b/c/g.'
)
self
.
checkJoin
(
RFC2396_BASE
,
'.g'
,
'http://a/b/c/.g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g..'
,
'http://a/b/c/g..'
)
self
.
checkJoin
(
RFC2396_BASE
,
'..g'
,
'http://a/b/c/..g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'./../g'
,
'http://a/b/g'
)
self
.
checkJoin
(
RFC2396_BASE
,
'./g/.'
,
'http://a/b/c/g/'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g/./h'
,
'http://a/b/c/g/h'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g/../h'
,
'http://a/b/c/h'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g;x=1/./y'
,
'http://a/b/c/g;x=1/y'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g;x=1/../y'
,
'http://a/b/c/y'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g?y/./x'
,
'http://a/b/c/g?y/./x'
)
self
.
checkJoin
(
RFC2396_BASE
,
'g?y/../x'
,
'http://a/b/c/g?y/../x'
)
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'
)
# "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'
)
def
test_main
():
test_support
.
run_unittest
(
UrlParseTestCase
)
# 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:')
if
__name__
==
"__main__"
:
test_main
()
print
errors
,
"errors"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment