android_test.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:clusterfuzz-tools 作者: google 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号