split_buffer_test.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. from .. import unittest
  4. from compose.cli.utils import split_buffer
  5. class SplitBufferTest(unittest.TestCase):
  6. def test_single_line_chunks(self):
  7. def reader():
  8. yield 'abc\n'
  9. yield 'def\n'
  10. yield 'ghi\n'
  11. self.assert_produces(reader, ['abc\n', 'def\n', 'ghi\n'])
  12. def test_no_end_separator(self):
  13. def reader():
  14. yield 'abc\n'
  15. yield 'def\n'
  16. yield 'ghi'
  17. self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
  18. def test_multiple_line_chunk(self):
  19. def reader():
  20. yield 'abc\ndef\nghi'
  21. self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
  22. def test_chunked_line(self):
  23. def reader():
  24. yield 'a'
  25. yield 'b'
  26. yield 'c'
  27. yield '\n'
  28. yield 'd'
  29. self.assert_produces(reader, ['abc\n', 'd'])
  30. def test_preserves_unicode_sequences_within_lines(self):
  31. string = u"a\u2022c\n"
  32. def reader():
  33. yield string
  34. self.assert_produces(reader, [string])
  35. def assert_produces(self, reader, expectations):
  36. split = split_buffer(reader(), '\n')
  37. for (actual, expected) in zip(split, expectations):
  38. self.assertEqual(type(actual), type(expected))
  39. self.assertEqual(actual, expected)