From: Zack Cerza Date: Wed, 18 May 2016 17:38:25 +0000 (-0600) Subject: Add missing unit test for Remote._sftp_open_file X-Git-Tag: 1.1.0~612^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=67fe85dc8d8079192b04684a01e449c7823194c8;p=teuthology.git Add missing unit test for Remote._sftp_open_file Signed-off-by: Zack Cerza --- 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