test_microfs.py 文件源码

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

项目:microfs 作者: ntoll 项目源码 文件源码
def test_get():
    """
    Ensure a successful get results in the expected file getting written on
    the local file system with the expected content.
    """
    mock_serial = mock.MagicMock()
    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', 'local.txt', mock_serial)
            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, mock_serial)
            mo.assert_called_once_with('local.txt', 'wb')
            handle = mo()
            handle.write.assert_called_once_with(b'hello')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号