summaryrefslogtreecommitdiffhomepage
path: root/tests/test_channelfile.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2019-06-14 17:36:10 -0400
committerJeff Forcier <jeff@bitprophet.org>2019-06-14 17:36:10 -0400
commite7e3dae2d40957bebd9c77c9389ea224f00d1a44 (patch)
treeee4a0c713cd2ea7dff962e3146bd295e04e52009 /tests/test_channelfile.py
parent8e88adb02c2bf373b039c319d0099828826799cd (diff)
parentc9eb8862f333910d8b89612e94a32d365319d449 (diff)
Merge branch '2.4' into 2.5
Diffstat (limited to 'tests/test_channelfile.py')
-rw-r--r--tests/test_channelfile.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_channelfile.py b/tests/test_channelfile.py
new file mode 100644
index 00000000..f8cfe473
--- /dev/null
+++ b/tests/test_channelfile.py
@@ -0,0 +1,42 @@
+from mock import patch, MagicMock
+
+from paramiko import Channel, ChannelFile
+
+
+class TestChannelFile(object):
+ @patch("paramiko.channel.ChannelFile._set_mode")
+ def test_defaults_to_unbuffered_reading(self, setmode):
+ cf = ChannelFile(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)
+ setmode.assert_called_once_with("w", 25)
+
+ def test_read_recvs_from_channel(self):
+ chan = MagicMock()
+ cf = ChannelFile(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.write("ohai")
+ chan.sendall.assert_called_once_with(b"ohai")
+
+
+def TestChannelStderrFile(object):
+ def test_read_calls_channel_recv_stderr(self):
+ chan = MagicMock()
+ cf = ChannelStderrFile(chan)
+ cf.read(100)
+ chan.recv_stderr.assert_called_once_with(100)
+
+ def test_write_calls_channel_sendall(self):
+ chan = MagicMock()
+ cf = ChannelStderrFile(chan, mode="w")
+ cf.write("ohai")
+ chan.sendall_stderr.assert_called_once_with(b"ohai")
+