コード例 #1
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_body_readline(self):
     body = BytesIO(b'1234567890\n1234567\n12345\n')
     stream = response.StreamingBody(body, content_length=25)
     chunk = stream.readline()
     self.assertEqual(chunk, b'1234567890\n')
     chunk = stream.readline()
     self.assertEqual(chunk, b'1234567\n')
コード例 #2
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_line_iterator_keepends(self):
     body = six.BytesIO(b'1234567890\n1234567890\n12345')
     stream = response.StreamingBody(body, content_length=27)
     self.assert_lines(
         stream.iter_lines(keepends=True),
         [b'1234567890\n', b'1234567890\n', b'12345'],
     )
コード例 #3
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_line_iterator(self):
     body = BytesIO(b'1234567890\n1234567890\n12345')
     stream = response.StreamingBody(body, content_length=27)
     self.assert_lines(
         stream.iter_lines(),
         [b'1234567890', b'1234567890', b'12345'],
     )
コード例 #4
0
 def test_streaming_line_iterator_ends_newline(self):
     body = six.BytesIO(b'1234567890\n1234567890\n12345\n')
     stream = response.StreamingBody(body, content_length=28)
     self.assert_lines(
         stream.iter_lines(),
         [b'1234567890', b'1234567890', b'12345'],
     )
コード例 #5
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_body_readable(self):
     body = BytesIO(b'1234567890')
     stream = response.StreamingBody(body, content_length=10)
     self.assertTrue(stream.readable())
     stream.close()
     with self.assertRaises(ValueError):
         stream.readable()
コード例 #6
0
 def test_streaming_line_abstruse_newline_standard(self):
     for chunk_size in range(1, 30):
         body = six.BytesIO(b'1234567890\r\n1234567890\r\n12345\r\n')
         stream = response.StreamingBody(body, content_length=31)
         self.assert_lines(
             stream.iter_lines(chunk_size),
             [b'1234567890', b'1234567890', b'12345'],
         )
コード例 #7
0
 def test_streaming_body_is_an_iterator(self):
     body = six.BytesIO(b'a' * 1024 + b'b' * 1024 + b'c' * 2)
     stream = response.StreamingBody(body, content_length=2050)
     self.assertEqual(b'a' * 1024, next(stream))
     self.assertEqual(b'b' * 1024, next(stream))
     self.assertEqual(b'c' * 2, next(stream))
     with self.assertRaises(StopIteration):
         next(stream)
コード例 #8
0
 def test_streaming_body_with_invalid_length(self):
     body = six.BytesIO(b'123456789')
     stream = response.StreamingBody(body, content_length=10)
     with self.assertRaises(IncompleteReadError):
         self.assertEqual(stream.read(9), b'123456789')
         # The next read will have nothing returned and raise
         # an IncompleteReadError because we were expectd 10 bytes, not 9.
         stream.read()
コード例 #9
0
 def test_streaming_line_iter_chunk_sizes(self):
     for chunk_size in range(1, 30):
         body = six.BytesIO(b'1234567890\n1234567890\n12345')
         stream = response.StreamingBody(body, content_length=27)
         self.assert_lines(
             stream.iter_lines(chunk_size),
             [b'1234567890', b'1234567890', b'12345'],
         )
コード例 #10
0
    def test_catches_urllib3_read_timeout(self):
        class TimeoutBody(object):
            def read(*args, **kwargs):
                raise URLLib3ReadTimeoutError(None, None, None)

            def geturl(*args, **kwargs):
                return 'http://example.com'

        stream = response.StreamingBody(TimeoutBody(), content_length=None)
        with self.assertRaises(ReadTimeoutError):
            stream.read()
コード例 #11
0
ファイル: test_response.py プロジェクト: aiven/botocore
    def test_catches_urllib3_protocol_error(self):
        class ProtocolErrorBody:
            def read(*args, **kwargs):
                raise URLLib3ProtocolError(None, None, None)

            def geturl(*args, **kwargs):
                return 'http://example.com'

        stream = response.StreamingBody(ProtocolErrorBody(),
                                        content_length=None)
        with self.assertRaises(ResponseStreamingError):
            stream.read()
コード例 #12
0
 def test_streaming_body_with_zero_read(self):
     body = six.BytesIO(b'1234567890')
     stream = response.StreamingBody(body, content_length=10)
     chunk = stream.read(0)
     self.assertEqual(chunk, b'')
     self.assertEqual(stream.read(), b'1234567890')
コード例 #13
0
 def test_iter_chunks_single_byte(self):
     body = six.BytesIO(b'abcde')
     stream = response.StreamingBody(body, content_length=5)
     chunks = list(stream.iter_chunks(chunk_size=1))
     self.assertEqual(chunks, [b'a', b'b', b'c', b'd', b'e'])
コード例 #14
0
 def test_default_iter_behavior(self):
     body = six.BytesIO(b'a' * 2048)
     stream = response.StreamingBody(body, content_length=2048)
     chunks = list(stream)
     self.assertEqual(len(chunks), 2)
     self.assertEqual(chunks, [b'a' * 1024, b'a' * 1024])
コード例 #15
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_iter_chunks_single_chunk(self):
     body = BytesIO(b'abcde')
     stream = response.StreamingBody(body, content_length=5)
     chunks = list(stream.iter_chunks(chunk_size=1024))
     self.assertEqual(chunks, [b'abcde'])
コード例 #16
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_body_tell(self):
     body = BytesIO(b'1234567890')
     stream = response.StreamingBody(body, content_length=10)
     self.assertEqual(stream.tell(), 0)
     stream.read(5)
     self.assertEqual(stream.tell(), 5)
コード例 #17
0
 def test_streaming_body_closes(self):
     body = six.BytesIO(b'1234567890')
     stream = response.StreamingBody(body, content_length=10)
     self.assertFalse(body.closed)
     stream.close()
     self.assertTrue(body.closed)
コード例 #18
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_line_empty_body(self):
     stream = response.StreamingBody(
         BytesIO(b''),
         content_length=0,
     )
     self.assert_lines(stream.iter_lines(), [])
コード例 #19
0
 def test_streaming_wrapper_validates_content_length(self):
     body = six.BytesIO(b'1234567890')
     stream = response.StreamingBody(body, content_length=10)
     self.assertEqual(stream.read(), b'1234567890')
コード例 #20
0
 def test_iter_chunks_with_leftover(self):
     body = six.BytesIO(b'abcde')
     stream = response.StreamingBody(body, content_length=5)
     chunks = list(stream.iter_chunks(chunk_size=2))
     self.assertEqual(chunks, [b'ab', b'cd', b'e'])
コード例 #21
0
 def test_streaming_body_with_single_read(self):
     body = six.BytesIO(b'123456789')
     stream = response.StreamingBody(body, content_length=10)
     with self.assertRaises(IncompleteReadError):
         stream.read()
コード例 #22
0
ファイル: test_response.py プロジェクト: aiven/botocore
 def test_streaming_body_readlines(self):
     body = BytesIO(b'1234567890\n1234567890\n12345')
     stream = response.StreamingBody(body, content_length=27)
     chunks = [b'1234567890\n', b'1234567890\n', b'12345']
     self.assertEqual(stream.readlines(), chunks)