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')
评论列表
文章目录