mirror of
				https://github.com/docker/compose.git
				synced 2025-10-31 19:24:21 +01:00 
			
		
		
		
	Closes: #6890 Some remarks, - `# coding ... utf-8` statements are not needed - isdigit on strings instead of a try-catch. - Default opening mode is read, so we can do `open()` without the `'r'` everywhere - Removed inheritinng from `object` class, it isn't necessary in python3. - `super(ClassName, self)` can now be replaced with `super()` - Use of itertools and `chain` on a couple places dealing with sets. - Used the operator module instead of lambdas when warranted `itemgetter(0)` instead of `lambda x: x[0]` `attrgetter('name')` instead of `lambda x: x.name` - `sorted` returns a list, so no need to use `list(sorted(...))` - Removed `dict()` using dictionary comprehensions whenever possible - Attempted to remove python3.2 support Signed-off-by: alexrecuenco <alejandrogonzalezrecuenco@gmail.com>
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from .. import unittest
 | |
| from compose.utils import split_buffer
 | |
| 
 | |
| 
 | |
| class SplitBufferTest(unittest.TestCase):
 | |
|     def test_single_line_chunks(self):
 | |
|         def reader():
 | |
|             yield b'abc\n'
 | |
|             yield b'def\n'
 | |
|             yield b'ghi\n'
 | |
| 
 | |
|         self.assert_produces(reader, ['abc\n', 'def\n', 'ghi\n'])
 | |
| 
 | |
|     def test_no_end_separator(self):
 | |
|         def reader():
 | |
|             yield b'abc\n'
 | |
|             yield b'def\n'
 | |
|             yield b'ghi'
 | |
| 
 | |
|         self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
 | |
| 
 | |
|     def test_multiple_line_chunk(self):
 | |
|         def reader():
 | |
|             yield b'abc\ndef\nghi'
 | |
| 
 | |
|         self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
 | |
| 
 | |
|     def test_chunked_line(self):
 | |
|         def reader():
 | |
|             yield b'a'
 | |
|             yield b'b'
 | |
|             yield b'c'
 | |
|             yield b'\n'
 | |
|             yield b'd'
 | |
| 
 | |
|         self.assert_produces(reader, ['abc\n', 'd'])
 | |
| 
 | |
|     def test_preserves_unicode_sequences_within_lines(self):
 | |
|         string = "a\u2022c\n"
 | |
| 
 | |
|         def reader():
 | |
|             yield string.encode('utf-8')
 | |
| 
 | |
|         self.assert_produces(reader, [string])
 | |
| 
 | |
|     def assert_produces(self, reader, expectations):
 | |
|         split = split_buffer(reader())
 | |
| 
 | |
|         for (actual, expected) in zip(split, expectations):
 | |
|             assert type(actual) == type(expected)
 | |
|             assert actual == expected
 |