def test_remove_fs_no_fs(): """ Removing a non-existent file system raises a RuntimeError. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.fs = None with pytest.raises(RuntimeError): mm.remove_fs()
def test_toggle_files_off(): """ If the fs is on, toggle if off. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.remove_fs = mock.MagicMock() mm.repl = None mm.fs = True mm.toggle_files(None) assert mm.remove_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_remove_fs(): """ Removing the file system results in the expected state. """ view = mock.MagicMock() view.remove_repl = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.fs = True mm.remove_fs() assert view.remove_filesystem.call_count == 1 assert mm.fs is None
def test_toggle_files_with_plotter(): """ If the plotter is active, ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.plotter = True mm.fs = None mm.toggle_files(None) assert view.show_message.call_count == 1
def test_toggle_repl_with_fs(): """ If the file system is active, show a helpful message instead. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.remove_repl = mock.MagicMock() mm.repl = None mm.fs = True mm.toggle_repl(None) assert view.show_message.call_count == 1
def test_toggle_repl_with_fs(): """ If the file system is active, show a helpful message instead. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.remove_repl = mock.MagicMock() mm.repl = None mm.fs = True mm.toggle_repl(None) assert view.show_message.call_count == 1
def test_toggle_files_with_repl(): """ If the REPL is active, ensure a helpful message is displayed. """ view = mock.MagicMock() view.show_message = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.add_repl = mock.MagicMock() mm.repl = True mm.fs = None mm.toggle_files(None) assert view.show_message.call_count == 1
def test_deactivate(): """ Ensure Filesystem pane is hidden, when MicroPython-mode is deactivated. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.remove_fs = mock.MagicMock() mm.activate() mm.fs = True mm.deactivate() mm.remove_fs.assert_called_once_with()
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)