Exemple #1
0
 def test_readline_incr(self):
     reader = StreamReader()
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         reader.feed(buf[i:i+1])
     self.assertEqual(reader.readline(), b'foo\n')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #2
0
 def test_readline(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     self.assertEqual(reader.readline(), b'foo\n')
     reader.feed(b'bar\nbaz\n')
     self.assertEqual(reader.readline(), b'bar\n')
     self.assertEqual(reader.readline(), b'baz\n')
Exemple #3
0
 def test_readline_incr(self):
     reader = StreamReader()
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         reader.feed(buf[i:i + 1])
     self.assertEqual(reader.readline(), b'foo\n')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #4
0
 def test_readline(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     self.assertEqual(reader.readline(), b'foo\n')
     reader.feed(b'bar\nbaz\n')
     self.assertEqual(reader.readline(), b'bar\n')
     self.assertEqual(reader.readline(), b'baz\n')
Exemple #5
0
 def test_read_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foo')
     self.assertEqual(reader.read(), b'')
     reader.feed_error(RuntimeError)
Exemple #6
0
 def test_read(self):
     reader = StreamReader()
     reader.feed(b'foo')
     self.assertEqual(reader.read(3), b'foo')
     reader.feed(b'foo bar')
     self.assertEqual(reader.read(3), b'foo')
     self.assertEqual(reader.read(4), b' bar')
Exemple #7
0
 def test_read_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foo')
     self.assertEqual(reader.read(), b'')
     reader.feed_error(RuntimeError)
Exemple #8
0
 def test_read(self):
     reader = StreamReader()
     reader.feed(b'foo')
     self.assertEqual(reader.read(3), b'foo')
     reader.feed(b'foo bar')
     self.assertEqual(reader.read(3), b'foo')
     self.assertEqual(reader.read(4), b' bar')
Exemple #9
0
 def test_read_incr(self):
     reader = StreamReader()
     buf = b'foobar'
     for i in range(len(buf)):
         reader.feed(buf[i:i + 1])
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foobar')
Exemple #10
0
 def test_read_incr(self):
     reader = StreamReader()
     buf = b'foobar'
     for i in range(len(buf)):
         reader.feed(buf[i:i+1])
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foobar')
Exemple #11
0
 def test_partial_decode_at_eof(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     # \u20ac is the euro sign in case you wondered..
     buf = u'20 \u20ac'.encode('utf-8')
     reader.feed(buf[:-1])
     reader.feed_eof()
     self.assertRaises(UnicodeDecodeError, wrapped.read, 4)
Exemple #12
0
 def test_iter_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_eof()
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(StopIteration, six.next, it)
Exemple #13
0
 def test_iter_error(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_error(RuntimeError)
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(RuntimeError, six.next, it)
Exemple #14
0
 def test_iter_error(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_error(RuntimeError)
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(RuntimeError, six.next, it)
Exemple #15
0
 def test_iter_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_eof()
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(StopIteration, six.next, it)
Exemple #16
0
 def test_partial_decode_at_eof(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     # \u20ac is the euro sign in case you wondered..
     buf = u'20 \u20ac'.encode('utf-8')
     reader.feed(buf[:-1])
     reader.feed_eof()
     self.assertRaises(UnicodeDecodeError, wrapped.read, 4)
Exemple #17
0
 def test_partial_decode_wait(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     buf = u'20 \u20ac'.encode('utf-8')
     reader.feed(buf[:-1])
     def write_last():
         gruvi.sleep(0.01)
         reader.feed(buf[-1:])
     gruvi.spawn(write_last)
     self.assertEqual(wrapped.read(4), u'20 \u20ac')
Exemple #18
0
 def test_read_wait_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar')
         gruvi.sleep(0.01)
         reader.feed_error(RuntimeError)
     gruvi.spawn(write_more)
     self.assertEqual(reader.read(), b'foobar')
     self.assertRaises(RuntimeError, reader.read)
Exemple #19
0
 def test_readlines_wait_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar\n')
         gruvi.sleep(0.01)
         reader.feed_eof()
     gruvi.spawn(write_more)
     self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(reader.readlines(), [])
Exemple #20
0
 def test_read_wait(self):
     reader = StreamReader()
     reader.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar')
         gruvi.sleep(0.01)
         reader.feed_eof()
     gruvi.spawn(write_more)
     self.assertEqual(reader.read(), b'foobar')
     self.assertEqual(reader.read(), b'')
Exemple #21
0
    def test_partial_decode_wait(self):
        reader = StreamReader()
        wrapped = TextIOWrapper(reader, 'utf-8')
        buf = u'20 \u20ac'.encode('utf-8')
        reader.feed(buf[:-1])

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

        gruvi.spawn(write_last)
        self.assertEqual(wrapped.read(4), u'20 \u20ac')
Exemple #22
0
 def test_iter_wait_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar\n')
         gruvi.sleep(0.01)
         reader.feed_eof()
     gruvi.spawn(write_more)
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(StopIteration, six.next, it)
Exemple #23
0
 def test_iter_wait_error(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar\n')
         gruvi.sleep(0.01)
         reader.feed_error(RuntimeError)
     gruvi.spawn(write_more)
     it = iter(reader)
     self.assertEqual(six.next(it), b'foo\n')
     self.assertEqual(six.next(it), b'bar\n')
     self.assertRaises(RuntimeError, six.next, it)
Exemple #24
0
    def test_read_wait(self):
        reader = StreamReader()
        reader.feed(b'foo')

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

        gruvi.spawn(write_more)
        self.assertEqual(reader.read(), b'foobar')
        self.assertEqual(reader.read(), b'')
Exemple #25
0
    def test_readlines_wait_eof(self):
        reader = StreamReader()
        reader.feed(b'foo\n')

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

        gruvi.spawn(write_more)
        self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
        self.assertEqual(reader.readlines(), [])
Exemple #26
0
    def test_read_wait_error(self):
        reader = StreamReader()
        reader.feed(b'foo')

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

        gruvi.spawn(write_more)
        self.assertEqual(reader.read(), b'foobar')
        self.assertRaises(RuntimeError, reader.read)
Exemple #27
0
    def test_iter_wait_error(self):
        reader = StreamReader()
        reader.feed(b'foo\n')

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

        gruvi.spawn(write_more)
        it = iter(reader)
        self.assertEqual(six.next(it), b'foo\n')
        self.assertEqual(six.next(it), b'bar\n')
        self.assertRaises(RuntimeError, six.next, it)
Exemple #28
0
    def test_iter_wait_eof(self):
        reader = StreamReader()
        reader.feed(b'foo\n')

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

        gruvi.spawn(write_more)
        it = iter(reader)
        self.assertEqual(six.next(it), b'foo\n')
        self.assertEqual(six.next(it), b'bar\n')
        self.assertRaises(StopIteration, six.next, it)
Exemple #29
0
 def test_readlines_error(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
     self.assertRaises(RuntimeError, reader.readlines)
Exemple #30
0
 def test_readlines_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_eof()
     self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(reader.readlines(), [])
Exemple #31
0
 def test_readlines_limit(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     self.assertEqual(reader.readlines(4), [b'foo\n', b'bar\n'])
Exemple #32
0
 def test_read_eof(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(wrapped.read(), 'foo')
Exemple #33
0
 def test_simple(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     reader.feed(b'foo')
     self.assertEqual(wrapped.read(3), 'foo')
Exemple #34
0
 def test_readlines_error(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
     self.assertRaises(RuntimeError, reader.readlines)
Exemple #35
0
 def test_readline_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.readline(), b'foo')
     self.assertEqual(reader.readline(), b'')
Exemple #36
0
 def test_readline_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readline(), b'foo')
     self.assertRaises(RuntimeError, reader.readline)
Exemple #37
0
 def test_simple(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     reader.feed(b'foo')
     self.assertEqual(wrapped.read(3), 'foo')
Exemple #38
0
 def test_read_eof(self):
     reader = StreamReader()
     wrapped = TextIOWrapper(reader, 'utf-8')
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(wrapped.read(), 'foo')
Exemple #39
0
 def test_readlines_limit(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     self.assertEqual(reader.readlines(4), [b'foo\n', b'bar\n'])
Exemple #40
0
 def test_readlines_eof(self):
     reader = StreamReader()
     reader.feed(b'foo\nbar\n')
     reader.feed_eof()
     self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n'])
     self.assertEqual(reader.readlines(), [])
Exemple #41
0
 def test_readline_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.readline(), b'foo')
     self.assertEqual(reader.readline(), b'')
Exemple #42
0
 def test_readline_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readline(), b'foo')
     self.assertRaises(RuntimeError, reader.readline)
Exemple #43
0
 def test_readline_limit(self):
     reader = StreamReader()
     reader.feed(b'foobar\n')
     self.assertEqual(reader.readline(3), b'foo')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #44
0
 def test_readline_limit(self):
     reader = StreamReader()
     reader.feed(b'foobar\n')
     self.assertEqual(reader.readline(3), b'foo')
     self.assertEqual(reader.readline(), b'bar\n')