From 67fe85dc8d8079192b04684a01e449c7823194c8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 18 May 2016 11:38:25 -0600 Subject: [PATCH] Add missing unit test for Remote._sftp_open_file Signed-off-by: Zack Cerza --- teuthology/orchestra/test/test_remote.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/teuthology/orchestra/test/test_remote.py b/teuthology/orchestra/test/test_remote.py index 714f8b100b..612a0ca400 100644 --- a/teuthology/orchestra/test/test_remote.py +++ b/teuthology/orchestra/test/test_remote.py @@ -147,3 +147,19 @@ class TestRemote(object): ssh_pub_key='host_key', up=True, ) + + def test_sftp_open_file(self): + m_file_obj = MagicMock() + m_stat = Mock() + m_stat.st_size = 42 + m_file_obj.stat.return_value = m_stat + m_open = MagicMock() + m_open.return_value = m_file_obj + m_open.return_value.__enter__.return_value = m_file_obj + with patch.object(remote.Remote, '_sftp_open_file', new=m_open): + rem = remote.Remote(name='jdoe@xyzzy.example.com', ssh=self.m_ssh) + assert rem._sftp_open_file('x') is m_file_obj + assert rem._sftp_open_file('x').stat() is m_stat + assert rem._sftp_open_file('x').stat().st_size == 42 + with rem._sftp_open_file('x') as f: + assert f == m_file_obj -- 2.39.5