def test_splittable_codedit_tab_widget(): tw = SplittableCodeEditTabWidget() tw.show() nd = tw.create_new_document() QTest.keyPress(nd, 'a') w_file = tw.open_document(__file__) QTest.qWait(1000) other = tw.open_document(server.__file__) assert tw.current_widget() == other assert other != w_file assert tw.open_document(__file__) == w_file QTest.qWait(1000) assert tw.count() == 3 tw.rename_document(__file__, __file__ + '.old') QTest.qWait(1000) tw.close_document(__file__ + '.old') QTest.qWait(1000) assert tw.count() == 2 tw.close_document(server.__file__) QTest.qWait(1000) assert tw.count() == 1 tw.close_all() QTest.qWait(1000) assert tw.count() == 0 tw.close() del tw
def reject_mbox(): print('reject') widgets = QtWidgets.QApplication.instance().topLevelWidgets() for w in widgets: print(w) if isinstance(w, QtWidgets.QDialog): QTest.keyPress(w, QtCore.Qt.Key_Escape)
def test_key_pressed(editor): editor.free_format = False editor.comment_indicator = '*> ' editor.setPlainText('123456DISPLAY "Hello".', '', '') QTest.keyPress(editor, QtCore.Qt.Key_Slash, QtCore.Qt.ControlModifier) assert editor.toPlainText() == '123456*> DISPLAY "Hello".' QTest.keyPress(editor, QtCore.Qt.Key_Slash, QtCore.Qt.ControlModifier) assert editor.toPlainText() == '123456DISPLAY "Hello".'
def test_calltips(editor): editor.clear() mode = get_mode(editor) assert editor.backend.connected assert mode is not None editor.setPlainText("open(__file_") TextHelper(editor).goto_line(1, len('open(__file_')) QTest.keyPress(editor, ',') QTest.keyRelease(editor, ',') QTest.qWait(1000)
def run(self, editor): editor.setPlainText(self.context.input_code, '', '') TextHelper(editor).goto_line(self.context.input_line, self.context.input_column) wait = 1 QTest.qWait(wait) QTest.keyPress(editor, QtCore.Qt.Key_Return) QTest.qWait(wait) assert editor.toPlainText() == self.context.expected_code assert TextHelper(editor).current_line_nbr() == self.context.expected_line assert TextHelper(editor).current_column_nbr() == self.context.expected_column
def test_calltips_with_closing_paren(editor): editor.clear() mode = get_mode(editor) assert editor.backend.connected assert mode is not None editor.setPlainText("open") TextHelper(editor).goto_line(1, len('open')) QTest.keyPress(editor, '(') QTest.keyRelease(editor, '(') QTest.qWait(1000) mode._display_tooltip(None, 0)
def test_event_filter(editor): panel = get_panel(editor) panel.on_actionActionSearchAndReplace_triggered() panel.request_search('import') QTest.qWait(5000) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Tab) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Return) QTest.keyPress(panel.lineEditReplace, QtCore.Qt.Key_Return) QTest.keyPress(panel.lineEditReplace, QtCore.Qt.Key_Return, QtCore.Qt.ControlModifier) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Escape) assert not panel.isVisible()
def run(self, editor): editor.setPlainText(self.context.input_code) TextHelper(editor).goto_line(self.context.input_line, self.context.input_column) wait = 1 QTest.qWait(wait) QTest.keyPress(editor, QtCore.Qt.Key_Return) QTest.qWait(wait) assert editor.toPlainText() == self.context.expected_code assert TextHelper( editor).current_line_nbr() == self.context.expected_line assert TextHelper( editor).current_column_nbr() == self.context.expected_column
def test_event_filter(editor): panel = get_panel(editor) panel.on_search_and_replace() panel.request_search('import') QTest.qWait(1000) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Tab) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Return) QTest.keyPress(panel.lineEditReplace, QtCore.Qt.Key_Return) QTest.keyPress(panel.lineEditReplace, QtCore.Qt.Key_Return, QtCore.Qt.ControlModifier) QTest.keyPress(panel.lineEditSearch, QtCore.Qt.Key_Escape) editor.show() QTest.qWait(1000) assert not panel.isVisible()
def test_autocomplete_double_quotes(editor): code = '''{ "widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": "height": 500 }, } } ''' editor.setPlainText(code) assert editor.toPlainText() == code TextHelper(editor).goto_line(6, column=16, move=True) QTest.qWait(100) assert TextHelper(editor).current_line_text() == ' "width":' QTest.keyPress(editor, '"') result = ' "width":""' assert TextHelper(editor).current_line_text() == result QTest.qWait(100) TextHelper(editor).goto_line(6, column=len(result), move=True) QTest.keyPress(editor, ',') QTest.keyPress(editor, QtCore.Qt.Key_Return) QTest.qWait(100) QTest.keyPress(editor, '"') QTest.qWait(100) result = ' "":' assert TextHelper(editor).current_line_text() == result
def test_key_pressed(): # " -> "" editor = CodeEdit() editor.modes.append(modes.AutoCompleteMode()) editor.setPlainText('', '', 'utf-8') QTest.keyPress(editor, '"') assert editor.toPlainText() == '""' editor.clear() # if a " already exists, cursor should just move after " and a new " should # not be inserted editor.setPlainText('"', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, '"') assert editor.toPlainText() == '"' editor.clear() # if a ) already exists, cursor should just move after ) and a new ) should # not be inserted editor.setPlainText(')', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, ')') QTest.qWait(1000) assert editor.toPlainText() == ')' # ] should be inserted ")" -> "])" TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, ']') QTest.qWait(1000) assert editor.toPlainText() == '])'
def test_forbidden_characters(editor): code = '''{ "widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": "height": 500 }, } } ''' editor.setPlainText(code) assert editor.toPlainText() == code TextHelper(editor).goto_line(6, column=16, move=True) QTest.qWait(100) assert TextHelper(editor).current_line_text() == ' "width":' QTest.keyPress(editor, '\'') assert TextHelper(editor).current_line_text() == ' "width":\''
def test_key_events(editor): zoom = editor.zoom_level QTest.keyPress(editor, '+', QtCore.Qt.ControlModifier) assert editor.zoom_level > zoom QTest.keyPress(editor, '0', QtCore.Qt.ControlModifier) assert editor.zoom_level == zoom == 0 QTest.keyPress(editor, '-', QtCore.Qt.ControlModifier) assert editor.zoom_level < zoom if os.environ['QT_API'].lower() == 'pyqt5': editor.wheelEvent( QtGui.QWheelEvent(QtCore.QPoint(10, 10), editor.mapToGlobal(QtCore.QPoint(10, 10)), QtCore.QPoint(0, 1), QtCore.QPoint(0, 1), 1, QtCore.Qt.Vertical, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) else: editor.wheelEvent( QtGui.QWheelEvent(QtCore.QPoint(10, 10), 1, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) if os.environ['QT_API'].lower() == 'pyqt5': editor.wheelEvent( QtGui.QWheelEvent(QtCore.QPoint(10, 10), editor.mapToGlobal(QtCore.QPoint(10, 10)), QtCore.QPoint(0, -1), QtCore.QPoint(0, -1), -1, QtCore.Qt.Vertical, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) else: editor.wheelEvent( QtGui.QWheelEvent(QtCore.QPoint(10, 10), -1, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier))
def test_key_events(editor): zoom = editor.zoom_level QTest.keyPress(editor, '+', QtCore.Qt.ControlModifier) assert editor.zoom_level > zoom QTest.keyPress(editor, '0', QtCore.Qt.ControlModifier) assert editor.zoom_level == zoom == 0 QTest.keyPress(editor, '-', QtCore.Qt.ControlModifier) assert editor.zoom_level < zoom if os.environ['QT_API'].lower() == 'pyqt5': editor.wheelEvent(QtGui.QWheelEvent( QtCore.QPoint(10, 10), editor.mapToGlobal(QtCore.QPoint(10, 10)), QtCore.QPoint(0, 1), QtCore.QPoint(0, 1), 1, QtCore.Qt.Vertical, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) else: editor.wheelEvent(QtGui.QWheelEvent( QtCore.QPoint(10, 10), 1, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) if os.environ['QT_API'].lower() == 'pyqt5': editor.wheelEvent(QtGui.QWheelEvent( QtCore.QPoint(10, 10), editor.mapToGlobal(QtCore.QPoint(10, 10)), QtCore.QPoint(0, -1), QtCore.QPoint(0, -1), -1, QtCore.Qt.Vertical, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier)) else: editor.wheelEvent(QtGui.QWheelEvent( QtCore.QPoint(10, 10), -1, QtCore.Qt.MidButton, QtCore.Qt.ControlModifier))
def perform_actions(self, editor): for action in self.actions: if action.startswith('goto_line('): p = re.compile(r'\b\d+\b') matches = list(p.finditer(action)) assert len(matches) == 2 line = int(matches[0].group()) column = int(matches[1].group()) TextHelper(editor).goto_line(line - 1, column) elif action.startswith('press('): p = re.compile(r'\b\d+\b') matches = list(p.finditer(action)) assert len(matches) == 1 key = int(matches[0].group()) QTest.keyPress(editor, key) elif action.startswith('assert_nb_children('): p = re.compile(r'\b\d+\b') matches = list(p.finditer(action)) assert len(matches) == 1 nb = int(matches[0].group()) scope = self._get_scope(editor) assert len(list(scope.child_regions())) == nb elif action == 'fold': scope = self._get_scope(editor) scope.fold() assert scope.collapsed elif action == 'unfold': scope = self._get_scope(editor) scope.unfold() assert not scope.collapsed elif action == 'assert_parent': scope = self._get_scope(editor) assert scope.parent() is not None elif action == 'assert_no_parent': scope = self._get_scope(editor) assert scope.parent() is None elif action == 'assert_not_scope_start': scope = self._get_scope(editor) assert scope is None
def accept_dlg(): global flg_multi flg_multi = True widgets = QtWidgets.QApplication.instance().topLevelWidgets() for w in widgets: if isinstance(w, QtWidgets.QDialog): QTest.keyPress(w, QtCore.Qt.Key_Tab) QTest.keyPress(w, QtCore.Qt.Key_Tab) QTest.keyPress(w, QtCore.Qt.Key_Return)
def accept_mbox(): print('accept') widgets = QtWidgets.QApplication.instance().topLevelWidgets() for w in widgets: print(w) if isinstance(w, QtWidgets.QDialog): QTest.keyPress(w, QtCore.Qt.Key_Return) QTest.keyPress(w, QtCore.Qt.Key_Enter) QTest.keyPress(w, QtCore.Qt.Key_Space)
def test_key_pressed(editor): QTest.keyPress(editor, '"') editor.clear() editor.setPlainText('"', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, '"') editor.clear() editor.setPlainText(')', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, ')')
def test_key_pressed(editor): QTest.qWait(1000) TextHelper(editor).goto_line(21, 4) # QTest.qWait(2000) assert editor.textCursor().positionInBlock() == 4 QTest.keyPress(editor, QtCore.Qt.Key_Backspace)
def test_disabled(editor): editor.setPlainText(' DISPLAY "Hello".', '', '') mode = editor.modes.get('CommentsMode') mode.enabled = False QTest.keyPress(editor, QtCore.Qt.Key_Slash, QtCore.Qt.ControlModifier) assert ' DISPLAY "Hello".' in editor.toPlainText()
def test_quoting_selection(editor): editor.setPlainText('foo', '', 'utf-8') TextHelper(editor).goto_line(0, 0) editor.selectAll() QTest.keyPress(editor, '(') assert editor.toPlainText() == '(foo)'
def test_autocomple_method_parens(editor): editor.clear() editor.setPlainText('class\n def foo') TextHelper(editor).goto_line(1, len(' def foo')) QTest.keyPress(editor, '(') assert editor.toPlainText() == 'class\n def foo(self):'
def test_key_pressed(editor): editor.setPlainText(' DISPLAY "Hello".', '', '') QTest.keyPress(editor, QtCore.Qt.Key_Slash, QtCore.Qt.ControlModifier) assert editor.toPlainText() == ' *> DISPLAY "Hello".' QTest.keyPress(editor, QtCore.Qt.Key_Slash, QtCore.Qt.ControlModifier) assert editor.toPlainText() == ' DISPLAY "Hello".'
def test_key_pressed_event(editor): QTest.keyPress(editor, QtCore.Qt.Key_Tab) QTest.keyPress(editor, QtCore.Qt.Key_Backtab) QTest.keyPress(editor, QtCore.Qt.Key_Home) QTest.keyPress(editor, QtCore.Qt.Key_Return)
def test_insert_completions(editor): assert editor.backend.running TextHelper(editor).goto_line(3) # check insert completions QTest.keyPress(editor, "m") QTest.keyPress(editor, "o") QTest.qWait(500) QTest.keyPress(editor, QtCore.Qt.Key_Return) # feature request #126: Key_Tab should select a completion QTest.keyPress(editor, QtCore.Qt.Key_Return) QTest.keyPress(editor, "Q") QTest.keyPress(editor, "T") QTest.keyPress(editor, "e") QTest.keyPress(editor, "s") QTest.qWait(500) QTest.keyPress(editor, "t") QTest.qWait(100)
def test_events(editor): assert editor.backend.running QTest.qWait(1000) TextHelper(editor).goto_line(3) QTest.keyPress(editor, QtCore.Qt.Key_Space, QtCore.Qt.ControlModifier) QTest.qWait(2000) QTest.keyPress(editor, QtCore.Qt.Key_Escape) QTest.qWait(500) QTest.keyPress(editor, "m") QTest.keyPress(editor, "o") QTest.qWait(1000) QTest.keyPress(editor, QtCore.Qt.Key_Escape) QTest.keyPress(editor, " ") QTest.keyPress(editor, "m") QTest.keyPress(editor, "o") QTest.keyPress(editor, "d") QTest.qWait(10) QTest.keyPress(editor, " ") QTest.qWait(500) QTest.keyPress(editor, "e") QTest.keyPress(editor, "n") QTest.keyPress(editor, "a") QTest.keyPress(editor, "b") QTest.keyPress(editor, "l") QTest.keyPress(editor, "e") QTest.keyPress(editor, "d") QTest.qWait(500) QTest.keyPress(editor, " ") QTest.keyPress(editor, "Q") QTest.keyPress(editor, "t") QTest.keyPress(editor, ".") QTest.qWait(500) QTest.keyPress(editor, "Q") QTest.keyPress(editor, "t") QTest.qWait(500) QTest.keyPress(editor, QtCore.Qt.Key_Space, QtCore.Qt.ControlModifier)
def test_insert_completions(editor): assert editor.backend.running TextHelper(editor).goto_line(3) # check insert completions QTest.keyPress(editor, 'm') QTest.keyPress(editor, 'o') QTest.qWait(500) QTest.keyPress(editor, QtCore.Qt.Key_Return) # feature request #126: Key_Tab should select a completion QTest.keyPress(editor, QtCore.Qt.Key_Return) QTest.keyPress(editor, 'Q') QTest.keyPress(editor, 'T') QTest.keyPress(editor, 'e') QTest.keyPress(editor, 's') QTest.qWait(500) QTest.keyPress(editor, 't') QTest.qWait(100)
def test_events(editor): assert editor.backend.running QTest.qWait(1000) TextHelper(editor).goto_line(3) QTest.keyPress(editor, QtCore.Qt.Key_Space, QtCore.Qt.ControlModifier) QTest.qWait(2000) QTest.keyPress(editor, QtCore.Qt.Key_Escape) QTest.qWait(500) QTest.keyPress(editor, 'm') QTest.keyPress(editor, 'o') QTest.qWait(1000) QTest.keyPress(editor, QtCore.Qt.Key_Escape) QTest.keyPress(editor, ' ') QTest.keyPress(editor, 'm') QTest.keyPress(editor, 'o') QTest.keyPress(editor, 'd') QTest.qWait(10) QTest.keyPress(editor, ' ') QTest.qWait(500) QTest.keyPress(editor, 'e') QTest.keyPress(editor, 'n') QTest.keyPress(editor, 'a') QTest.keyPress(editor, 'b') QTest.keyPress(editor, 'l') QTest.keyPress(editor, 'e') QTest.keyPress(editor, 'd') QTest.qWait(500) QTest.keyPress(editor, ' ') QTest.keyPress(editor, 'Q') QTest.keyPress(editor, 't') QTest.keyPress(editor, '.') QTest.qWait(500) QTest.keyPress(editor, 'Q') QTest.keyPress(editor, 't') QTest.qWait(500) QTest.keyPress(editor, QtCore.Qt.Key_Space, QtCore.Qt.ControlModifier)
def test_indent_eat_whitespaces(editor): editor.setPlainText('app = get_app(45, 4)', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 17) QTest.keyPress(editor, QtCore.Qt.Key_Return)
def test_indent_after_opening_symbol(editor): editor.file.open('test/files/example.json') TextHelper(editor).goto_line(1, 15) assert TextHelper(editor).current_line_text() == ' "widget": {' QTest.keyPress(editor, QtCore.Qt.Key_Return) assert TextHelper(editor).current_line_text() == ' '
def test_basic(editor): QTest.keyPress(editor, '(') editor.clear() QTest.keyPress(editor, '(')
def test_autocomple_func_parens(editor): editor.clear() editor.setPlainText('def foo') TextHelper(editor).goto_line(0, len('def foo')) QTest.keyPress(editor, '(') assert editor.toPlainText() == 'def foo():'
def reject_mbox(): widgets = QtWidgets.QApplication.instance().topLevelWidgets() for w in widgets: if isinstance(w, QtWidgets.QMessageBox): QTest.keyPress(w, QtCore.Qt.Key_Escape)