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-08-24 21:25:25 +02:00
|
|
|
from compose.cli.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():
|
2014-08-19 23:36:46 +02:00
|
|
|
yield 'abc\n'
|
|
|
|
yield 'def\n'
|
|
|
|
yield '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():
|
2014-08-19 23:36:46 +02:00
|
|
|
yield 'abc\n'
|
|
|
|
yield 'def\n'
|
|
|
|
yield '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():
|
2014-08-19 23:36:46 +02:00
|
|
|
yield '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():
|
2014-08-19 23:36:46 +02:00
|
|
|
yield 'a'
|
|
|
|
yield 'b'
|
|
|
|
yield 'c'
|
|
|
|
yield '\n'
|
|
|
|
yield '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():
|
|
|
|
yield string
|
|
|
|
|
|
|
|
self.assert_produces(reader, [string])
|
|
|
|
|
|
|
|
def assert_produces(self, reader, expectations):
|
2014-08-19 23:36:46 +02:00
|
|
|
split = split_buffer(reader(), '\n')
|
2014-05-29 13:11:08 +02:00
|
|
|
|
|
|
|
for (actual, expected) in zip(split, expectations):
|
|
|
|
self.assertEqual(type(actual), type(expected))
|
|
|
|
self.assertEqual(actual, expected)
|