168
168
reader = pack.BytesRecordReader(input.read)
169
169
self.assertRaises(errors.InvalidRecordError, reader.read)
171
def test_early_eof(self):
172
"""Tests for premature EOF occuring during parsing Bytes records with
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.
179
In all cases, UnexpectedEndOfContainerError should be raised.
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.
188
except errors.UnexpectedEndOfContainerError:
192
"UnexpectedEndOfContainerError not raised when parsing %r"
193
% (input.getvalue()))
195
def test_initial(self):
196
"""EOF before any bytes read at all."""
198
reader = pack.BytesRecordReader(input.read)
199
self.assertRaises(errors.UnexpectedEndOfContainerError, reader.read)
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)
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)
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,