Exemplo n.º 1
0
 def test_readlines_eof_and_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     stream.buffer.feed_eof()
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(stream.readlines(), [])
Exemplo n.º 2
0
 def test_read_eof_and_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.read(), b'foo')
     self.assertEqual(stream.read(), b'')
Exemplo n.º 3
0
 def test_readline(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\n')
     self.assertEqual(stream.readline(), b'foo\n')
     stream.buffer.feed(b'bar\nbaz\n')
     self.assertEqual(stream.readline(), b'bar\n')
     self.assertEqual(stream.readline(), b'baz\n')
Exemplo n.º 4
0
 def test_read(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     self.assertEqual(stream.read(3), b'foo')
     stream.buffer.feed(b'foo bar')
     self.assertEqual(stream.read(3), b'foo')
     self.assertEqual(stream.read(4), b' bar')
Exemplo n.º 5
0
 def test_read_eof_and_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.read(), b'foo')
     self.assertEqual(stream.read(), b'')
Exemplo n.º 6
0
 def test_readlines_eof_and_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     stream.buffer.feed_eof()
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(stream.readlines(), [])
Exemplo n.º 7
0
 def test_read_incr(self):
     stream = Stream(None)
     buf = b'foobar'
     for i in range(len(buf)):
         stream.buffer.feed(buf[i:i + 1])
     stream.buffer.feed_eof()
     self.assertEqual(stream.read(), b'foobar')
Exemplo n.º 8
0
 def test_readline_incr(self):
     stream = Stream(None)
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         stream.buffer.feed(buf[i:i + 1])
     self.assertEqual(stream.readline(), b'foo\n')
     self.assertEqual(stream.readline(), b'bar\n')
Exemplo n.º 9
0
 def test_read(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     self.assertEqual(stream.read(3), b'foo')
     stream.buffer.feed(b'foo bar')
     self.assertEqual(stream.read(3), b'foo')
     self.assertEqual(stream.read(4), b' bar')
Exemplo n.º 10
0
 def test_read_incr(self):
     stream = Stream(None)
     buf = b'foobar'
     for i in range(len(buf)):
         stream.buffer.feed(buf[i:i+1])
     stream.buffer.feed_eof()
     self.assertEqual(stream.read(), b'foobar')
Exemplo n.º 11
0
 def test_readline(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\n')
     self.assertEqual(stream.readline(), b'foo\n')
     stream.buffer.feed(b'bar\nbaz\n')
     self.assertEqual(stream.readline(), b'bar\n')
     self.assertEqual(stream.readline(), b'baz\n')
Exemplo n.º 12
0
 def test_write(self):
     transport = MockTransport()
     stream = Stream(transport)
     wrapped = stream.wrap('utf-8')
     wrapped.write(u'foo')
     wrapped.flush()
     self.assertEqual(transport.buffer.getvalue(), b'foo')
Exemplo n.º 13
0
 def test_readline_incr(self):
     stream = Stream(None)
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         stream.buffer.feed(buf[i:i+1])
     self.assertEqual(stream.readline(), b'foo\n')
     self.assertEqual(stream.readline(), b'bar\n')
Exemplo n.º 14
0
 def test_partial_decode_at_eof(self):
     stream = Stream(None)
     wrapped = stream.wrap('utf-8')
     # \u20ac is the euro sign in case you wondered..
     buf = u'20 \u20ac'.encode('utf-8')
     stream.buffer.feed(buf[:-1])
     stream.buffer.feed_eof()
     self.assertRaises(UnicodeDecodeError, wrapped.read, 4)
Exemplo n.º 15
0
 def test_partial_decode_wait(self):
     stream = Stream(None)
     wrapped = stream.wrap('utf-8')
     buf = u'20 \u20ac'.encode('utf-8')
     stream.buffer.feed(buf[:-1])
     def write_last_byte():
         gruvi.sleep(0.01)
         stream.buffer.feed(buf[-1:])
     gruvi.spawn(write_last_byte)
     self.assertEqual(wrapped.read(4), u'20 \u20ac')
Exemplo n.º 16
0
 def test_read_wait(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         stream.buffer.feed(b'bar')
         gruvi.sleep(0.01)
         stream.buffer.feed_eof()
     gruvi.spawn(write_more)
     self.assertEqual(stream.read(), b'foobar')
     self.assertEqual(stream.read(), b'')
Exemplo n.º 17
0
 def test_readlines_wait_eof(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\n')
     def write_more():
         gruvi.sleep(0.01)
         stream.buffer.feed(b'bar\n')
         gruvi.sleep(0.01)
         stream.buffer.feed_eof()
     gruvi.spawn(write_more)
     self.assertEqual(stream.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(stream.readlines(), [])
Exemplo n.º 18
0
 def test_read_wait_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         stream.buffer.feed(b'bar')
         gruvi.sleep(0.01)
         stream.buffer.feed_error(RuntimeError)
     gruvi.spawn(write_more)
     self.assertEqual(stream.read(), b'foobar')
     self.assertRaises(RuntimeError, stream.read)
Exemplo n.º 19
0
    def test_read_wait_error(self):
        stream = Stream(None)
        stream.buffer.feed(b'foo')

        def write_more():
            gruvi.sleep(0.01)
            stream.buffer.feed(b'bar')
            gruvi.sleep(0.01)
            stream.buffer.feed_error(RuntimeError)

        gruvi.spawn(write_more)
        self.assertEqual(stream.read(), b'foobar')
        self.assertRaises(RuntimeError, stream.read)
Exemplo n.º 20
0
    def test_read_wait(self):
        stream = Stream(None)
        stream.buffer.feed(b'foo')

        def write_more():
            gruvi.sleep(0.01)
            stream.buffer.feed(b'bar')
            gruvi.sleep(0.01)
            stream.buffer.feed_eof()

        gruvi.spawn(write_more)
        self.assertEqual(stream.read(), b'foobar')
        self.assertEqual(stream.read(), b'')
Exemplo n.º 21
0
    def test_readlines_wait_eof(self):
        stream = Stream(None)
        stream.buffer.feed(b'foo\n')

        def write_more():
            gruvi.sleep(0.01)
            stream.buffer.feed(b'bar\n')
            gruvi.sleep(0.01)
            stream.buffer.feed_eof()

        gruvi.spawn(write_more)
        self.assertEqual(stream.readlines(), [b'foo\n', b'bar\n'])
        self.assertEqual(stream.readlines(), [])
Exemplo n.º 22
0
 def test_iter_eof(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     stream.buffer.feed_eof()
     it = iter(stream)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(StopIteration, six.next, it)
Exemplo n.º 23
0
 def test_iter_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     stream.buffer.feed_error(RuntimeError)
     it = iter(stream)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(RuntimeError, six.next, it)
Exemplo n.º 24
0
 def test_partial_decode_at_eof(self):
     stream = Stream(None)
     wrapped = TextIOWrapper(stream, 'utf-8')
     # \u20ac is the euro sign in case you wondered..
     buf = u'20 \u20ac'.encode('utf-8')
     stream.buffer.feed(buf[:-1])
     stream.buffer.feed_eof()
     self.assertRaises(UnicodeDecodeError, wrapped.read, 4)
Exemplo n.º 25
0
    def test_partial_decode_wait(self):
        stream = Stream(None)
        wrapped = TextIOWrapper(stream, 'utf-8')
        buf = u'20 \u20ac'.encode('utf-8')
        stream.buffer.feed(buf[:-1])

        def write_last():
            gruvi.sleep(0.01)
            stream.buffer.feed(buf[-1:])

        gruvi.spawn(write_last)
        self.assertEqual(wrapped.read(4), u'20 \u20ac')
Exemplo n.º 26
0
    def test_iter_wait_error(self):
        stream = Stream(None)
        stream.buffer.feed(b'foo\n')

        def write_more():
            gruvi.sleep(0.01)
            stream.buffer.feed(b'bar\n')
            gruvi.sleep(0.01)
            stream.buffer.feed_error(RuntimeError)

        gruvi.spawn(write_more)
        it = iter(stream)
        self.assertEqual(six.next(it), b'foo\n')
        self.assertEqual(six.next(it), b'bar\n')
        self.assertRaises(RuntimeError, six.next, it)
Exemplo n.º 27
0
 def test_write_through(self):
     transport = MockTransport()
     stream = Stream(transport)
     stream.write(b'foo')
     self.assertEqual(transport.buffer.getvalue(), b'foo')
Exemplo n.º 28
0
 def test_simple(self):
     stream = Stream(None)
     wrapped = stream.wrap('utf-8')
     stream.buffer.feed(b'foo')
     self.assertEqual(wrapped.read(3), 'foo')
Exemplo n.º 29
0
 def test_read_eof(self):
     stream = Stream(None)
     wrapped = stream.wrap('utf-8')
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     self.assertEqual(wrapped.read(), 'foo')
Exemplo n.º 30
0
 def test_read_eof(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     self.assertEqual(stream.read(), b'foo')
     self.assertEqual(stream.read(), b'')
Exemplo n.º 31
0
 def test_writelines(self):
     transport = MockTransport()
     stream = Stream(transport)
     wrapped = stream.wrap('utf-8')
     wrapped.writelines([u'foo', u'bar'])
     self.assertEqual(transport.buffer.getvalue(), b'foobar')
Exemplo n.º 32
0
 def test_readline_limit(self):
     stream = Stream(None)
     stream.buffer.feed(b'foobar\n')
     self.assertEqual(stream.readline(3), b'foo')
     self.assertEqual(stream.readline(), b'bar\n')
Exemplo n.º 33
0
 def test_readline_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.readline(), b'foo')
     self.assertRaises(RuntimeError, stream.readline)
Exemplo n.º 34
0
 def test_readlines_limit(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     self.assertEqual(stream.readlines(4), [b'foo\n', b'bar\n'])
Exemplo n.º 35
0
 def test_readlines_limit(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo\nbar\n')
     self.assertEqual(stream.readlines(4), [b'foo\n', b'bar\n'])
Exemplo n.º 36
0
 def test_readline_error(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_error(RuntimeError)
     self.assertEqual(stream.readline(), b'foo')
     self.assertRaises(RuntimeError, stream.readline)
Exemplo n.º 37
0
 def test_readline_limit(self):
     stream = Stream(None)
     stream.buffer.feed(b'foobar\n')
     self.assertEqual(stream.readline(3), b'foo')
     self.assertEqual(stream.readline(), b'bar\n')
Exemplo n.º 38
0
 def test_read_eof(self):
     stream = Stream(None)
     wrapped = TextIOWrapper(stream, 'utf-8')
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     self.assertEqual(wrapped.read(), 'foo')
Exemplo n.º 39
0
 def test_writelines(self):
     transport = MockTransport()
     stream = Stream(transport)
     stream.writelines([b'foo', b'bar'])
     self.assertEqual(transport.buffer.getvalue(), b'foobar')
Exemplo n.º 40
0
 def test_read_eof(self):
     stream = Stream(None)
     stream.buffer.feed(b'foo')
     stream.buffer.feed_eof()
     self.assertEqual(stream.read(), b'foo')
     self.assertEqual(stream.read(), b'')