def test_add_fs_no_device(): """ If there's no device attached then ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() editor.current_device = None mm = MicrobitMode(editor, view) mm.add_fs() assert view.show_message.call_count == 1
def test_add_fs_with_repl(): """ If the REPL is active, you can't add the file system pane. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.repl = True with mock.patch('mu.modes.microbit.microfs.get_serial', return_value=True): mm.add_fs() assert view.add_filesystem.call_count == 0
def test_add_fs_with_repl(): """ If the REPL is active, you can't add the file system pane. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.repl = True with mock.patch('mu.modes.microbit.microfs.get_serial', return_value=True): mm.add_fs() assert view.add_filesystem.call_count == 0
def test_add_fs_no_device(): """ If there's no device attached then ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.microfs.find_microbit', return_value=False): mm.add_fs() assert view.show_message.call_count == 1
def test_add_fs_no_device(): """ If there's no device attached then ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() ex = IOError('BOOM') editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.microfs.get_serial', side_effect=ex): mm.add_fs() assert view.show_message.call_count == 1
def test_add_fs_no_device(): """ If there's no device attached then ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() ex = IOError('BOOM') editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.microfs.get_serial', side_effect=ex): mm.add_fs() assert view.show_message.call_count == 1
def test_add_fs_no_repl(): """ It's possible to add the file system pane if the REPL is inactive. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.microfs.get_serial', return_value=True): mm.add_fs() workspace = mm.workspace_dir() view.add_filesystem.assert_called_once_with(home=workspace) assert mm.fs
def test_add_fs(): """ It's possible to add the file system pane if the REPL is inactive. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.FileManager') as mock_fm,\ mock.patch('mu.modes.microbit.QThread'),\ mock.patch('mu.modes.microbit.microfs.find_microbit', return_value=True): mm.add_fs() workspace = mm.workspace_dir() view.add_filesystem.assert_called_once_with(workspace, mock_fm()) assert mm.fs
def test_add_fs(microbit): """ It's possible to add the file system pane if the REPL is inactive. """ view = mock.MagicMock() editor = mock.MagicMock() editor.current_device = microbit mm = MicrobitMode(editor, view) with mock.patch("mu.modes.microbit.FileManager") as mock_fm, mock.patch( "mu.modes.microbit.QThread"): mm.add_fs() workspace = mm.workspace_dir() view.add_filesystem.assert_called_once_with(workspace, mock_fm(), "micro:bit") assert mm.fs
def test_add_fs_no_repl(): """ It's possible to add the file system pane if the REPL is inactive. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) with mock.patch('mu.modes.microbit.FileManager') as mock_fm,\ mock.patch('mu.modes.microbit.QThread'),\ mock.patch('mu.modes.microbit.microfs.get_serial', return_value=True): mm.add_fs() workspace = mm.workspace_dir() view.add_filesystem.assert_called_once_with(workspace, mock_fm()) assert mm.fs
def test_toggle_files_on(): """ If the fs is off, toggle it on. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.add_fs = mock.MagicMock() mm.repl = None mm.fs = None mm.toggle_files(None) assert mm.add_fs.call_count == 1
def test_toggle_files_on(): """ If the fs is off, toggle it on. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.add_fs = mock.MagicMock() mm.repl = None mm.fs = None mm.toggle_files(None) assert mm.add_fs.call_count == 1
def test_device_changed(microbit): """ Ensure Filesystem pane is reconnected, when the user changes device. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.add_fs = mock.MagicMock() mm.remove_fs = mock.MagicMock() mm.activate() mm.fs = True mm.device_changed(microbit) mm.remove_fs.assert_called_once_with() mm.add_fs.assert_called_once_with()
def test_toggle_files_on(): """ If the fs is off, toggle it on. """ view = mock.MagicMock() view.button_bar.slots = { 'repl': mock.MagicMock(), 'plotter': mock.MagicMock(), } editor = mock.MagicMock() mm = MicrobitMode(editor, view) def side_effect(*args, **kwargs): mm.fs = True mm.add_fs = mock.MagicMock(side_effect=side_effect) mm.repl = None mm.fs = None mm.toggle_files(None) assert mm.add_fs.call_count == 1 view.button_bar.slots['repl'].setEnabled.assert_called_once_with(False) view.button_bar.slots['plotter'].setEnabled.assert_called_once_with(False)
def test_toggle_files_on(): """ If the fs is off, toggle it on. """ view = mock.MagicMock() view.button_bar.slots = { 'repl': mock.MagicMock(), 'plotter': mock.MagicMock(), } editor = mock.MagicMock() mm = MicrobitMode(editor, view) def side_effect(*args, **kwargs): mm.fs = True mm.add_fs = mock.MagicMock(side_effect=side_effect) mm.repl = None mm.fs = None mm.toggle_files(None) assert mm.add_fs.call_count == 1 view.button_bar.slots['repl'].setEnabled.assert_called_once_with(False) view.button_bar.slots['plotter'].setEnabled.assert_called_once_with(False)