mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
Fix tests that tried to sneak strings through httplib.
The httplib interface returns bytes for now.
This commit is contained in:
parent
04319c78d6
commit
66dc8c59be
1 changed files with 13 additions and 13 deletions
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
import httplib
|
import httplib
|
||||||
|
import io
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import os
|
import os
|
||||||
import mimetools
|
import mimetools
|
||||||
import tempfile
|
import tempfile
|
||||||
import StringIO
|
|
||||||
import ftplib
|
import ftplib
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
|
|
@ -99,15 +99,15 @@ class urlopen_HttpTests(unittest.TestCase):
|
||||||
"""Test urlopen() opening a fake http connection."""
|
"""Test urlopen() opening a fake http connection."""
|
||||||
|
|
||||||
def fakehttp(self, fakedata):
|
def fakehttp(self, fakedata):
|
||||||
class FakeSocket(StringIO.StringIO):
|
class FakeSocket(io.BytesIO):
|
||||||
def sendall(self, str): pass
|
def sendall(self, str): pass
|
||||||
def makefile(self, mode, name): return self
|
def makefile(self, mode, name): return self
|
||||||
def read(self, amt=None):
|
def read(self, amt=None):
|
||||||
if self.closed: return ''
|
if self.closed: return b""
|
||||||
return StringIO.StringIO.read(self, amt)
|
return io.BytesIO.read(self, amt)
|
||||||
def readline(self, length=None):
|
def readline(self, length=None):
|
||||||
if self.closed: return ''
|
if self.closed: return b""
|
||||||
return StringIO.StringIO.readline(self, length)
|
return io.BytesIO.readline(self, length)
|
||||||
class FakeHTTPConnection(httplib.HTTPConnection):
|
class FakeHTTPConnection(httplib.HTTPConnection):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.sock = FakeSocket(fakedata)
|
self.sock = FakeSocket(fakedata)
|
||||||
|
|
@ -118,20 +118,20 @@ class urlopen_HttpTests(unittest.TestCase):
|
||||||
httplib.HTTP._connection_class = httplib.HTTPConnection
|
httplib.HTTP._connection_class = httplib.HTTPConnection
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
self.fakehttp('Hello!')
|
self.fakehttp(b"Hello!")
|
||||||
try:
|
try:
|
||||||
fp = urllib.urlopen("http://python.org/")
|
fp = urllib.urlopen("http://python.org/")
|
||||||
self.assertEqual(fp.readline(), 'Hello!')
|
self.assertEqual(fp.readline(), b"Hello!")
|
||||||
self.assertEqual(fp.readline(), '')
|
self.assertEqual(fp.readline(), b"")
|
||||||
finally:
|
finally:
|
||||||
self.unfakehttp()
|
self.unfakehttp()
|
||||||
|
|
||||||
def test_empty_socket(self):
|
def test_empty_socket(self):
|
||||||
"""urlopen() raises IOError if the underlying socket does not send any
|
# urlopen() raises IOError if the underlying socket does not send any
|
||||||
data. (#1680230) """
|
# data. (#1680230)
|
||||||
self.fakehttp('')
|
self.fakehttp(b"")
|
||||||
try:
|
try:
|
||||||
self.assertRaises(IOError, urllib.urlopen, 'http://something')
|
self.assertRaises(IOError, urllib.urlopen, "http://something")
|
||||||
finally:
|
finally:
|
||||||
self.unfakehttp()
|
self.unfakehttp()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue