~thumper/bzr/alias-command

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http_response.py

  • Committer: Tim Penhey
  • Date: 2008-05-30 10:57:24 UTC
  • mfrom: (2900.1.561 +trunk)
  • Revision ID: tim@penhey.net-20080530105724-8494sid7i6ajilg4
Merge bzr.dev and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    response,
49
49
    _urllib2_wrappers,
50
50
    )
 
51
from bzrlib.tests.file_utils import (
 
52
    FakeReadFile,
 
53
    )
51
54
 
52
55
 
53
56
class ReadSocket(object):
59
62
    def makefile(self, mode='r', bufsize=None):
60
63
        return self.readfile
61
64
 
 
65
 
62
66
class FakeHTTPConnection(_urllib2_wrappers.HTTPConnection):
63
67
 
64
68
    def __init__(self, sock):
753
757
        out.read()  # Read the whole range
754
758
        # Fail to find the boundary line
755
759
        self.assertRaises(errors.InvalidHttpResponse, out.seek, 1, 1)
 
760
 
 
761
 
 
762
class TestRangeFileSizeReadLimited(tests.TestCase):
 
763
    """Test RangeFile _max_read_size functionality which limits the size of
 
764
    read blocks to prevent MemoryError messages in socket.recv.
 
765
    """
 
766
 
 
767
    def setUp(self):
 
768
        # create a test datablock larger than _max_read_size.
 
769
        chunk_size = response.RangeFile._max_read_size
 
770
        test_pattern = '0123456789ABCDEF'
 
771
        self.test_data =  test_pattern * (3 * chunk_size / len(test_pattern))
 
772
        self.test_data_len = len(self.test_data)
 
773
 
 
774
    def test_max_read_size(self):
 
775
        """Read data in blocks and verify that the reads are not larger than
 
776
           the maximum read size.
 
777
        """
 
778
        # retrieve data in large blocks from response.RangeFile object
 
779
        mock_read_file = FakeReadFile(self.test_data)
 
780
        range_file = response.RangeFile('test_max_read_size', mock_read_file)
 
781
        response_data = range_file.read(self.test_data_len)
 
782
 
 
783
        # verify read size was equal to the maximum read size
 
784
        self.assertTrue(mock_read_file.get_max_read_size() > 0)
 
785
        self.assertEqual(mock_read_file.get_max_read_size(),
 
786
                         response.RangeFile._max_read_size)
 
787
        self.assertEqual(mock_read_file.get_read_count(), 3)
 
788
 
 
789
        # report error if the data wasn't equal (we only report the size due
 
790
        # to the length of the data)
 
791
        if response_data != self.test_data:
 
792
            message = "Data not equal.  Expected %d bytes, received %d."
 
793
            self.fail(message % (len(response_data), self.test_data_len))
 
794