Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9270be76
Kaydet (Commit)
9270be76
authored
Mar 02, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added more tests for urllib.parse utility functions.
These functions are not documented but used in third-party code.
üst
ed0392ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
69 deletions
+129
-69
test_urllib.py
Lib/test/test_urllib.py
+0
-15
test_urlparse.py
Lib/test/test_urlparse.py
+129
-54
No files found.
Lib/test/test_urllib.py
Dosyayı görüntüle @
9270be76
...
@@ -1294,21 +1294,6 @@ class Pathname_Tests(unittest.TestCase):
...
@@ -1294,21 +1294,6 @@ class Pathname_Tests(unittest.TestCase):
class
Utility_Tests
(
unittest
.
TestCase
):
class
Utility_Tests
(
unittest
.
TestCase
):
"""Testcase to test the various utility functions in the urllib."""
"""Testcase to test the various utility functions in the urllib."""
def
test_splitpasswd
(
self
):
"""Some of password examples are not sensible, but it is added to
confirming to RFC2617 and addressing issue4675.
"""
self
.
assertEqual
((
'user'
,
'ab'
),
urllib
.
parse
.
splitpasswd
(
'user:ab'
))
self
.
assertEqual
((
'user'
,
'a
\n
b'
),
urllib
.
parse
.
splitpasswd
(
'user:a
\n
b'
))
self
.
assertEqual
((
'user'
,
'a
\t
b'
),
urllib
.
parse
.
splitpasswd
(
'user:a
\t
b'
))
self
.
assertEqual
((
'user'
,
'a
\r
b'
),
urllib
.
parse
.
splitpasswd
(
'user:a
\r
b'
))
self
.
assertEqual
((
'user'
,
'a
\f
b'
),
urllib
.
parse
.
splitpasswd
(
'user:a
\f
b'
))
self
.
assertEqual
((
'user'
,
'a
\v
b'
),
urllib
.
parse
.
splitpasswd
(
'user:a
\v
b'
))
self
.
assertEqual
((
'user'
,
'a:b'
),
urllib
.
parse
.
splitpasswd
(
'user:a:b'
))
self
.
assertEqual
((
'user'
,
'a b'
),
urllib
.
parse
.
splitpasswd
(
'user:a b'
))
self
.
assertEqual
((
'user 2'
,
'ab'
),
urllib
.
parse
.
splitpasswd
(
'user 2:ab'
))
self
.
assertEqual
((
'user+1'
,
'a+b'
),
urllib
.
parse
.
splitpasswd
(
'user+1:a+b'
))
def
test_thishost
(
self
):
def
test_thishost
(
self
):
"""Test the urllib.request.thishost utility function returns a tuple"""
"""Test the urllib.request.thishost utility function returns a tuple"""
self
.
assertIsInstance
(
urllib
.
request
.
thishost
(),
tuple
)
self
.
assertIsInstance
(
urllib
.
request
.
thishost
(),
tuple
)
...
...
Lib/test/test_urlparse.py
Dosyayı görüntüle @
9270be76
from
test
import
support
import
unittest
import
unittest
import
urllib.parse
import
urllib.parse
...
@@ -749,52 +748,6 @@ class UrlParseTestCase(unittest.TestCase):
...
@@ -749,52 +748,6 @@ class UrlParseTestCase(unittest.TestCase):
errors
=
"ignore"
)
errors
=
"ignore"
)
self
.
assertEqual
(
result
,
[(
'key'
,
'
\u0141
-'
)])
self
.
assertEqual
(
result
,
[(
'key'
,
'
\u0141
-'
)])
def
test_splitport
(
self
):
splitport
=
urllib
.
parse
.
splitport
self
.
assertEqual
(
splitport
(
'parrot:88'
),
(
'parrot'
,
'88'
))
self
.
assertEqual
(
splitport
(
'parrot'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitport
(
'parrot:'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitport
(
'127.0.0.1'
),
(
'127.0.0.1'
,
None
))
self
.
assertEqual
(
splitport
(
'parrot:cheese'
),
(
'parrot:cheese'
,
None
))
def
test_splitnport
(
self
):
splitnport
=
urllib
.
parse
.
splitnport
self
.
assertEqual
(
splitnport
(
'parrot:88'
),
(
'parrot'
,
88
))
self
.
assertEqual
(
splitnport
(
'parrot'
),
(
'parrot'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'parrot'
,
55
),
(
'parrot'
,
55
))
self
.
assertEqual
(
splitnport
(
'parrot:'
),
(
'parrot'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'parrot:'
,
55
),
(
'parrot'
,
55
))
self
.
assertEqual
(
splitnport
(
'127.0.0.1'
),
(
'127.0.0.1'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'127.0.0.1'
,
55
),
(
'127.0.0.1'
,
55
))
self
.
assertEqual
(
splitnport
(
'parrot:cheese'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitnport
(
'parrot:cheese'
,
55
),
(
'parrot'
,
None
))
def
test_splitquery
(
self
):
# Normal cases are exercised by other tests; ensure that we also
# catch cases with no port specified (testcase ensuring coverage)
result
=
urllib
.
parse
.
splitquery
(
'http://python.org/fake?foo=bar'
)
self
.
assertEqual
(
result
,
(
'http://python.org/fake'
,
'foo=bar'
))
result
=
urllib
.
parse
.
splitquery
(
'http://python.org/fake?foo=bar?'
)
self
.
assertEqual
(
result
,
(
'http://python.org/fake?foo=bar'
,
''
))
result
=
urllib
.
parse
.
splitquery
(
'http://python.org/fake'
)
self
.
assertEqual
(
result
,
(
'http://python.org/fake'
,
None
))
def
test_splitvalue
(
self
):
# Normal cases are exercised by other tests; test pathological cases
# with no key/value pairs. (testcase ensuring coverage)
result
=
urllib
.
parse
.
splitvalue
(
'foo=bar'
)
self
.
assertEqual
(
result
,
(
'foo'
,
'bar'
))
result
=
urllib
.
parse
.
splitvalue
(
'foo='
)
self
.
assertEqual
(
result
,
(
'foo'
,
''
))
result
=
urllib
.
parse
.
splitvalue
(
'foobar'
)
self
.
assertEqual
(
result
,
(
'foobar'
,
None
))
def
test_to_bytes
(
self
):
result
=
urllib
.
parse
.
to_bytes
(
'http://www.python.org'
)
self
.
assertEqual
(
result
,
'http://www.python.org'
)
self
.
assertRaises
(
UnicodeError
,
urllib
.
parse
.
to_bytes
,
'http://www.python.org/medi
\u00e6
val'
)
def
test_urlencode_sequences
(
self
):
def
test_urlencode_sequences
(
self
):
# Other tests incidentally urlencode things; test non-covered cases:
# Other tests incidentally urlencode things; test non-covered cases:
# Sequence and object values.
# Sequence and object values.
...
@@ -863,17 +816,139 @@ class UrlParseTestCase(unittest.TestCase):
...
@@ -863,17 +816,139 @@ class UrlParseTestCase(unittest.TestCase):
self
.
assertEqual
(
p1
.
path
,
'863-1234'
)
self
.
assertEqual
(
p1
.
path
,
'863-1234'
)
self
.
assertEqual
(
p1
.
params
,
'phone-context=+1-914-555'
)
self
.
assertEqual
(
p1
.
params
,
'phone-context=+1-914-555'
)
def
test_unwrap
(
self
):
url
=
urllib
.
parse
.
unwrap
(
'<URL:type://host/path>'
)
self
.
assertEqual
(
url
,
'type://host/path'
)
def
test_Quoter_repr
(
self
):
def
test_Quoter_repr
(
self
):
quoter
=
urllib
.
parse
.
Quoter
(
urllib
.
parse
.
_ALWAYS_SAFE
)
quoter
=
urllib
.
parse
.
Quoter
(
urllib
.
parse
.
_ALWAYS_SAFE
)
self
.
assertIn
(
'Quoter'
,
repr
(
quoter
))
self
.
assertIn
(
'Quoter'
,
repr
(
quoter
))
def
test_main
():
class
Utility_Tests
(
unittest
.
TestCase
):
support
.
run_unittest
(
UrlParseTestCase
)
"""Testcase to test the various utility functions in the urllib."""
# In Python 2 this test class was in test_urllib.
def
test_splittype
(
self
):
splittype
=
urllib
.
parse
.
splittype
self
.
assertEqual
(
splittype
(
'type:opaquestring'
),
(
'type'
,
'opaquestring'
))
self
.
assertEqual
(
splittype
(
'opaquestring'
),
(
None
,
'opaquestring'
))
self
.
assertEqual
(
splittype
(
':opaquestring'
),
(
None
,
':opaquestring'
))
self
.
assertEqual
(
splittype
(
'type:'
),
(
'type'
,
''
))
self
.
assertEqual
(
splittype
(
'type:opaque:string'
),
(
'type'
,
'opaque:string'
))
def
test_splithost
(
self
):
splithost
=
urllib
.
parse
.
splithost
self
.
assertEqual
(
splithost
(
'//www.example.org:80/foo/bar/baz.html'
),
(
'www.example.org:80'
,
'/foo/bar/baz.html'
))
self
.
assertEqual
(
splithost
(
'//www.example.org:80'
),
(
'www.example.org:80'
,
''
))
self
.
assertEqual
(
splithost
(
'/foo/bar/baz.html'
),
(
None
,
'/foo/bar/baz.html'
))
def
test_splituser
(
self
):
splituser
=
urllib
.
parse
.
splituser
self
.
assertEqual
(
splituser
(
'User:Pass@www.python.org:080'
),
(
'User:Pass'
,
'www.python.org:080'
))
self
.
assertEqual
(
splituser
(
'@www.python.org:080'
),
(
''
,
'www.python.org:080'
))
self
.
assertEqual
(
splituser
(
'www.python.org:080'
),
(
None
,
'www.python.org:080'
))
self
.
assertEqual
(
splituser
(
'User:Pass@'
),
(
'User:Pass'
,
''
))
self
.
assertEqual
(
splituser
(
'User@example.com:Pass@www.python.org:080'
),
(
'User@example.com:Pass'
,
'www.python.org:080'
))
def
test_splitpasswd
(
self
):
# Some of the password examples are not sensible, but it is added to
# confirming to RFC2617 and addressing issue4675.
splitpasswd
=
urllib
.
parse
.
splitpasswd
self
.
assertEqual
(
splitpasswd
(
'user:ab'
),
(
'user'
,
'ab'
))
self
.
assertEqual
(
splitpasswd
(
'user:a
\n
b'
),
(
'user'
,
'a
\n
b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a
\t
b'
),
(
'user'
,
'a
\t
b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a
\r
b'
),
(
'user'
,
'a
\r
b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a
\f
b'
),
(
'user'
,
'a
\f
b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a
\v
b'
),
(
'user'
,
'a
\v
b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a:b'
),
(
'user'
,
'a:b'
))
self
.
assertEqual
(
splitpasswd
(
'user:a b'
),
(
'user'
,
'a b'
))
self
.
assertEqual
(
splitpasswd
(
'user 2:ab'
),
(
'user 2'
,
'ab'
))
self
.
assertEqual
(
splitpasswd
(
'user+1:a+b'
),
(
'user+1'
,
'a+b'
))
self
.
assertEqual
(
splitpasswd
(
'user:'
),
(
'user'
,
''
))
self
.
assertEqual
(
splitpasswd
(
'user'
),
(
'user'
,
None
))
self
.
assertEqual
(
splitpasswd
(
':ab'
),
(
''
,
'ab'
))
def
test_splitport
(
self
):
splitport
=
urllib
.
parse
.
splitport
self
.
assertEqual
(
splitport
(
'parrot:88'
),
(
'parrot'
,
'88'
))
self
.
assertEqual
(
splitport
(
'parrot'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitport
(
'parrot:'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitport
(
'127.0.0.1'
),
(
'127.0.0.1'
,
None
))
self
.
assertEqual
(
splitport
(
'parrot:cheese'
),
(
'parrot:cheese'
,
None
))
self
.
assertEqual
(
splitport
(
'[::1]:88'
),
(
'[::1]'
,
'88'
))
self
.
assertEqual
(
splitport
(
'[::1]'
),
(
'[::1]'
,
None
))
self
.
assertEqual
(
splitport
(
':88'
),
(
''
,
'88'
))
def
test_splitnport
(
self
):
splitnport
=
urllib
.
parse
.
splitnport
self
.
assertEqual
(
splitnport
(
'parrot:88'
),
(
'parrot'
,
88
))
self
.
assertEqual
(
splitnport
(
'parrot'
),
(
'parrot'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'parrot'
,
55
),
(
'parrot'
,
55
))
self
.
assertEqual
(
splitnport
(
'parrot:'
),
(
'parrot'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'parrot:'
,
55
),
(
'parrot'
,
55
))
self
.
assertEqual
(
splitnport
(
'127.0.0.1'
),
(
'127.0.0.1'
,
-
1
))
self
.
assertEqual
(
splitnport
(
'127.0.0.1'
,
55
),
(
'127.0.0.1'
,
55
))
self
.
assertEqual
(
splitnport
(
'parrot:cheese'
),
(
'parrot'
,
None
))
self
.
assertEqual
(
splitnport
(
'parrot:cheese'
,
55
),
(
'parrot'
,
None
))
def
test_splitquery
(
self
):
# Normal cases are exercised by other tests; ensure that we also
# catch cases with no port specified (testcase ensuring coverage)
splitquery
=
urllib
.
parse
.
splitquery
self
.
assertEqual
(
splitquery
(
'http://python.org/fake?foo=bar'
),
(
'http://python.org/fake'
,
'foo=bar'
))
self
.
assertEqual
(
splitquery
(
'http://python.org/fake?foo=bar?'
),
(
'http://python.org/fake?foo=bar'
,
''
))
self
.
assertEqual
(
splitquery
(
'http://python.org/fake'
),
(
'http://python.org/fake'
,
None
))
self
.
assertEqual
(
splitquery
(
'?foo=bar'
),
(
''
,
'foo=bar'
))
def
test_splittag
(
self
):
splittag
=
urllib
.
parse
.
splittag
self
.
assertEqual
(
splittag
(
'http://example.com?foo=bar#baz'
),
(
'http://example.com?foo=bar'
,
'baz'
))
self
.
assertEqual
(
splittag
(
'http://example.com?foo=bar#'
),
(
'http://example.com?foo=bar'
,
''
))
self
.
assertEqual
(
splittag
(
'#baz'
),
(
''
,
'baz'
))
self
.
assertEqual
(
splittag
(
'http://example.com?foo=bar'
),
(
'http://example.com?foo=bar'
,
None
))
self
.
assertEqual
(
splittag
(
'http://example.com?foo=bar#baz#boo'
),
(
'http://example.com?foo=bar#baz'
,
'boo'
))
def
test_splitattr
(
self
):
splitattr
=
urllib
.
parse
.
splitattr
self
.
assertEqual
(
splitattr
(
'/path;attr1=value1;attr2=value2'
),
(
'/path'
,
[
'attr1=value1'
,
'attr2=value2'
]))
self
.
assertEqual
(
splitattr
(
'/path;'
),
(
'/path'
,
[
''
]))
self
.
assertEqual
(
splitattr
(
';attr1=value1;attr2=value2'
),
(
''
,
[
'attr1=value1'
,
'attr2=value2'
]))
self
.
assertEqual
(
splitattr
(
'/path'
),
(
'/path'
,
[]))
def
test_splitvalue
(
self
):
# Normal cases are exercised by other tests; test pathological cases
# with no key/value pairs. (testcase ensuring coverage)
splitvalue
=
urllib
.
parse
.
splitvalue
self
.
assertEqual
(
splitvalue
(
'foo=bar'
),
(
'foo'
,
'bar'
))
self
.
assertEqual
(
splitvalue
(
'foo='
),
(
'foo'
,
''
))
self
.
assertEqual
(
splitvalue
(
'=bar'
),
(
''
,
'bar'
))
self
.
assertEqual
(
splitvalue
(
'foobar'
),
(
'foobar'
,
None
))
self
.
assertEqual
(
splitvalue
(
'foo=bar=baz'
),
(
'foo'
,
'bar=baz'
))
def
test_to_bytes
(
self
):
result
=
urllib
.
parse
.
to_bytes
(
'http://www.python.org'
)
self
.
assertEqual
(
result
,
'http://www.python.org'
)
self
.
assertRaises
(
UnicodeError
,
urllib
.
parse
.
to_bytes
,
'http://www.python.org/medi
\u00e6
val'
)
def
test_unwrap
(
self
):
url
=
urllib
.
parse
.
unwrap
(
'<URL:type://host/path>'
)
self
.
assertEqual
(
url
,
'type://host/path'
)
if
__name__
==
"__main__"
:
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