summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2019-06-14 20:45:09 -0400
committerJeff Forcier <jeff@bitprophet.org>2019-06-14 20:45:09 -0400
commit04505d5ead61d0aea866c36a89d3fbfb786b3206 (patch)
tree4d32a528daefe8f3583ad6ca046d1e48db3ded5f /tests
parent02175b034d91ef5fc4e86ab7379cdc2aacd7f3c4 (diff)
Implement #322 - new ChannelFile subclass for stdin that calls shutdown_write on close()
Diffstat (limited to 'tests')
-rw-r--r--tests/test_channelfile.py30
-rw-r--r--tests/test_client.py2
2 files changed, 25 insertions, 7 deletions
diff --git a/tests/test_channelfile.py b/tests/test_channelfile.py
index 6faf8bf8..707a49c0 100644
--- a/tests/test_channelfile.py
+++ b/tests/test_channelfile.py
@@ -1,32 +1,36 @@
from mock import patch, MagicMock
-from paramiko import Channel, ChannelFile, ChannelStderrFile
+from paramiko import Channel, ChannelFile, ChannelStderrFile, ChannelStdinFile
-class TestChannelFile(object):
+class ChannelFileBase(object):
@patch("paramiko.channel.ChannelFile._set_mode")
def test_defaults_to_unbuffered_reading(self, setmode):
- cf = ChannelFile(Channel(None))
+ cf = self.klass(Channel(None))
setmode.assert_called_once_with("r", -1)
@patch("paramiko.channel.ChannelFile._set_mode")
def test_can_override_mode_and_bufsize(self, setmode):
- cf = ChannelFile(Channel(None), mode="w", bufsize=25)
+ cf = self.klass(Channel(None), mode="w", bufsize=25)
setmode.assert_called_once_with("w", 25)
def test_read_recvs_from_channel(self):
chan = MagicMock()
- cf = ChannelFile(chan)
+ cf = self.klass(chan)
cf.read(100)
chan.recv.assert_called_once_with(100)
def test_write_calls_channel_sendall(self):
chan = MagicMock()
- cf = ChannelFile(chan, mode="w")
+ cf = self.klass(chan, mode="w")
cf.write("ohai")
chan.sendall.assert_called_once_with(b"ohai")
+class TestChannelFile(ChannelFileBase):
+ klass = ChannelFile
+
+
class TestChannelStderrFile(object):
def test_read_calls_channel_recv_stderr(self):
chan = MagicMock()
@@ -40,3 +44,17 @@ class TestChannelStderrFile(object):
cf.write("ohai")
chan.sendall_stderr.assert_called_once_with(b"ohai")
+
+class TestChannelStdinFile(ChannelFileBase):
+ klass = ChannelStdinFile
+
+ def test_close_calls_channel_shutdown_write(self):
+ chan = MagicMock()
+ cf = ChannelStdinFile(chan, mode="wb")
+ cf.flush = MagicMock()
+ cf.close()
+ # Sanity check that we still call BufferedFile.close()
+ cf.flush.assert_called_once_with()
+ assert cf._closed is True
+ # Actual point of test
+ chan.shutdown_write.assert_called_once_with()
diff --git a/tests/test_client.py b/tests/test_client.py
index 26de2d37..c46c383b 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -213,7 +213,7 @@ class ClientTest(unittest.TestCase):
# Nobody else tests the API of exec_command so let's do it here for
# now. :weary:
- assert isinstance(stdin, paramiko.ChannelFile)
+ assert isinstance(stdin, paramiko.ChannelStdinFile)
assert isinstance(stdout, paramiko.ChannelFile)
assert isinstance(stderr, paramiko.ChannelStderrFile)