diff options
author | Corentin Henry <corentinhenry@gmail.com> | 2018-11-27 17:01:06 -0800 |
---|---|---|
committer | Corentin Henry <corentinhenry@gmail.com> | 2018-11-28 13:37:10 -0800 |
commit | 6540900dae21571a60fd92037e926cd6599a52eb (patch) | |
tree | 6508711d2174ac9b26c445ca3064257be3d781da /docker/utils | |
parent | 5f157bbaca5ae62a5bb71547106beb6ef02bc485 (diff) | |
download | docker-py-6540900dae21571a60fd92037e926cd6599a52eb.tar.gz |
add tests for _read_from_socket
Check that the return value against the various combination of
parameters this function can take (tty, stream, and demux).
This commit also fixes a bug that the tests uncovered a bug in
consume_socket_output.
Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
Diffstat (limited to 'docker/utils')
-rw-r--r-- | docker/utils/socket.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/docker/utils/socket.py b/docker/utils/socket.py index fe4a332..4b32853 100644 --- a/docker/utils/socket.py +++ b/docker/utils/socket.py @@ -136,15 +136,17 @@ def consume_socket_output(frames, demux=False): # we just need to concatenate. return six.binary_type().join(frames) - # If the streams are demultiplexed, the generator returns tuples - # (stdin, stdout, stderr) + # If the streams are demultiplexed, the generator yields tuples + # (stdout, stderr) out = [six.binary_type(), six.binary_type()] for frame in frames: - for stream_id in [STDOUT, STDERR]: - # It is guaranteed that for each frame, one and only one stream - # is not None. - if frame[stream_id] is not None: - out[stream_id] += frame[stream_id] + # It is guaranteed that for each frame, one and only one stream + # is not None. + assert frame != (None, None) + if frame[0] is not None: + out[0] += frame[0] + else: + out[1] += frame[1] return tuple(out) |