From c160002bc33b04d14f36da6d6320653247636ee3 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sat, 4 Jan 2025 14:16:50 +0300 Subject: [PATCH] Wrap lines that are longer than 106 characters --- .github/workflows/main.yml | 2 +- ReText/converterprocess.py | 5 +- ReText/dialogs.py | 4 +- ReText/editor.py | 26 ++++++-- ReText/tab.py | 35 ++++++++--- ReText/tablemode.py | 22 +++++-- ReText/window.py | 34 +++++++--- tests/test_editor.py | 73 ++++++++++++++++++---- tests/test_tablemode.py | 23 +++++-- tests/test_window.py | 125 +++++++++++++++++++++++++++---------- 10 files changed, 272 insertions(+), 77 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 970b564a..558d0985 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -83,4 +83,4 @@ jobs: - name: Install ruff run: python -m pip install ruff - name: Run ruff check - run: ruff check --select F,E,W,I,UP --ignore E501 . + run: ruff check --select F,E,W,I,UP --line-length=106 . diff --git a/ReText/converterprocess.py b/ReText/converterprocess.py index 8faa0b13..c91ec340 100644 --- a/ReText/converterprocess.py +++ b/ReText/converterprocess.py @@ -32,7 +32,10 @@ def recvall(sock, remaining): while remaining > 0: data = sock.recv(remaining) if len(data) == 0: - raise EOFError('Received 0 bytes from socket while more bytes were expected. Did the sender process exit unexpectedly?') + raise EOFError( + 'Received 0 bytes from socket while more bytes were expected.' + ' Did the sender process exit unexpectedly?' + ) alldata.extend(data) remaining -= len(data) diff --git a/ReText/dialogs.py b/ReText/dialogs.py index b73192e1..c1d6fbaa 100644 --- a/ReText/dialogs.py +++ b/ReText/dialogs.py @@ -58,7 +58,9 @@ def __init__(self, parent, defaultText=None): self.checkBox = QCheckBox(self.tr('Set as default'), self) verticalLayout.addWidget(self.checkBox) buttonBox = QDialogButtonBox(self) - buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) + buttonBox.setStandardButtons( + QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok + ) verticalLayout.addWidget(buttonBox) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) diff --git a/ReText/editor.py b/ReText/editor.py index e95c6a5b..531847e8 100644 --- a/ReText/editor.py +++ b/ReText/editor.py @@ -260,7 +260,10 @@ def contextMenuEvent(self, event): curchar = self.document().characterAt(cursor.position()) isalpha = curchar.isalpha() word = None - if isalpha and not (oldcursor.hasSelection() and oldcursor.selectedText() != cursor.selectedText()): + if isalpha and not ( + oldcursor.hasSelection() + and oldcursor.selectedText() != cursor.selectedText() + ): cursor.select(QTextCursor.SelectionType.WordUnderCursor) word = cursor.selectedText() @@ -276,7 +279,10 @@ def contextMenuEvent(self, event): for action in actions[::-1]: menu.insertAction(menu.actions()[0], action) menu.insertSeparator(menu.actions()[0]) - menu.insertAction(menu.actions()[0], self.parent.act(self.tr('Add to dictionary'), trig=self.learnWord(word))) + menu.insertAction( + menu.actions()[0], + self.parent.act(self.tr('Add to dictionary'), trig=self.learnWord(word)), + ) menu.addSeparator() menu.addAction(self.parent.actionMoveUp) @@ -384,7 +390,11 @@ def handleReturn(self, cursor): if matchOL is not None: matchedPrefix = matchOL.group(1) matchedNumber = int(matchOL.group(2)) - nextNumber = matchedNumber if self.settings.orderedListMode == 'repeat' else matchedNumber + 1 + nextNumber = ( + matchedNumber + if self.settings.orderedListMode == 'repeat' + else matchedNumber + 1 + ) matchedText = matchedPrefix + str(nextNumber) + ". " else: matchedText = '' @@ -455,7 +465,10 @@ def highlightCurrentLine(self): if globalSettings.highlightCurrentLine == 'wrapped-line': selections.append(QTextEdit.ExtraSelection()) selections[0].cursor.movePosition(QTextCursor.MoveOperation.StartOfBlock) - selections[0].cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.KeepAnchor) + selections[0].cursor.movePosition( + QTextCursor.MoveOperation.EndOfBlock, + QTextCursor.MoveMode.KeepAnchor, + ) selections[1].format.setBackground(getColor('currentLineHighlight')) selections[1].format.setProperty(QTextFormat.Property.FullWidthSelection, True) selections[1].cursor = self.textCursor() @@ -463,7 +476,10 @@ def highlightCurrentLine(self): elif selection.cursor.block().textDirection() == Qt.LayoutDirection.RightToLeft: # FullWidthSelection does not work correctly for RTL direction selection.cursor.movePosition(QTextCursor.MoveOperation.StartOfLine) - selection.cursor.movePosition(QTextCursor.MoveOperation.EndOfLine, QTextCursor.MoveMode.KeepAnchor) + selection.cursor.movePosition( + QTextCursor.MoveOperation.EndOfLine, + QTextCursor.MoveMode.KeepAnchor, + ) self.setExtraSelections(selections) def enableTableMode(self, enable): diff --git a/ReText/tab.py b/ReText/tab.py index 72dd9cf5..559ff131 100644 --- a/ReText/tab.py +++ b/ReText/tab.py @@ -416,8 +416,16 @@ def find(self, text, flags, replaceText=None, wrap=False): if not newCursor.isNull(): if replaceText is not None: newCursor.insertText(replaceText) - newCursor.movePosition(QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.MoveAnchor, len(replaceText)) - newCursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, len(replaceText)) + newCursor.movePosition( + QTextCursor.MoveOperation.Left, + QTextCursor.MoveMode.MoveAnchor, + len(replaceText), + ) + newCursor.movePosition( + QTextCursor.MoveOperation.Right, + QTextCursor.MoveMode.KeepAnchor, + len(replaceText), + ) self.editBox.setTextCursor(newCursor) if self.editBox.cursorRect().bottom() >= self.editBox.height() - 3: scrollValue = self.editBox.verticalScrollBar().value() @@ -439,8 +447,16 @@ def replaceAll(self, text, replaceText): lastCursor = cursor cursor = self.editBox.document().find(text, cursor, flags) if not lastCursor.isNull(): - lastCursor.movePosition(QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.MoveAnchor, len(replaceText)) - lastCursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, len(replaceText)) + lastCursor.movePosition( + QTextCursor.MoveOperation.Left, + QTextCursor.MoveMode.MoveAnchor, + len(replaceText), + ) + lastCursor.movePosition( + QTextCursor.MoveOperation.Right, + QTextCursor.MoveMode.KeepAnchor, + len(replaceText), + ) self.editBox.setTextCursor(lastCursor) self.editBox.textCursor().endEditBlock() return not lastCursor.isNull() @@ -468,10 +484,13 @@ def promptFileCreation(self, fileToCreate): Prompt user if a file should be created for the clicked link, and try to create it. Return True on success. """ - buttonReply = QMessageBox.question(self, self.tr('Create missing file?'), - self.tr("The file '%s' does not exist.\n\nDo you want to create it?") % fileToCreate, - QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, - QMessageBox.StandardButton.No) + buttonReply = QMessageBox.question( + self, + self.tr('Create missing file?'), + self.tr("The file '%s' does not exist.\n\nDo you want to create it?") % fileToCreate, + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, + QMessageBox.StandardButton.No, + ) if buttonReply == QMessageBox.StandardButton.Yes: return self.createFile(fileToCreate) elif buttonReply == QMessageBox.StandardButton.No: diff --git a/ReText/tablemode.py b/ReText/tablemode.py index fae03530..82bb160a 100644 --- a/ReText/tablemode.py +++ b/ReText/tablemode.py @@ -180,19 +180,33 @@ def _determineEditLists(rows, editedlineindex, offset, editsize, alignWithAnyEdg if editsize < 0: # How much an edge shifts to the left depends on how much room # there is in the cells on any row that shares this edge. - leastLeftShift = min((-rowShift + _determineRoomInCell(row, currentedge, currentedgeindex, True) - for row, rowShift in zip(rows, rowShifts))) + leastLeftShift = min( + -rowShift + _determineRoomInCell(row, currentedge, currentedgeindex, True) + for row, rowShift in zip(rows, rowShifts) + ) shift = max(editsize, -leastLeftShift) else: # When shifting right, determine how much only once based on how # much the edited cell needs to expand if firstEdge: - room = _determineRoomInCell(rows[editedlineindex], currentedge, currentedgeindex, False, offset) + room = _determineRoomInCell( + rows[editedlineindex], + currentedge, + currentedgeindex, + False, + offset, + ) shift = max(0, editsize - room) for i, row in enumerate(rows): - editList, newRowShift = _performShift(row, rowShifts[i], currentedge, currentedgeindex, shift) + editList, newRowShift = _performShift( + row, + rowShifts[i], + currentedge, + currentedgeindex, + shift, + ) rowShifts[i] = newRowShift editLists[i].extend(editList) diff --git a/ReText/window.py b/ReText/window.py index 888da842..20b25bb9 100644 --- a/ReText/window.py +++ b/ReText/window.py @@ -237,7 +237,11 @@ def __init__(self, parent=None): self.actionPdf = self.act('PDF', 'application-pdf', self.savePdf) self.actionOdf = self.act('ODT', 'x-office-document', self.saveOdf) self.getExportExtensionsList() - self.actionQuit = self.act(self.tr('Quit'), 'application-exit', shct=QKeySequence.StandardKey.Quit) + self.actionQuit = self.act( + self.tr('Quit'), + 'application-exit', + shct=QKeySequence.StandardKey.Quit, + ) self.actionQuit.setMenuRole(QAction.MenuRole.QuitRole) self.actionQuit.triggered.connect(self.close) self.actionUndo = self.act(self.tr('Undo'), 'edit-undo', @@ -250,8 +254,12 @@ def __init__(self, parent=None): lambda: self.currentTab.editBox.cut(), shct=QKeySequence.StandardKey.Cut) self.actionPaste = self.act(self.tr('Paste'), 'edit-paste', lambda: self.currentTab.editBox.paste(), shct=QKeySequence.StandardKey.Paste) - self.actionPasteImage = self.act(self.tr('Paste image'), 'edit-paste', - lambda: self.currentTab.editBox.pasteImage(), shct=Qt.Modifier.CTRL | Qt.Modifier.SHIFT | Qt.Key.Key_V) + self.actionPasteImage = self.act( + self.tr('Paste image'), + 'edit-paste', + lambda: self.currentTab.editBox.pasteImage(), + shct=Qt.Modifier.CTRL | Qt.Modifier.SHIFT | Qt.Key.Key_V, + ) self.actionMoveUp = self.act(self.tr('Move line up'), 'go-up', lambda: self.currentTab.editBox.moveLineUp(), shct=Qt.Modifier.ALT | Qt.Key.Key_Up) self.actionMoveDown = self.act(self.tr('Move line down'), 'go-down', @@ -615,7 +623,9 @@ def createTab(self, fileName): previewState = PreviewDisabled # Opening empty document in preview mode makes no sense self.currentTab = ReTextTab(self, fileName, previewState) self.currentTab.fileNameChanged.connect(lambda: self.tabFileNameChanged(self.currentTab)) - self.currentTab.modificationStateChanged.connect(lambda: self.tabModificationStateChanged(self.currentTab)) + self.currentTab.modificationStateChanged.connect( + lambda: self.tabModificationStateChanged(self.currentTab) + ) self.currentTab.activeMarkupChanged.connect(lambda: self.tabActiveMarkupChanged(self.currentTab)) self.tabWidget.addTab(self.currentTab, self.tr("New document")) self.currentTab.updateBoxesVisibility() @@ -1096,7 +1106,12 @@ def savePdf(self): if pageSize is None: pageSize = QPageSize(QPageSize.PageSizeId.A4) margins = QMarginsF(20, 20, 13, 20) # left, top, right, bottom (in millimeters) - layout = QPageLayout(pageSize, QPageLayout.Orientation.Portrait, margins, QPageLayout.Unit.Millimeter) + layout = QPageLayout( + pageSize, + QPageLayout.Orientation.Portrait, + margins, + QPageLayout.Unit.Millimeter, + ) preview.page().printToPdf(fileName, layout) return printer = self.standardPrinter(title) @@ -1267,9 +1282,14 @@ def maybeSave(self, ind): if not tab.editBox.document().isModified(): return True self.tabWidget.setCurrentIndex(ind) - ret = QMessageBox.warning(self, '', + ret = QMessageBox.warning( + self, + '', self.tr("The document has been modified.\nDo you want to save your changes?"), - QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel) + QMessageBox.StandardButton.Save + | QMessageBox.StandardButton.Discard + | QMessageBox.StandardButton.Cancel, + ) if ret == QMessageBox.StandardButton.Save: return self.saveFile(False) elif ret == QMessageBox.StandardButton.Cancel: diff --git a/tests/test_editor.py b/tests/test_editor.py index ff291ebf..0de67efd 100644 --- a/tests/test_editor.py +++ b/tests/test_editor.py @@ -161,7 +161,12 @@ def getText(self, key): return '\'' def getEvent(self, key): - return QKeyEvent(QEvent.Type.KeyPress, key, Qt.KeyboardModifier.NoModifier, text=self.getText(key)) + return QKeyEvent( + QEvent.Type.KeyPress, + key, + Qt.KeyboardModifier.NoModifier, + text=self.getText(key), + ) def test_isSurroundKey(self): # close keys should not start a surrounding @@ -176,12 +181,30 @@ def test_isSurroundKey(self): self.assertTrue(self.editor.isSurroundKey(Qt.Key.Key_Apostrophe)) def test_getCloseKey(self): - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore), '_') - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk), '*') - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl), '"') - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe), '\'') - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft), ')') - self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft), ']') + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore), + '_', + ) + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk), + '*', + ) + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl), + '"', + ) + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe), + '\'', + ) + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft), + ')', + ) + self.assertEqual( + self.editor.getCloseKey(self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft), + ']', + ) def changeCursor(self, posI, posF): self.cursor.setPosition(posI) @@ -190,27 +213,51 @@ def changeCursor(self, posI, posF): def test_surroundText(self): self.changeCursor(0, 3) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_Underscore), + Qt.Key.Key_Underscore, + ) self.assertEqual(self.document.toPlainText(), '_foo_ bar baz qux corge grault') self.changeCursor(6, 9) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_Asterisk), + Qt.Key.Key_Asterisk, + ) self.assertEqual(self.document.toPlainText(), '_foo_ *bar* baz qux corge grault') self.changeCursor(12, 15) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_QuoteDbl), + Qt.Key.Key_QuoteDbl, + ) self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" qux corge grault') self.changeCursor(18, 21) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_Apostrophe), + Qt.Key.Key_Apostrophe, + ) self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' corge grault') self.changeCursor(24, 29) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_ParenLeft), + Qt.Key.Key_ParenLeft, + ) self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' (corge) grault') self.changeCursor(32, 38) - self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft) + self.editor.surroundText( + self.cursor, + self.getEvent(Qt.Key.Key_BracketLeft), + Qt.Key.Key_BracketLeft, + ) self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' (corge) [grault]') class TestOrderedListMode(unittest.TestCase): diff --git a/tests/test_tablemode.py b/tests/test_tablemode.py index db4d0db3..e5e0150f 100644 --- a/tests/test_tablemode.py +++ b/tests/test_tablemode.py @@ -72,8 +72,13 @@ def __init__(self, text, separatorLine, paddingChar): else: editoffset = contentsChangeOffset - editLists = tablemode._determineEditLists(rows, edit[0], contentsChangeOffset, editsize, alignWithAnyEdge) - + editLists = tablemode._determineEditLists( + rows, + edit[0], + contentsChangeOffset, + editsize, + alignWithAnyEdge, + ) editedRows = [] @@ -83,11 +88,21 @@ def __init__(self, text, separatorLine, paddingChar): editedText = row.text for editEntry in editList: - editedText = self.performEdit(editedText, editEntry[0], editEntry[1], paddingchar=row.paddingchar) + editedText = self.performEdit( + editedText, + editEntry[0], + editEntry[1], + paddingchar=row.paddingchar, + ) editedRows.append(editedText) - editedRows[editedline] = self.performEdit(editedRows[editedline], editoffset, editsize, fragment=editstripped) + editedRows[editedline] = self.performEdit( + editedRows[editedline], + editoffset, + editsize, + fragment=editstripped, + ) if editedRows != after: if alignWithAnyEdge: diff --git a/tests/test_window.py b/tests/test_window.py index 700981fa..58b3e75e 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -59,11 +59,17 @@ class TestWindow(unittest.TestCase): def setUp(self): warnings.simplefilter("ignore", Warning) self.readListFromSettingsMock = patch('ReText.readListFromSettings', return_value=[]).start() - self.writeListToSettingsMock = patch('ReText.writeListToSettings').start() - self.globalSettingsMock = patch('ReText.window.globalSettings', MagicMock(**ReText.configOptions)).start() - self.globalCacheMock = patch('ReText.window.globalCache', MagicMock(**ReText.cacheOptions)).start() + self.writeListToSettingsMock = patch('ReText.writeListToSettings').start() + self.globalSettingsMock = patch( + 'ReText.window.globalSettings', + MagicMock(**ReText.configOptions), + ).start() + self.globalCacheMock = patch( + 'ReText.window.globalCache', + MagicMock(**ReText.cacheOptions), + ).start() self.fileSystemWatcherPatcher = patch('ReText.window.QFileSystemWatcher') - self.fileSystemWatcherMock = self.fileSystemWatcherPatcher.start() + self.fileSystemWatcherMock = self.fileSystemWatcherPatcher.start() ReText.tab.globalSettings = self.globalSettingsMock def tearDown(self): @@ -102,28 +108,36 @@ def get_ui_enabled_states(window): def check_widget_state(self, window, expected_enabled, expected_disabled): actually_enabled, actually_disabled = self.get_ui_enabled_states(window) - self.assertEqual(expected_enabled - actually_enabled, set(), 'These widgets are unexpectedly disabled') - self.assertEqual(expected_disabled - actually_disabled, set(), 'These widgets are unexpectedly enabled') + self.assertEqual( + expected_enabled - actually_enabled, + set(), + 'These widgets are unexpectedly disabled', + ) + self.assertEqual( + expected_disabled - actually_disabled, + set(), + 'These widgets are unexpectedly enabled', + ) def check_widgets_enabled_for_markdown(self, window): - self.check_widget_state(window, - {'actionBold', 'actionItalic', 'actionUnderline', 'formattingBox', 'symbolBox'}, - set()) + self.check_widget_state( + window, + {'actionBold', 'actionItalic', 'actionUnderline', 'formattingBox', 'symbolBox'}, + set(), + ) def check_widgets_enabled_for_restructuredtext(self, window): - self.check_widget_state(window, - {'actionBold', 'actionItalic'}, - {'actionUnderline', 'formattingBox', 'symbolBox'}) + self.check_widget_state( + window, + {'actionBold', 'actionItalic'}, + {'actionUnderline', 'formattingBox', 'symbolBox'}, + ) def check_widgets_enabled(self, window, widgets): - self.check_widget_state(window, - set(widgets), - set()) + self.check_widget_state(window, set(widgets), set()) def check_widgets_disabled(self, window, widgets): - self.check_widget_state(window, - set(), - set(widgets)) + self.check_widget_state(window, set(), set(widgets)) # @@ -139,7 +153,10 @@ def test_windowTitleAndTabs_afterStartWithEmptyTab(self): self.assertEqual('New document[*]', self.window.windowTitle()) self.assertFalse(self.window.currentTab.fileName) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_windowTitleAndTabs_afterLoadingFile(self, getOpenFileNamesMock): self.window = ReTextWindow() self.window.createNew('') @@ -153,7 +170,10 @@ def test_windowTitleAndTabs_afterLoadingFile(self, getOpenFileNamesMock): self.assertEqual(self.window.tabWidget.tabText(0), 'existing_file') self.assertFalse(self.window.isWindowModified()) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_windowTitleAndTabs_afterSwitchingTab(self, getOpenFileNamesMock): self.window = ReTextWindow() self.window.createNew('') @@ -181,7 +201,10 @@ def test_windowTitleAndTabs_afterSwitchingTab(self, getOpenFileNamesMock): self.assertIs(self.window.currentTab, tab_with_file) self.assertIs(self.window.tabWidget.currentWidget(), tab_with_file) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_activeTab_afterLoadingFileThatIsAlreadyOpenInOtherTab(self, getOpenFileNamesMock): self.window = ReTextWindow() self.window.createNew('') @@ -228,7 +251,10 @@ def test_markupDependentWidgetStates_afterChangingDefaultMarkup(self): self.check_widgets_enabled_for_restructuredtext(self.window) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_markupDependentWidgetStates_afterLoadingMarkdownDocument(self, getOpenFileNamesMock): self.window = ReTextWindow() self.window.createNew('') @@ -237,8 +263,14 @@ def test_markupDependentWidgetStates_afterLoadingMarkdownDocument(self, getOpenF self.check_widgets_enabled_for_markdown(self.window) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.rst')], None)) - def test_markupDependentWidgetStates_afterLoadingRestructuredtextDocument(self, getOpenFileNamesMock): + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.rst')], None), + ) + def test_markupDependentWidgetStates_afterLoadingRestructuredtextDocument( + self, + getOpenFileNamesMock, + ): self.window = ReTextWindow() self.window.createNew('') self.window.actionOpen.trigger() @@ -246,8 +278,13 @@ def test_markupDependentWidgetStates_afterLoadingRestructuredtextDocument(self, self.check_widgets_enabled_for_restructuredtext(self.window) - @patch('ReText.window.QFileDialog.getOpenFileNames', side_effect=[ ([os.path.join(path_to_testdata, 'existing_file.md')], None), - ([os.path.join(path_to_testdata, 'existing_file.rst')], None) ]) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + side_effect=[ + ([os.path.join(path_to_testdata, 'existing_file.md')], None), + ([os.path.join(path_to_testdata, 'existing_file.rst')], None), + ], + ) def test_markupDependentWidgetStates_afterSwitchingTab(self, getOpenFileNamesMock): self.window = ReTextWindow() self.window.createNew('') @@ -264,9 +301,19 @@ def test_markupDependentWidgetStates_afterSwitchingTab(self, getOpenFileNamesMoc self.assertIn('.md', self.window.windowTitle()) self.check_widgets_enabled_for_markdown(self.window) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) - @patch('ReText.window.QFileDialog.getSaveFileName', return_value=(os.path.join(path_to_testdata, 'not_existing_file.rst'), None)) - def test_markupDependentWidgetStates_afterSavingDocumentAsDifferentMarkup(self, getSaveFileNameMock, getOpenFileNamesMock): + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) + @patch( + 'ReText.window.QFileDialog.getSaveFileName', + return_value=(os.path.join(path_to_testdata, 'not_existing_file.rst'), None), + ) + def test_markupDependentWidgetStates_afterSavingDocumentAsDifferentMarkup( + self, + getSaveFileNameMock, + getOpenFileNamesMock, + ): self.window = ReTextWindow() self.window.createNew('') self.window.actionOpen.trigger() @@ -281,8 +328,14 @@ def test_markupDependentWidgetStates_afterSavingDocumentAsDifferentMarkup(self, self.check_widgets_enabled_for_restructuredtext(self.window) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) - @patch('ReText.window.QFileDialog.getSaveFileName', return_value=(os.path.join(path_to_testdata, 'not_existing_file.md'), None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) + @patch( + 'ReText.window.QFileDialog.getSaveFileName', + return_value=(os.path.join(path_to_testdata, 'not_existing_file.md'), None), + ) def test_saveWidgetStates(self, getSaveFileNameMock, getOpenFileNamesMock): self.window = ReTextWindow() @@ -327,7 +380,10 @@ def test_saveWidgetStates(self, getSaveFileNameMock, getOpenFileNamesMock): finally: os.remove(os.path.join(path_to_testdata, 'not_existing_file.md')) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_encodingAndReloadWidgetStates(self, getOpenFileNamesMock): self.window = ReTextWindow() @@ -340,7 +396,10 @@ def test_encodingAndReloadWidgetStates(self, getOpenFileNamesMock): app.processEvents() self.check_widgets_enabled(self.window, ('actionReload','actionSetEncoding')) - @patch('ReText.window.QFileDialog.getOpenFileNames', return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None)) + @patch( + 'ReText.window.QFileDialog.getOpenFileNames', + return_value=([os.path.join(path_to_testdata, 'existing_file.md')], None), + ) def test_encodingAndReloadWidgetStates_alwaysDisabledWhenAutosaveEnabled(self, getOpenFileNamesMock): self.globalSettingsMock.autoSave = True self.window = ReTextWindow()