Fix split buffer with inconsistently delimited json objects.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
3661e8bc74
commit
15d0c60a73
6 changed files with 62 additions and 22 deletions
|
|
@ -9,8 +9,6 @@ from compose.config.config import ServiceLoader
|
|||
from compose.const import LABEL_PROJECT
|
||||
from compose.progress_stream import stream_output
|
||||
from compose.service import Service
|
||||
from compose.utils import split_buffer
|
||||
from compose.utils import stream_as_text
|
||||
|
||||
|
||||
def pull_busybox(client):
|
||||
|
|
@ -73,5 +71,5 @@ class DockerClientTestCase(unittest.TestCase):
|
|||
|
||||
def check_build(self, *args, **kwargs):
|
||||
kwargs.setdefault('rm', True)
|
||||
build_output = stream_as_text(self.client.build(*args, **kwargs))
|
||||
stream_output(split_buffer(build_output), open('/dev/null', 'w'))
|
||||
build_output = self.client.build(*args, **kwargs)
|
||||
stream_output(build_output, open('/dev/null', 'w'))
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class SplitBufferTest(unittest.TestCase):
|
|||
self.assert_produces(reader, [string])
|
||||
|
||||
def assert_produces(self, reader, expectations):
|
||||
split = split_buffer(reader(), u'\n')
|
||||
split = split_buffer(reader())
|
||||
|
||||
for (actual, expected) in zip(split, expectations):
|
||||
self.assertEqual(type(actual), type(expected))
|
||||
|
|
|
|||
16
tests/unit/utils_test.py
Normal file
16
tests/unit/utils_test.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from .. import unittest
|
||||
from compose import utils
|
||||
|
||||
|
||||
class JsonSplitterTestCase(unittest.TestCase):
|
||||
|
||||
def test_json_splitter_no_object(self):
|
||||
data = '{"foo": "bar'
|
||||
self.assertEqual(utils.json_splitter(data), (None, None))
|
||||
|
||||
def test_json_splitter_with_object(self):
|
||||
data = '{"foo": "bar"}\n \n{"next": "obj"}'
|
||||
self.assertEqual(
|
||||
utils.json_splitter(data),
|
||||
({'foo': 'bar'}, '{"next": "obj"}')
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue