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
a8e3b0a1
Commit
a8e3b0a1
authored
May 07, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Plain Diff
Replace example.com with pythontest.net in test_urllibnet
example.com/404 returns 500 instead of 404 now.
parents
17e22959
a40b0ef6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
Lib/test/test_urllibnet.py
Lib/test/test_urllibnet.py
+13
-12
No files found.
Lib/test/test_urllibnet.py
View file @
a8e3b0a1
...
@@ -37,12 +37,14 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -37,12 +37,14 @@ class urlopenNetworkTests(unittest.TestCase):
for transparent redirection have been written.
for transparent redirection have been written.
setUp is not used for always constructing a connection to
setUp is not used for always constructing a connection to
http://www.
example.com
/ since there a few tests that don't use that address
http://www.
pythontest.net
/ since there a few tests that don't use that address
and making a connection is expensive enough to warrant minimizing unneeded
and making a connection is expensive enough to warrant minimizing unneeded
connections.
connections.
"""
"""
url
=
'http://www.pythontest.net/'
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
def
urlopen
(
self
,
*
args
,
**
kwargs
):
def
urlopen
(
self
,
*
args
,
**
kwargs
):
resource
=
args
[
0
]
resource
=
args
[
0
]
...
@@ -55,7 +57,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -55,7 +57,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_basic
(
self
):
def
test_basic
(
self
):
# Simple test expected to pass.
# Simple test expected to pass.
with
self
.
urlopen
(
"http://www.example.com/"
)
as
open_url
:
with
self
.
urlopen
(
self
.
url
)
as
open_url
:
for
attr
in
(
"read"
,
"readline"
,
"readlines"
,
"fileno"
,
"close"
,
for
attr
in
(
"read"
,
"readline"
,
"readlines"
,
"fileno"
,
"close"
,
"info"
,
"geturl"
):
"info"
,
"geturl"
):
self
.
assertTrue
(
hasattr
(
open_url
,
attr
),
"object returned from "
self
.
assertTrue
(
hasattr
(
open_url
,
attr
),
"object returned from "
...
@@ -64,7 +66,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -64,7 +66,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_readlines
(
self
):
def
test_readlines
(
self
):
# Test both readline and readlines.
# Test both readline and readlines.
with
self
.
urlopen
(
"http://www.example.com/"
)
as
open_url
:
with
self
.
urlopen
(
self
.
url
)
as
open_url
:
self
.
assertIsInstance
(
open_url
.
readline
(),
bytes
,
self
.
assertIsInstance
(
open_url
.
readline
(),
bytes
,
"readline did not return a string"
)
"readline did not return a string"
)
self
.
assertIsInstance
(
open_url
.
readlines
(),
list
,
self
.
assertIsInstance
(
open_url
.
readlines
(),
list
,
...
@@ -72,7 +74,7 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -72,7 +74,7 @@ class urlopenNetworkTests(unittest.TestCase):
def
test_info
(
self
):
def
test_info
(
self
):
# Test 'info'.
# Test 'info'.
with
self
.
urlopen
(
"http://www.example.com/"
)
as
open_url
:
with
self
.
urlopen
(
self
.
url
)
as
open_url
:
info_obj
=
open_url
.
info
()
info_obj
=
open_url
.
info
()
self
.
assertIsInstance
(
info_obj
,
email
.
message
.
Message
,
self
.
assertIsInstance
(
info_obj
,
email
.
message
.
Message
,
"object returned by 'info' is not an "
"object returned by 'info' is not an "
...
@@ -81,14 +83,13 @@ class urlopenNetworkTests(unittest.TestCase):
...
@@ -81,14 +83,13 @@ 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.example.com/"
with
self
.
urlopen
(
self
.
url
)
as
open_url
:
with
self
.
urlopen
(
URL
)
as
open_url
:
gotten_url
=
open_url
.
geturl
()
gotten_url
=
open_url
.
geturl
()
self
.
assertEqual
(
gotten_url
,
URL
)
self
.
assertEqual
(
gotten_url
,
self
.
url
)
def
test_getcode
(
self
):
def
test_getcode
(
self
):
# test getcode() with the fancy opener to get 404 error codes
# test getcode() with the fancy opener to get 404 error codes
URL
=
"http://www.example.com/
XXXinvalidXXX"
URL
=
self
.
url
+
"
XXXinvalidXXX"
with
support
.
transient_internet
(
URL
):
with
support
.
transient_internet
(
URL
):
with
self
.
assertWarns
(
DeprecationWarning
):
with
self
.
assertWarns
(
DeprecationWarning
):
open_url
=
urllib
.
request
.
FancyURLopener
().
open
(
URL
)
open_url
=
urllib
.
request
.
FancyURLopener
().
open
(
URL
)
...
@@ -152,7 +153,7 @@ class urlretrieveNetworkTests(unittest.TestCase):
...
@@ -152,7 +153,7 @@ class urlretrieveNetworkTests(unittest.TestCase):
def
test_basic
(
self
):
def
test_basic
(
self
):
# Test basic functionality.
# Test basic functionality.
with
self
.
urlretrieve
(
"http://www.example.com/"
)
as
(
file_location
,
info
):
with
self
.
urlretrieve
(
self
.
logo
)
as
(
file_location
,
info
):
self
.
assertTrue
(
os
.
path
.
exists
(
file_location
),
"file location returned by"
self
.
assertTrue
(
os
.
path
.
exists
(
file_location
),
"file location returned by"
" urlretrieve is not a valid path"
)
" urlretrieve is not a valid path"
)
with
open
(
file_location
,
'rb'
)
as
f
:
with
open
(
file_location
,
'rb'
)
as
f
:
...
@@ -161,7 +162,7 @@ class urlretrieveNetworkTests(unittest.TestCase):
...
@@ -161,7 +162,7 @@ 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.
with
self
.
urlretrieve
(
"http://www.example.com/"
,
with
self
.
urlretrieve
(
self
.
logo
,
support
.
TESTFN
)
as
(
file_location
,
info
):
support
.
TESTFN
)
as
(
file_location
,
info
):
self
.
assertEqual
(
file_location
,
support
.
TESTFN
)
self
.
assertEqual
(
file_location
,
support
.
TESTFN
)
self
.
assertTrue
(
os
.
path
.
exists
(
file_location
))
self
.
assertTrue
(
os
.
path
.
exists
(
file_location
))
...
@@ -170,11 +171,11 @@ class urlretrieveNetworkTests(unittest.TestCase):
...
@@ -170,11 +171,11 @@ 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.
with
self
.
urlretrieve
(
"http://www.example.com/"
)
as
(
file_location
,
info
):
with
self
.
urlretrieve
(
self
.
logo
)
as
(
file_location
,
info
):
self
.
assertIsInstance
(
info
,
email
.
message
.
Message
,
self
.
assertIsInstance
(
info
,
email
.
message
.
Message
,
"info is not an instance of email.message.Message"
)
"info is not an instance of email.message.Message"
)
logo
=
"http://www.
example.com
/"
logo
=
"http://www.
pythontest.net
/"
def
test_data_header
(
self
):
def
test_data_header
(
self
):
with
self
.
urlretrieve
(
self
.
logo
)
as
(
file_location
,
fileheaders
):
with
self
.
urlretrieve
(
self
.
logo
)
as
(
file_location
,
fileheaders
):
...
...
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