def test_set_parser_unset_prev(self): stream = parsers.StreamBuffer() stream.set_parser(parsers.lines_parser()) unset = stream.unset_parser = unittest.mock.Mock() stream.set_parser(parsers.lines_parser()) self.assertTrue(unset.called)
def test_set_parser_exception(self): stream = parsers.StreamBuffer() exc = ValueError() stream.set_exception(exc) s = stream.set_parser(parsers.lines_parser()) self.assertIs(s.exception(), exc)
def test_exception_waiter(self): stream = parsers.StreamBuffer() stream._parser = parsers.lines_parser() buf = stream._parser_buffer = parsers.DataBuffer() exc = ValueError() stream.set_exception(exc) self.assertIs(buf.exception(), exc)
def test_exception_waiter(self): stream = parsers.StreamBuffer() stream._parser = parsers.lines_parser() buf = stream._parser_buffer = parsers.DataBuffer(loop=self.loop) exc = ValueError() stream.set_exception(exc) self.assertIs(buf.exception(), exc)
def test_set_parser_feed_existing_eof(self): stream = parsers.StreamBuffer() stream.feed_data(b'line1') stream.feed_data(b'\r\nline2\r\ndata') stream.feed_eof() s = stream.set_parser(parsers.lines_parser()) self.assertEqual([bytearray(b'line1\r\n'), bytearray(b'line2\r\n')], list(s._buffer)) self.assertEqual(b'data', bytes(stream._buffer)) self.assertIsNone(stream._parser)
def test_feed_parser2(self): stream = parsers.StreamBuffer() s = stream.set_parser(parsers.lines_parser()) stream.feed_data(b'line1\r\nline2\r\n') stream.feed_eof() self.assertEqual( [bytearray(b'line1\r\n'), bytearray(b'line2\r\n')], list(s._buffer)) self.assertEqual(b'', bytes(stream._buffer)) self.assertTrue(s._eof)
def test_lines_parser(self): out = parsers.DataBuffer() buf = self._make_one() p = parsers.lines_parser() next(p) p.send((out, buf)) for d in (b'line1', b'\r\n', b'lin', b'e2\r', b'\ndata'): p.send(d) self.assertEqual( [bytearray(b'line1\r\n'), bytearray(b'line2\r\n')], list(out._buffer)) try: p.throw(parsers.EofStream()) except parsers.EofStream: pass self.assertEqual(bytes(buf), b'data')
def test_lines_parser(self): out = parsers.DataBuffer(loop=self.loop) buf = self._make_one() p = parsers.lines_parser() next(p) p.send((out, buf)) for d in (b'line1', b'\r\n', b'lin', b'e2\r', b'\ndata'): p.send(d) self.assertEqual( [bytearray(b'line1\r\n'), bytearray(b'line2\r\n')], list(out._buffer)) try: p.throw(parsers.EofStream()) except parsers.EofStream: pass self.assertEqual(bytes(buf), b'data')