diff options
author | Michael Williamson <mike@zwobble.org> | 2013-09-29 17:36:32 +0100 |
---|---|---|
committer | Michael Williamson <mike@zwobble.org> | 2014-09-07 18:27:19 +0100 |
commit | 3b7c8ee3bd87905d8ae6964aea3e2c1181672289 (patch) | |
tree | adacfc3cfec6d53835677429347be1f1066053c4 /tests/test_transport.py | |
parent | 64d54e942c8839acdb615bb9cbe402d7c9bd0709 (diff) |
Convert Channel into a context manager
Diffstat (limited to 'tests/test_transport.py')
-rw-r--r-- | tests/test_transport.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_transport.py b/tests/test_transport.py index 485a18e8..ae0f5e01 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -20,6 +20,8 @@ Some unit tests for the ssh2 protocol in Transport. """ +from __future__ import with_statement + from binascii import hexlify import select import socket @@ -278,6 +280,22 @@ class TransportTest(ParamikoTest): self.assertEqual('Hello there.\n', f.readline()) self.assertEqual('This is on stderr.\n', f.readline()) self.assertEqual('', f.readline()) + + def test_6a_channel_can_be_used_as_context_manager(self): + """ + verify that exec_command() does something reasonable. + """ + self.setup_test_server() + + with self.tc.open_session() as chan: + with self.ts.accept(1.0) as schan: + chan.exec_command('yes') + schan.send('Hello there.\n') + schan.close() + + f = chan.makefile() + self.assertEqual('Hello there.\n', f.readline()) + self.assertEqual('', f.readline()) def test_7_invoke_shell(self): """ |