2014-01-22 18:44:04 +01:00
|
|
|
from __future__ import absolute_import
|
2015-08-24 21:25:25 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-04-25 23:58:21 +02:00
|
|
|
from .. import unittest
|
2015-10-03 01:47:27 +02:00
|
|
|
from compose.utils import split_buffer
|
2014-01-22 18:44:04 +01:00
|
|
|
|
2015-03-26 04:13:01 +01:00
|
|
|
|
2014-01-22 18:44:04 +01:00
|
|
|
class SplitBufferTest(unittest.TestCase):
|
|
|
|
def test_single_line_chunks(self):
|
|
|
|
def reader():
|
2015-08-25 23:17:12 +02:00
|
|
|
yield b'abc\n'
|
|
|
|
yield b'def\n'
|
|
|
|
yield b'ghi\n'
|
2014-01-22 18:44:04 +01:00
|
|
|
|
2014-08-19 23:36:46 +02:00
|
|
|
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi\n'])
|
2014-01-22 18:44:04 +01:00
|
|
|
|
|
|
|
def test_no_end_separator(self):
|
|
|
|
def reader():
|
2015-08-25 23:17:12 +02:00
|
|
|
yield b'abc\n'
|
|
|
|
yield b'def\n'
|
|
|
|
yield b'ghi'
|
2014-01-22 18:44:04 +01:00
|
|
|
|
2014-08-19 23:36:46 +02:00
|
|
|
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
|
2014-01-22 18:44:04 +01:00
|
|
|
|
|
|
|
def test_multiple_line_chunk(self):
|
|
|
|
def reader():
|
2015-08-25 23:17:12 +02:00
|
|
|
yield b'abc\ndef\nghi'
|
2014-01-22 18:44:04 +01:00
|
|
|
|
2014-08-19 23:36:46 +02:00
|
|
|
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
|
2014-01-22 18:44:04 +01:00
|
|
|
|
|
|
|
def test_chunked_line(self):
|
|
|
|
def reader():
|
2015-08-25 23:17:12 +02:00
|
|
|
yield b'a'
|
|
|
|
yield b'b'
|
|
|
|
yield b'c'
|
|
|
|
yield b'\n'
|
|
|
|
yield b'd'
|
2014-01-22 18:44:04 +01:00
|
|
|
|
2014-08-19 23:36:46 +02:00
|
|
|
self.assert_produces(reader, ['abc\n', 'd'])
|
2014-05-29 13:11:08 +02:00
|
|
|
|
|
|
|
def test_preserves_unicode_sequences_within_lines(self):
|
2014-08-19 23:36:46 +02:00
|
|
|
string = u"a\u2022c\n"
|
2014-05-29 13:11:08 +02:00
|
|
|
|
|
|
|
def reader():
|
2015-08-25 23:17:12 +02:00
|
|
|
yield string.encode('utf-8')
|
2014-05-29 13:11:08 +02:00
|
|
|
|
|
|
|
self.assert_produces(reader, [string])
|
|
|
|
|
|
|
|
def assert_produces(self, reader, expectations):
|
2015-10-05 18:56:10 +02:00
|
|
|
split = split_buffer(reader())
|
2014-05-29 13:11:08 +02:00
|
|
|
|
|
|
|
for (actual, expected) in zip(split, expectations):
|
2018-01-04 22:01:54 +01:00
|
|
|
assert type(actual) == type(expected)
|
|
|
|
assert actual == expected
|