(self)
| 280 | self.assertTrue(stream.at_eof()) |
| 281 | |
| 282 | def test_readline_limit(self): |
| 283 | # Read one line. StreamReaders are fed with data after |
| 284 | # their 'readline' methods are called. |
| 285 | |
| 286 | stream = asyncio.StreamReader(limit=7, loop=self.loop) |
| 287 | def cb(): |
| 288 | stream.feed_data(b'chunk1') |
| 289 | stream.feed_data(b'chunk2') |
| 290 | stream.feed_data(b'chunk3\n') |
| 291 | stream.feed_eof() |
| 292 | self.loop.call_soon(cb) |
| 293 | |
| 294 | self.assertRaises( |
| 295 | ValueError, self.loop.run_until_complete, stream.readline()) |
| 296 | # The buffer had just one line of data, and after raising |
| 297 | # a ValueError it should be empty. |
| 298 | self.assertEqual(b'', stream._buffer) |
| 299 | |
| 300 | stream = asyncio.StreamReader(limit=7, loop=self.loop) |
| 301 | def cb(): |
| 302 | stream.feed_data(b'chunk1') |
| 303 | stream.feed_data(b'chunk2\n') |
| 304 | stream.feed_data(b'chunk3\n') |
| 305 | stream.feed_eof() |
| 306 | self.loop.call_soon(cb) |
| 307 | |
| 308 | self.assertRaises( |
| 309 | ValueError, self.loop.run_until_complete, stream.readline()) |
| 310 | self.assertEqual(b'chunk3\n', stream._buffer) |
| 311 | |
| 312 | # check strictness of the limit |
| 313 | stream = asyncio.StreamReader(limit=7, loop=self.loop) |
| 314 | stream.feed_data(b'1234567\n') |
| 315 | line = self.loop.run_until_complete(stream.readline()) |
| 316 | self.assertEqual(b'1234567\n', line) |
| 317 | self.assertEqual(b'', stream._buffer) |
| 318 | |
| 319 | stream.feed_data(b'12345678\n') |
| 320 | with self.assertRaises(ValueError) as cm: |
| 321 | self.loop.run_until_complete(stream.readline()) |
| 322 | self.assertEqual(b'', stream._buffer) |
| 323 | |
| 324 | stream.feed_data(b'12345678') |
| 325 | with self.assertRaises(ValueError) as cm: |
| 326 | self.loop.run_until_complete(stream.readline()) |
| 327 | self.assertEqual(b'', stream._buffer) |
| 328 | |
| 329 | def test_readline_nolimit_nowait(self): |
| 330 | # All needed data for the first 'readline' call will be |
nothing calls this directly
no test coverage detected