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
5be30677
Kaydet (Commit)
5be30677
authored
Ock 26, 2008
tarafından
Neal Norwitz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Prevent this test from failing if there are transient network problems
by retrying the host for up to 3 times.
üst
00417a3b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
10 deletions
+30
-10
test_urllibnet.py
Lib/test/test_urllibnet.py
+30
-10
No files found.
Lib/test/test_urllibnet.py
Dosyayı görüntüle @
5be30677
...
@@ -9,6 +9,20 @@ import sys
...
@@ -9,6 +9,20 @@ import sys
import
os
import
os
import
mimetools
import
mimetools
def
_open_with_retry
(
func
,
host
,
*
args
,
**
kwargs
):
# Connecting to remote hosts is flaky. Make it more robust
# by retrying the connection several times.
for
i
in
range
(
3
):
try
:
return
func
(
host
,
*
args
,
**
kwargs
)
except
IOError
,
last_exc
:
continue
except
:
raise
raise
last_exc
class
URLTimeoutTest
(
unittest
.
TestCase
):
class
URLTimeoutTest
(
unittest
.
TestCase
):
TIMEOUT
=
10.0
TIMEOUT
=
10.0
...
@@ -20,7 +34,7 @@ class URLTimeoutTest(unittest.TestCase):
...
@@ -20,7 +34,7 @@ class URLTimeoutTest(unittest.TestCase):
socket
.
setdefaulttimeout
(
None
)
socket
.
setdefaulttimeout
(
None
)
def
testURLread
(
self
):
def
testURLread
(
self
):
f
=
urllib
.
urlopen
(
"http://www.python.org/"
)
f
=
_open_with_retry
(
urllib
.
urlopen
,
"http://www.python.org/"
)
x
=
f
.
read
()
x
=
f
.
read
()
class
urlopenNetworkTests
(
unittest
.
TestCase
):
class
urlopenNetworkTests
(
unittest
.
TestCase
):
...
@@ -38,9 +52,12 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -38,9 +52,12 @@ class urlopenNetworkTests(unittest.TestCase):
"""
"""
def
urlopen
(
self
,
*
args
):
return
_open_with_retry
(
urllib
.
urlopen
,
*
args
)
def
test_basic
(
self
):
def
test_basic
(
self
):
# Simple test expected to pass.
# Simple test expected to pass.
open_url
=
urllib
.
urlopen
(
"http://www.python.org/"
)
open_url
=
self
.
urlopen
(
"http://www.python.org/"
)
for
attr
in
(
"read"
,
"readline"
,
"readlines"
,
"fileno"
,
"close"
,
for
attr
in
(
"read"
,
"readline"
,
"readlines"
,
"fileno"
,
"close"
,
"info"
,
"geturl"
):
"info"
,
"geturl"
):
self
.
assert_
(
hasattr
(
open_url
,
attr
),
"object returned from "
self
.
assert_
(
hasattr
(
open_url
,
attr
),
"object returned from "
...
@@ -52,7 +69,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -52,7 +69,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_readlines
(
self
):
def
test_readlines
(
self
):
# Test both readline and readlines.
# Test both readline and readlines.
open_url
=
urllib
.
urlopen
(
"http://www.python.org/"
)
open_url
=
self
.
urlopen
(
"http://www.python.org/"
)
try
:
try
:
self
.
assert_
(
isinstance
(
open_url
.
readline
(),
basestring
),
self
.
assert_
(
isinstance
(
open_url
.
readline
(),
basestring
),
"readline did not return a string"
)
"readline did not return a string"
)
...
@@ -63,7 +80,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -63,7 +80,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_info
(
self
):
def
test_info
(
self
):
# Test 'info'.
# Test 'info'.
open_url
=
urllib
.
urlopen
(
"http://www.python.org/"
)
open_url
=
self
.
urlopen
(
"http://www.python.org/"
)
try
:
try
:
info_obj
=
open_url
.
info
()
info_obj
=
open_url
.
info
()
finally
:
finally
:
...
@@ -76,7 +93,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -76,7 +93,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_geturl
(
self
):
def
test_geturl
(
self
):
# Make sure same URL as opened is returned by geturl.
# Make sure same URL as opened is returned by geturl.
URL
=
"http://www.python.org/"
URL
=
"http://www.python.org/"
open_url
=
urllib
.
urlopen
(
URL
)
open_url
=
self
.
urlopen
(
URL
)
try
:
try
:
gotten_url
=
open_url
.
geturl
()
gotten_url
=
open_url
.
geturl
()
finally
:
finally
:
...
@@ -100,7 +117,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -100,7 +117,7 @@ class urlopenNetworkTests(unittest.TestCase):
# test can't pass on Windows.
# test can't pass on Windows.
return
return
# Make sure fd returned by fileno is valid.
# Make sure fd returned by fileno is valid.
open_url
=
urllib
.
urlopen
(
"http://www.python.org/"
)
open_url
=
self
.
urlopen
(
"http://www.python.org/"
)
fd
=
open_url
.
fileno
()
fd
=
open_url
.
fileno
()
FILE
=
os
.
fdopen
(
fd
)
FILE
=
os
.
fdopen
(
fd
)
try
:
try
:
...
@@ -125,9 +142,12 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -125,9 +142,12 @@ class urlopenNetworkTests(unittest.TestCase):
class
urlretrieveNetworkTests
(
unittest
.
TestCase
):
class
urlretrieveNetworkTests
(
unittest
.
TestCase
):
"""Tests urllib.urlretrieve using the network."""
"""Tests urllib.urlretrieve using the network."""
def
urlretrieve
(
self
,
*
args
):
return
_open_with_retry
(
urllib
.
urlretrieve
,
*
args
)
def
test_basic
(
self
):
def
test_basic
(
self
):
# Test basic functionality.
# Test basic functionality.
file_location
,
info
=
urllib
.
urlretrieve
(
"http://www.python.org/"
)
file_location
,
info
=
self
.
urlretrieve
(
"http://www.python.org/"
)
self
.
assert_
(
os
.
path
.
exists
(
file_location
),
"file location returned by"
self
.
assert_
(
os
.
path
.
exists
(
file_location
),
"file location returned by"
" urlretrieve is not a valid path"
)
" urlretrieve is not a valid path"
)
FILE
=
file
(
file_location
)
FILE
=
file
(
file_location
)
...
@@ -140,8 +160,8 @@ class urlretrieveNetworkTests(unittest.TestCase):
...
@@ -140,8 +160,8 @@ class urlretrieveNetworkTests(unittest.TestCase):
def
test_specified_path
(
self
):
def
test_specified_path
(
self
):
# Make sure that specifying the location of the file to write to works.
# Make sure that specifying the location of the file to write to works.
file_location
,
info
=
urllib
.
urlretrieve
(
"http://www.python.org/"
,
file_location
,
info
=
self
.
urlretrieve
(
"http://www.python.org/"
,
test_support
.
TESTFN
)
test_support
.
TESTFN
)
self
.
assertEqual
(
file_location
,
test_support
.
TESTFN
)
self
.
assertEqual
(
file_location
,
test_support
.
TESTFN
)
self
.
assert_
(
os
.
path
.
exists
(
file_location
))
self
.
assert_
(
os
.
path
.
exists
(
file_location
))
FILE
=
file
(
file_location
)
FILE
=
file
(
file_location
)
...
@@ -153,7 +173,7 @@ class urlretrieveNetworkTests(unittest.TestCase):
...
@@ -153,7 +173,7 @@ class urlretrieveNetworkTests(unittest.TestCase):
def
test_header
(
self
):
def
test_header
(
self
):
# Make sure header returned as 2nd value from urlretrieve is good.
# Make sure header returned as 2nd value from urlretrieve is good.
file_location
,
header
=
urllib
.
urlretrieve
(
"http://www.python.org/"
)
file_location
,
header
=
self
.
urlretrieve
(
"http://www.python.org/"
)
os
.
unlink
(
file_location
)
os
.
unlink
(
file_location
)
self
.
assert_
(
isinstance
(
header
,
mimetools
.
Message
),
self
.
assert_
(
isinstance
(
header
,
mimetools
.
Message
),
"header is not an instance of mimetools.Message"
)
"header is not an instance of mimetools.Message"
)
...
...
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