def test_flash_path_specified_does_not_exist(): """ Ensure that if a micro:bit is not automatically found by uflash and the user has previously specified a path to the device, then the hex is saved in the specified location. """ with mock.patch('mu.contrib.uflash.hexlify', return_value=''), \ mock.patch('mu.contrib.uflash.embed_hex', return_value='foo'), \ mock.patch('mu.contrib.uflash.find_microbit', return_value=None),\ mock.patch('mu.logic.os.path.exists', return_value=False),\ mock.patch('mu.logic.os.makedirs', return_value=None), \ mock.patch('mu.contrib.uflash.save_hex', return_value=None) as s: view = mock.MagicMock() view.current_tab.text = mock.MagicMock(return_value='') view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.user_defined_microbit_path = 'baz' mm.flash() message = 'Could not find an attached BBC micro:bit.' information = ("Please ensure you leave enough time for the BBC" " micro:bit to be attached and configured correctly" " by your computer. This may take several seconds." " Alternatively, try removing and re-attaching the" " device or saving your work and restarting Mu if" " the device remains unfound.") view.show_message.assert_called_once_with(message, information) assert s.call_count == 0 assert mm.user_defined_microbit_path is None
def test_flash_existing_user_specified_device_path(): """ Ensure that if a micro:bit is not automatically found by uflash and the user has previously specified a path to the device, then the hex is saved in the specified location. """ mock_flasher = mock.MagicMock() mock_flasher_class = mock.MagicMock(return_value=mock_flasher) with mock.patch('mu.contrib.uflash.find_microbit', return_value=None),\ mock.patch('mu.logic.os.path.exists', return_value=True),\ mock.patch('mu.modes.microbit.DeviceFlasher', mock_flasher_class), \ mock.patch('mu.modes.microbit.sys.platform', 'win32'): view = mock.MagicMock() view.current_tab.text = mock.MagicMock(return_value='foo') view.get_microbit_path = mock.MagicMock(return_value='bar') view.show_message = mock.MagicMock() editor = mock.MagicMock() editor.minify = False editor.microbit_runtime = '/foo/bar' mm = MicrobitMode(editor, view) mm.user_defined_microbit_path = 'baz' mm.flash() assert view.get_microbit_path.call_count == 0 assert editor.show_status_message.call_count == 1 mock_flasher_class.assert_called_once_with([ 'baz', ], b'foo', '/foo/bar')
def test_flash_path_specified_does_not_exist(): """ Ensure that if a micro:bit is not automatically found by uflash and the user has previously specified a path to the device, then the hex is saved in the specified location. """ with mock.patch('mu.logic.uflash.hexlify', return_value=''), \ mock.patch('mu.logic.uflash.embed_hex', return_value='foo'), \ mock.patch('mu.logic.uflash.find_microbit', return_value=None),\ mock.patch('mu.logic.os.path.exists', return_value=False),\ mock.patch('mu.logic.os.makedirs', return_value=None), \ mock.patch('mu.logic.uflash.save_hex', return_value=None) as s: view = mock.MagicMock() view.current_tab.text = mock.MagicMock(return_value='') view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.user_defined_microbit_path = 'baz' mm.flash() message = 'Could not find an attached BBC micro:bit.' information = ("Please ensure you leave enough time for the BBC" " micro:bit to be attached and configured correctly" " by your computer. This may take several seconds." " Alternatively, try removing and re-attaching the" " device or saving your work and restarting Mu if" " the device remains unfound.") view.show_message.assert_called_once_with(message, information) assert s.call_count == 0 assert mm.user_defined_microbit_path is None
def test_flash_existing_user_specified_device_path(): """ Ensure that if a micro:bit is not automatically found by uflash and the user has previously specified a path to the device, then the hex is saved in the specified location. """ with mock.patch('mu.logic.uflash.hexlify', return_value=''), \ mock.patch('mu.logic.uflash.embed_hex', return_value='foo'), \ mock.patch('mu.logic.uflash.find_microbit', return_value=None),\ mock.patch('mu.logic.os.path.exists', return_value=True),\ mock.patch('mu.logic.uflash.save_hex', return_value=None) as s: view = mock.MagicMock() view.get_microbit_path = mock.MagicMock(return_value='bar') view.current_tab.text = mock.MagicMock(return_value='') view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.user_defined_microbit_path = 'baz' mm.flash() assert view.get_microbit_path.call_count == 0 assert editor.show_status_message.call_count == 1 hex_file_path = os.path.join('baz', 'micropython.hex') s.assert_called_once_with('foo', hex_file_path)
def test_flash_existing_user_specified_device_path(): """ Ensure that if a micro:bit is not automatically found by uflash and the user has previously specified a path to the device, then the hex is saved in the specified location. """ mock_flasher = mock.MagicMock() mock_flasher_class = mock.MagicMock(return_value=mock_flasher) with mock.patch('mu.logic.uflash.find_microbit', return_value=None),\ mock.patch('mu.logic.os.path.exists', return_value=True),\ mock.patch('mu.modes.microbit.DeviceFlasher', mock_flasher_class), \ mock.patch('mu.modes.microbit.sys.platform', 'win32'): view = mock.MagicMock() view.current_tab.text = mock.MagicMock(return_value='foo') view.get_microbit_path = mock.MagicMock(return_value='bar') view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.user_defined_microbit_path = 'baz' mm.flash() assert view.get_microbit_path.call_count == 0 assert editor.show_status_message.call_count == 1 mock_flasher_class.assert_called_once_with(['baz', ], b'foo', None)