def test_write(self):
"""Tests write_content."""
# name is a special attribute in mock.Mock. Therefore, it needs a special
# way of mocking.
tmp_file = mock.Mock()
type(tmp_file).name = mock.PropertyMock(return_value='/tmp/file')
tmp = mock.Mock()
tmp.__enter__ = mock.Mock(return_value=tmp_file)
tmp.__exit__ = mock.Mock(return_value=False)
self.mock.NamedTemporaryFile.return_value = tmp
android.write_content('/test.html', 'content')
self.mock.NamedTemporaryFile.assert_called_once_with(delete=False)
self.mock.adb.assert_called_once_with('push /tmp/file /test.html')
self.mock.adb_shell.assert_called_once_with('chmod 0644 /test.html')
self.mock.delete_if_exists.assert_called_once_with('/tmp/file')
tmp_file.write.assert_called_once_with('content')
评论列表
文章目录