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