summaryrefslogtreecommitdiff
path: root/docker/utils
diff options
context:
space:
mode:
authorCorentin Henry <corentinhenry@gmail.com>2018-11-27 17:01:06 -0800
committerCorentin Henry <corentinhenry@gmail.com>2018-11-28 13:37:10 -0800
commit6540900dae21571a60fd92037e926cd6599a52eb (patch)
tree6508711d2174ac9b26c445ca3064257be3d781da /docker/utils
parent5f157bbaca5ae62a5bb71547106beb6ef02bc485 (diff)
downloaddocker-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.py16
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)