test_microfs.py 文件源码

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

项目:microfs 作者: ntoll 项目源码 文件源码
def test_get_no_target():
    """
    Ensure a successful get results in the expected file getting written on
    the local file system with the expected content. In this case, since no
    target is provided, use the name of the remote file.
    """
    with mock.patch('microfs.execute', return_value=(b'hello', b'')) as exe:
        mo = mock.mock_open()
        with mock.patch('microfs.open', mo, create=True):
            assert microfs.get('hello.txt')
            commands = [
                "from microbit import uart",
                "f = open('{}', 'rb')".format('hello.txt'),
                "r = f.read",
                "result = True",
                "while result:\n    result = r(32)\n    if result:\n        "
                "uart.write(result)\n",
                "f.close()",
            ]
            exe.assert_called_once_with(commands, None)
            mo.assert_called_once_with('hello.txt', 'wb')
            handle = mo()
            handle.write.assert_called_once_with(b'hello')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号