def test_connect_to_progress_reports_connects_sig_process_to_the_code_editor_progress(self): w = PythonFileInterpreter() w.editor = mock.MagicMock() this = mock.MagicMock() w.connect_to_progress_reports(this) w.editor.progressMade.connect.assert_called_once()
def append_new_editor(self, font=None, content=None, filename=None): """ Appends a new editor the tabbed widget :param font: A reference to the font to be used by the editor. If None is given then self.default_font is used :param content: An optional string containing content to be placed into the editor on opening. If None then self.default_content is used :param filename: An optional string containing the filename of the editor if applicable. :return: """ if content is None: content = self.default_content if font is None: font = self.default_font interpreter = PythonFileInterpreter(font, content, filename=filename, parent=self) if self.whitespace_visible: interpreter.set_whitespace_visible() # monitor future modifications interpreter.sig_editor_modified.connect(self.mark_current_tab_modified) interpreter.sig_filename_modified.connect(self.on_filename_modified) tab_title, tab_tooltip = _tab_title_and_toolip(filename) tab_idx = self._tabs.addTab(interpreter, tab_title) self._tabs.setTabToolTip(tab_idx, tab_tooltip) self._tabs.setCurrentIndex(tab_idx) return tab_idx
def append_new_editor(self, font=None, content=None, filename=None): """ Appends a new editor the tabbed widget :param font: A reference to the font to be used by the editor. If None is given then self.default_font is used :param content: An optional string containing content to be placed into the editor on opening. If None then self.default_content is used :param filename: An optional string containing the filename of the editor if applicable. :return: """ if content is None: content = self.default_content if font is None: font = self.default_font interpreter = PythonFileInterpreter(font, content, filename=filename, parent=self) if self.whitespace_visible: interpreter.set_whitespace_visible() # monitor future modifications interpreter.sig_editor_modified.connect(self.mark_current_tab_modified) interpreter.sig_filename_modified.connect(self.on_filename_modified) tab_title, tab_tooltip = _tab_title_and_toolip(filename) tab_idx = self._tabs.addTab(interpreter, tab_title) self._tabs.setTabToolTip(tab_idx, tab_tooltip) self._tabs.setCurrentIndex(tab_idx) return tab_idx
def test_disconnect_from_progress_reports_attempts_to_disconnect_sig_process_from_the_code_editor( self): w = PythonFileInterpreter() w.editor = mock.MagicMock() w.disconnect_from_progress_reports() w.editor.progressMade.disconnect.assert_called_once()
def append_new_editor(self, font=None, content=None, filename=None): """ Appends a new editor the tabbed widget :param font: A reference to the font to be used by the editor. If None is given then self.default_font is used :param content: An optional string containing content to be placed into the editor on opening. If None then self.default_content is used :param filename: An optional string containing the filename of the editor if applicable. :return: """ if content is None: content = self.default_content if font is None: font = self.default_font if self.editor_count > 0: # If there are other tabs open the same zoom level # as these is used. current_zoom = self._tabs.widget(0).editor.getZoom() else: # Otherwise the zoom level of the last tab closed is used # Or the default (0) if this is the very first tab current_zoom = self.zoom_level interpreter = PythonFileInterpreter( font, content, filename=filename, parent=self, completion_enabled=self.completion_enabled) interpreter.editor.zoomTo(current_zoom) if self.whitespace_visible: interpreter.set_whitespace_visible() # monitor future modifications interpreter.sig_editor_modified.connect(self.mark_current_tab_modified) interpreter.sig_filename_modified.connect(self.on_filename_modified) interpreter.editor.textZoomedIn.connect(self.zoom_in_all_tabs) interpreter.editor.textZoomedOut.connect(self.zoom_out_all_tabs) tab_title, tab_tooltip = self._tab_title_and_tooltip(filename) tab_idx = self._tabs.addTab(interpreter, tab_title) self._tabs.setTabToolTip(tab_idx, tab_tooltip) self._tabs.setCurrentIndex(tab_idx) # set the cursor to the last line and give the new editor focus interpreter.editor.setFocus() if content is not None: line_count = content.count(linesep) interpreter.editor.setCursorPosition(line_count, 0) return tab_idx
def test_clear_key_binding(self): test_cases = {'Ctrl+A': None, 'Shift+A': ValueError, 'Ctrl+AAA': ValueError, 'Ctrl+Shift+A': ValueError} w = PythonFileInterpreter() for key_combo, expected_result in test_cases.items(): fail_msg = ("Failed on case '{}' with expected result '{}'" "".format(key_combo, expected_result)) if expected_result is ValueError: with self.assertRaises(expected_result, msg=fail_msg): w.clear_key_binding(key_combo) else: self.assertEqual(w.clear_key_binding(key_combo), None, msg=fail_msg)
def test_find_replace_dialog(self): w = PythonFileInterpreter() # dialog not initialised by default, only when used self.assertIsNone(w.find_replace_dialog) w.show_find_replace_dialog() self.assertIsNotNone(w.find_replace_dialog) w.hide_find_replace_dialog() # dialog not deleted on hide - just hidden self.assertIsNotNone(w.find_replace_dialog) self.assertFalse(w.find_replace_dialog.visible)
def append_new_editor(self, content=None, filename=None): if content is None: content = self.default_content interpreter = PythonFileInterpreter(content, filename=filename, parent=self._tabs) if self.whitespace_visible: interpreter.set_whitespace_visible() # monitor future modifications interpreter.sig_editor_modified.connect(self.mark_current_tab_modified) interpreter.sig_filename_modified.connect(self.on_filename_modified) tab_title, tab_tooltip = _tab_title_and_toolip(filename) tab_idx = self._tabs.addTab(interpreter, tab_title) self._tabs.setTabToolTip(tab_idx, tab_tooltip) self._tabs.setCurrentIndex(tab_idx) return tab_idx
def test_find_replace_dialog(self): w = PythonFileInterpreter() # dialog not initialised by default, only when used self.assertIsNone(w.find_replace_dialog) w.show_find_replace_dialog() self.assertIsNotNone(w.find_replace_dialog) w.hide_find_replace_dialog() # dialog not deleted on hide - just hidden self.assertIsNotNone(w.find_replace_dialog) self.assertFalse(w.find_replace_dialog.visible)
def test_variables_reset(self, mock_on_error): w = PythonFileInterpreter(content='x=\'this is a string\'\r\nprint(x)') w.sig_editor_modified = mock.MagicMock() w._presenter.model.sig_exec_success = mock.MagicMock() w.execute_async_blocking() self.assertTrue('x' in w._presenter.model._globals_ns.keys()) w._presenter.is_executing = False w._presenter.view.editor.hasSelectedText = mock.MagicMock() w._presenter.view.editor.hasSelectedText.return_value = True w._presenter.view.editor.selectedText = mock.MagicMock() w._presenter.view.editor.selectedText.return_value = 'print(x)' w._presenter.view.editor.getSelection = mock.MagicMock() w._presenter.view.editor.getSelection.return_value = [0, 0, 0, 0] w.execute_async_blocking() self.assertTrue('x' in w._presenter.model._globals_ns.keys()) w._presenter.view.editor.text = mock.MagicMock() w._presenter.view.editor.text.return_value = 'print(x)' w._presenter.is_executing = False w._presenter.view.editor.hasSelectedText.return_value = False w.execute_async_blocking() self.assertFalse('x' in w._presenter.model._globals_ns.keys()) mock_on_error.assert_called_once()
def test_variables_reset(self): w = PythonFileInterpreter(content='x=\'this is a string\'\r\nprint(x)') w.execute_async() self.assertTrue('x' in w._presenter.model._globals_ns.keys()) w._presenter.is_executing = False w._presenter.view.editor.hasSelectedText = mock.MagicMock() w._presenter.view.editor.hasSelectedText.return_value = True w._presenter.view.editor.selectedText = mock.MagicMock() w._presenter.view.editor.selectedText.return_value = 'print(x)' w._presenter.view.editor.getSelection = mock.MagicMock() w._presenter.view.editor.getSelection.return_value = [0, 0, 0, 0] w.execute_async() self.assertTrue('x' in w._presenter.model._globals_ns.keys()) w._presenter.view.editor.text = mock.MagicMock() w._presenter.view.editor.text.return_value = 'print(x)' w._presenter.is_executing = False w._presenter.view.editor.hasSelectedText.return_value = False w.execute_async() self.assertFalse('x' in w._presenter.model._globals_ns.keys())
def test_successful_execution(self): w = PythonFileInterpreter() w.editor.setText("x = 1 + 2") w.execute_async() self.assertTrue("Status: Idle", w.status.currentMessage())
def test_constructor_respects_filename(self): w = PythonFileInterpreter(filename='test.py') self.assertEqual('test.py', w.filename)
def test_constructor_populates_editor_with_content(self): w = PythonFileInterpreter(content='# my funky code') self.assertEqual('# my funky code', w.editor.text())
def test_empty_code_does_nothing_on_exec(self): w = PythonFileInterpreter() w._presenter.model.execute_async = mock.MagicMock() w.execute_async() w._presenter.model.execute_async.assert_not_called() self.assertTrue("Status: Idle", w.status.currentMessage())
def test_construction(self): w = PythonFileInterpreter() self.assertTrue("Status: Idle", w.status.currentMessage())