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
277e9090
Commit
277e9090
authored
Apr 10, 2013
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#5609 - test_urllib coverage for url2pathname and pathname2url. Patch
contribution by Thomas Fenzl & Maksim Kozyarchuk
parent
c9314d9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
17 deletions
+56
-17
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+56
-17
No files found.
Lib/test/test_urllib.py
View file @
277e9090
...
...
@@ -11,6 +11,7 @@ from test import support
import
os
import
sys
import
tempfile
from
nturl2path
import
url2pathname
,
pathname2url
from
base64
import
b64encode
import
collections
...
...
@@ -24,6 +25,8 @@ def hexescape(char):
# Shortcut for testing FancyURLopener
_urlopener
=
None
def
urlopen
(
url
,
data
=
None
,
proxies
=
None
):
"""urlopen(url [, data]) -> open file-like object"""
global
_urlopener
...
...
@@ -1312,24 +1315,60 @@ class RequestTests(unittest.TestCase):
self
.
assertEqual
(
request
.
get_method
(),
'HEAD'
)
def
test_main
():
support
.
run_unittest
(
urlopen_FileTests
,
urlopen_HttpTests
,
urlretrieve_FileTests
,
urlretrieve_HttpTests
,
ProxyTests
,
QuotingTests
,
UnquotingTests
,
urlencode_Tests
,
Pathname_Tests
,
Utility_Tests
,
URLopener_Tests
,
#FTPWrapperTests,
RequestTests
,
)
class
URL2PathNameTests
(
unittest
.
TestCase
):
def
test_converting_drive_letter
(
self
):
self
.
assertEqual
(
url2pathname
(
"///C|"
),
'C:'
)
self
.
assertEqual
(
url2pathname
(
"///C:"
),
'C:'
)
self
.
assertEqual
(
url2pathname
(
"///C|/"
),
'C:
\
\
'
)
def
test_converting_when_no_drive_letter
(
self
):
# cannot end a raw string in \
self
.
assertEqual
(
url2pathname
(
"///C/test/"
),
r'\\\
C
\test'
'
\
\
'
)
self
.
assertEqual
(
url2pathname
(
"////C/test/"
),
r'\\C\test'
'
\
\
'
)
def
test_simple_compare
(
self
):
self
.
assertEqual
(
url2pathname
(
"///C|/foo/bar/spam.foo"
),
r'C:\foo\bar\
sp
am.foo'
)
def
test_non_ascii_drive_letter
(
self
):
self
.
assertRaises
(
IOError
,
url2pathname
,
"///
\
u00e8
|/"
)
def
test_roundtrip_url2pathname
(
self
):
list_of_paths
=
[
'C:'
,
r'\\\
C
\test\\'
,
r'C:\foo\bar\
sp
am.foo'
]
for
path
in
list_of_paths
:
self
.
assertEqual
(
url2pathname
(
pathname2url
(
path
)),
path
)
class
PathName2URLTests
(
unittest
.
TestCase
):
def
test_converting_drive_letter
(
self
):
self
.
assertEqual
(
pathname2url
(
"C:"
),
'///C:'
)
self
.
assertEqual
(
pathname2url
(
"C:
\
\
"
),
'///C:'
)
def
test_converting_when_no_drive_letter
(
self
):
self
.
assertEqual
(
pathname2url
(
r"\\\folder\test"
"
\
\
"
),
'/////folder/test/'
)
self
.
assertEqual
(
pathname2url
(
r"\\folder\test"
"
\
\
"
),
'////folder/test/'
)
self
.
assertEqual
(
pathname2url
(
r"\folder\test"
"
\
\
"
),
'/folder/test/'
)
def
test_simple_compare
(
self
):
self
.
assertEqual
(
pathname2url
(
r'C:\foo\bar\
sp
am.foo'
),
"///C:/foo/bar/spam.foo"
)
def
test_long_drive_letter
(
self
):
self
.
assertRaises
(
IOError
,
pathname2url
,
"XX:
\
\
"
)
def
test_roundtrip_pathname2url
(
self
):
list_of_paths
=
[
'///C:'
,
'/////folder/test/'
,
'///C:/foo/bar/spam.foo'
]
for
path
in
list_of_paths
:
self
.
assertEqual
(
pathname2url
(
url2pathname
(
path
)),
path
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
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