Skip to content

bpo-46648: move test_issue16464 to urllib2_localnet #31186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Lib/test/test_urllib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,24 +1788,6 @@ class MyOtherHTTPHandler(urllib.request.HTTPHandler):
self.opener_has_handler(o, MyHTTPHandler)
self.opener_has_handler(o, MyOtherHTTPHandler)

@unittest.skipUnless(support.is_resource_enabled('network'),
'test requires network access')
# bpo-46648: test fails randomly with "http://www.example.com/" URL
@unittest.skipIf(True, "POST request to http://www.example.com/ fail randomly")
def test_issue16464(self):
with socket_helper.transient_internet("http://www.example.com/"):
opener = urllib.request.build_opener()
request = urllib.request.Request("http://www.example.com/")
self.assertEqual(None, request.data)

opener.open(request, "1".encode("us-ascii"))
self.assertEqual(b"1", request.data)
self.assertEqual("1", request.get_header("Content-length"))

opener.open(request, "1234567890".encode("us-ascii"))
self.assertEqual(b"1234567890", request.data)
self.assertEqual("10", request.get_header("Content-length"))

def test_HTTPError_interface(self):
"""
Issue 13211 reveals that HTTPError didn't implement the URLError
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_urllib2_localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,24 @@ def test_line_iteration(self):
(index, len(lines[index]), len(line)))
self.assertEqual(index + 1, len(lines))

def test_issue16464(self):
# See https://bugs.python.org/issue16464
# and https://bugs.python.org/issue46648
handler = self.start_server([
(200, [], b'any'),
(200, [], b'any'),
])
opener = urllib.request.build_opener()
request = urllib.request.Request("http://localhost:%s" % handler.port)
self.assertEqual(None, request.data)

opener.open(request, "1".encode("us-ascii"))
self.assertEqual(b"1", request.data)
self.assertEqual("1", request.get_header("Content-length"))

opener.open(request, "1234567890".encode("us-ascii"))
self.assertEqual(b"1234567890", request.data)
self.assertEqual("10", request.get_header("Content-length"))

def setUpModule():
thread_info = threading_helper.threading_setup()
Expand Down