diff options
| author | Jeremy Hylton <jeremy@alum.mit.edu> | 2007-08-03 20:56:14 +0000 | 
|---|---|---|
| committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2007-08-03 20:56:14 +0000 | 
| commit | 8fff7924a4217dc73de2042168a0eda7243e26d7 (patch) | |
| tree | cfa2d115a3a70144599501a129e560d0246c2015 | |
| parent | 9648d62fd58d9ae9356ab717e3d594a61cb4782a (diff) | |
| download | cpython-git-8fff7924a4217dc73de2042168a0eda7243e26d7.tar.gz | |
Fix tests to use bytes() where the actual sockets return bytes().
Use io.BytesIO() instead of StringIO.StringIO().  FakeSocket still
accepts regular strings and coverts them to bytes internally.
| -rw-r--r-- | Lib/test/test_httplib.py | 14 | 
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index d18ea2b4bc..4c104b7151 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -1,5 +1,5 @@  import httplib -import StringIO +import io  import sys  import socket @@ -8,7 +8,9 @@ from unittest import TestCase  from test import test_support  class FakeSocket: -    def __init__(self, text, fileclass=StringIO.StringIO): +    def __init__(self, text, fileclass=io.BytesIO): +        if isinstance(text, str): +            text = bytes(text)          self.text = text          self.fileclass = fileclass          self.data = b'' @@ -21,20 +23,20 @@ class FakeSocket:              raise httplib.UnimplementedFileMode()          return self.fileclass(self.text) -class NoEOFStringIO(StringIO.StringIO): +class NoEOFStringIO(io.BytesIO):      """Like StringIO, but raises AssertionError on EOF.      This is used below to test that httplib doesn't try to read      more from the underlying file than it should.      """      def read(self, n=-1): -        data = StringIO.StringIO.read(self, n) +        data = io.BytesIO.read(self, n)          if data == '':              raise AssertionError('caller tried to read past EOF')          return data      def readline(self, length=None): -        data = StringIO.StringIO.readline(self, length) +        data = io.BytesIO.readline(self, length)          if data == '':              raise AssertionError('caller tried to read past EOF')          return data @@ -80,7 +82,7 @@ class BasicTest(TestCase):          sock = FakeSocket(body)          resp = httplib.HTTPResponse(sock)          resp.begin() -        self.assertEqual(resp.read(), 'Text') +        self.assertEqual(resp.read(), b"Text")          resp.close()          body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"  | 
