summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-09-29 17:25:58 +0100
committerMichael Williamson <mike@zwobble.org>2014-09-07 18:21:10 +0100
commit64d54e942c8839acdb615bb9cbe402d7c9bd0709 (patch)
treef0d55a147369cef742c98e136ed528b09b0438b3 /tests
parent979838040f9ff2f52e369812be87f0c7c9c1a0db (diff)
Convert SFTPClient to a context manager
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_sftp.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 1ae9781d..e3f7e59b 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -195,6 +195,18 @@ class SFTPTest (unittest.TestCase):
pass
sftp = paramiko.SFTP.from_transport(tc)
+ def test_2_sftp_can_be_used_as_context_manager(self):
+ """
+ verify that the sftp session is closed when exiting the context manager
+ """
+ global sftp
+ with sftp:
+ pass
+ try:
+ self._assert_opening_file_raises_error(sftp)
+ finally:
+ sftp = paramiko.SFTP.from_transport(tc)
+
def test_3_write(self):
"""
verify that a file can be created and written, and the size is correct.
@@ -796,6 +808,15 @@ class SFTPTest (unittest.TestCase):
sftp.remove('%s/nonutf8data' % FOLDER)
+ def _assert_opening_file_raises_error(self, sftp):
+ try:
+ sftp.open(FOLDER + '/test2', 'w')
+ self.fail('expected exception')
+ # TODO: extract failing command (the open) to share with a passing assertion
+ except EOFError as error:
+ pass
+
+
if __name__ == '__main__':
SFTPTest.init_loopback()
# logging is required by test_N_file_with_percent