~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack.py

  • Committer: Andrew Bennetts
  • Date: 2007-06-09 03:45:25 UTC
  • mto: (2506.2.2 container-format)
  • mto: This revision was merged to the branch mainline in revision 2572.
  • Revision ID: andrew.bennetts@canonical.com-20070609034525-j9d7i5dlk6ou97eb
Deal with EOF in the middle of a bytes record.

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
        reader = pack.BytesRecordReader(input.read)
169
169
        self.assertRaises(errors.InvalidRecordError, reader.read)
170
170
 
 
171
    def test_early_eof(self):
 
172
        """Tests for premature EOF occuring during parsing Bytes records with
 
173
        BytesRecordReader.
 
174
        
 
175
        A incomplete container might be interrupted at any point.  The
 
176
        BytesRecordReader needs to cope with the input stream running out no
 
177
        matter where it is in the parsing process.
 
178
 
 
179
        In all cases, UnexpectedEndOfContainerError should be raised.
 
180
        """
 
181
        complete_record = "6\nname\n\nabcdef"
 
182
        for count in range(0, len(complete_record)):
 
183
            input = StringIO(complete_record[:count])
 
184
            reader = pack.BytesRecordReader(input.read)
 
185
            # We don't use assertRaises to make diagnosing failures easier.
 
186
            try:
 
187
                reader.read()
 
188
            except errors.UnexpectedEndOfContainerError:
 
189
                pass
 
190
            else:
 
191
                self.fail(
 
192
                    "UnexpectedEndOfContainerError not raised when parsing %r"
 
193
                    % (input.getvalue()))
 
194
 
 
195
    def test_initial(self):
 
196
        """EOF before any bytes read at all."""
 
197
        input = StringIO("")
 
198
        reader = pack.BytesRecordReader(input.read)
 
199
        self.assertRaises(errors.UnexpectedEndOfContainerError, reader.read)
 
200
 
 
201
    def test_after_length(self):
 
202
        """EOF after reading the length and before reading name(s)."""
 
203
        input = StringIO("123\n")
 
204
        reader = pack.BytesRecordReader(input.read)
 
205
        self.assertRaises(errors.UnexpectedEndOfContainerError, reader.read)
 
206
 
 
207
    def test_during_name(self):
 
208
        """EOF during reading a name."""
 
209
        input = StringIO("123\nname")
 
210
        reader = pack.BytesRecordReader(input.read)
 
211
        self.assertRaises(errors.UnexpectedEndOfContainerError, reader.read)
 
212
 
 
213
        
171
214
    # Other Bytes record parsing cases to test:
172
215
    #  - incomplete bytes (i.e. stream ends before $length bytes read)
173
216
    #  - _read_line encountering end of stream (at any time; during length,