Switch test code to PyQt6
This commit is contained in:
@@ -24,12 +24,12 @@ from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QEvent, QMimeData, Qt, QThreadPool, QUrl
|
||||
from PyQt5.QtGui import (
|
||||
QClipboard, QDesktopServices, QDragEnterEvent, QDragMoveEvent, QDropEvent,
|
||||
QFont, QMouseEvent, QTextBlock, QTextCursor, QTextOption
|
||||
from PyQt6.QtCore import QEvent, QMimeData, QPointF, Qt, QThreadPool, QUrl
|
||||
from PyQt6.QtGui import (
|
||||
QAction, QClipboard, QDesktopServices, QDragEnterEvent, QDragMoveEvent,
|
||||
QDropEvent, QFont, QMouseEvent, QTextBlock, QTextCursor, QTextOption
|
||||
)
|
||||
from PyQt5.QtWidgets import QAction, QApplication, QMenu, QPlainTextEdit
|
||||
from PyQt6.QtWidgets import QApplication, QMenu, QPlainTextEdit
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import decodeMimeHandles
|
||||
@@ -102,8 +102,8 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
qDoc = docEditor.document()
|
||||
assert CONFIG.textFont == qDoc.defaultFont()
|
||||
assert qDoc.defaultTextOption().alignment() == QtAlignJustify
|
||||
assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces
|
||||
assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators
|
||||
assert qDoc.defaultTextOption().flags() & QTextOption.Flag.ShowTabsAndSpaces
|
||||
assert qDoc.defaultTextOption().flags() & QTextOption.Flag.ShowLineAndParagraphSeparators
|
||||
assert docEditor.verticalScrollBarPolicy() == QtScrollAlwaysOff
|
||||
assert docEditor.horizontalScrollBarPolicy() == QtScrollAlwaysOff
|
||||
assert docEditor._autoReplace._padChar == nwUnicode.U_THNBSP
|
||||
@@ -262,6 +262,7 @@ def testGuiEditor_DragAndDrop(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
assert mockMove.call_count == 1
|
||||
|
||||
# Drop
|
||||
middle = QPointF(docEditor.viewport().rect().center())
|
||||
mockDrop = MagicMock()
|
||||
docEvent = QDropEvent(middle, action, docMime, mouse, QtModNone)
|
||||
noneEvent = QDropEvent(middle, action, noneMime, mouse, QtModNone)
|
||||
@@ -1708,7 +1709,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
|
||||
# On Known Tag, Follow
|
||||
docEditor.setCursorPosition(22)
|
||||
position = docEditor.cursorRect().center()
|
||||
position = QPointF(docEditor.cursorRect().center())
|
||||
event = QMouseEvent(
|
||||
QEvent.Type.MouseButtonPress, position, QtMouseLeft, QtMouseLeft, QtModCtrl
|
||||
)
|
||||
@@ -1750,7 +1751,7 @@ def testGuiEditor_Links(qtbot, monkeypatch, nwGUI, projPath, ipsumText, mockRnd)
|
||||
docEditor.replaceText("### Scene\n\nFoo http://www.example.com bar.\n\n")
|
||||
|
||||
docEditor.setCursorPosition(20)
|
||||
position = docEditor.cursorRect().center()
|
||||
position = QPointF(docEditor.cursorRect().center())
|
||||
event = QMouseEvent(
|
||||
QEvent.Type.MouseButtonPress, position, QtMouseLeft, QtMouseLeft, QtModCtrl
|
||||
)
|
||||
@@ -1988,7 +1989,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
|
||||
# Select the Word "est"
|
||||
docEditor.setCursorPosition(645)
|
||||
docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
cursor = docEditor.textCursor()
|
||||
assert cursor.selectedText() == "est"
|
||||
|
||||
@@ -2118,7 +2119,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Close search and select "est" again
|
||||
docSearch.cancelSearch.activate(QAction.ActionEvent.Trigger)
|
||||
docEditor.setCursorPosition(645)
|
||||
docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
cursor = docEditor.textCursor()
|
||||
assert cursor.selectedText() == "est"
|
||||
|
||||
|
||||
@@ -24,18 +24,18 @@ from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QEvent, QMimeData, QPoint, Qt, QUrl
|
||||
from PyQt5.QtGui import (
|
||||
QDesktopServices, QDragEnterEvent, QDragMoveEvent, QDropEvent, QMouseEvent,
|
||||
QTextCursor
|
||||
from PyQt6.QtCore import QEvent, QMimeData, QPointF, Qt, QUrl
|
||||
from PyQt6.QtGui import (
|
||||
QAction, QDesktopServices, QDragEnterEvent, QDragMoveEvent, QDropEvent,
|
||||
QMouseEvent, QTextCursor
|
||||
)
|
||||
from PyQt5.QtWidgets import QAction, QApplication, QMenu, QTextBrowser
|
||||
from PyQt6.QtWidgets import QApplication, QMenu, QTextBrowser
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import decodeMimeHandles
|
||||
from novelwriter.enum import nwChange, nwDocAction
|
||||
from novelwriter.formats.toqdoc import ToQTextDocument
|
||||
from novelwriter.types import QtModNone, QtMouseLeft
|
||||
from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle
|
||||
|
||||
from tests.mocked import causeException
|
||||
from tests.tools import C, buildTestProject
|
||||
@@ -59,7 +59,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Middle-click the selected item
|
||||
index = SHARED.project.tree.model.indexFromHandle("88243afbe5ed8")
|
||||
rect = nwGUI.projView.projTree.visualRect(index)
|
||||
qtbot.mouseClick(nwGUI.projView.projTree.viewport(), Qt.MidButton, pos=rect.center())
|
||||
qtbot.mouseClick(nwGUI.projView.projTree.viewport(), QtMouseMiddle, pos=rect.center())
|
||||
assert docViewer.docHandle == "88243afbe5ed8"
|
||||
|
||||
# Clear selection
|
||||
@@ -69,7 +69,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Re-select via header click
|
||||
button = QtMouseLeft
|
||||
modifier = QtModNone
|
||||
event = QMouseEvent(QEvent.Type.MouseButtonPress, QPoint(), button, button, modifier)
|
||||
event = QMouseEvent(QEvent.Type.MouseButtonPress, QPointF(), button, button, modifier)
|
||||
docViewer.docHeader.mousePressEvent(event)
|
||||
assert nwGUI.projView.projTree.getSelectedHandle() == "88243afbe5ed8"
|
||||
|
||||
@@ -89,7 +89,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
cursor = docViewer.textCursor()
|
||||
cursor.setPosition(100)
|
||||
docViewer.setTextCursor(cursor)
|
||||
docViewer._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
|
||||
qClip = QApplication.clipboard()
|
||||
qClip.clear()
|
||||
@@ -158,7 +158,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
cursor = docViewer.textCursor()
|
||||
cursor.setPosition(27)
|
||||
docViewer.setTextCursor(cursor)
|
||||
docViewer._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QMenu, "exec", mockExec)
|
||||
docViewer._openContextMenu(docViewer.cursorRect().center())
|
||||
@@ -168,7 +168,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
cursor = docViewer.textCursor()
|
||||
cursor.setPosition(27)
|
||||
docViewer.setTextCursor(cursor)
|
||||
docViewer._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
rect = docViewer.cursorRect()
|
||||
docViewer._linkClicked(QUrl("#tag_bod"))
|
||||
assert docViewer.docHandle == "4c4f28287af27"
|
||||
@@ -187,11 +187,12 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
assert openUrl.call_args[0][0] == QUrl("http://www.example.com")
|
||||
|
||||
# Click mouse nav buttons
|
||||
qtbot.mouseClick(docViewer.viewport(), Qt.BackButton, pos=rect.center(), delay=100)
|
||||
viewport = docViewer.viewport()
|
||||
qtbot.mouseClick(viewport, Qt.MouseButton.BackButton, pos=rect.center(), delay=100)
|
||||
assert docViewer.docHandle == "88243afbe5ed8"
|
||||
qtbot.mouseClick(docViewer.viewport(), Qt.ForwardButton, pos=rect.center(), delay=100)
|
||||
qtbot.mouseClick(viewport, Qt.MouseButton.ForwardButton, pos=rect.center(), delay=100)
|
||||
assert docViewer.docHandle == "4c4f28287af27"
|
||||
qtbot.mouseClick(docViewer.viewport(), QtMouseLeft, pos=rect.center(), delay=100)
|
||||
qtbot.mouseClick(viewport, QtMouseLeft, pos=rect.center(), delay=100)
|
||||
assert docViewer.docHandle == "4c4f28287af27"
|
||||
|
||||
# Scroll bar default on empty document
|
||||
@@ -299,6 +300,7 @@ def testGuiViewer_DragAndDrop(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Drop
|
||||
mockDrop = MagicMock()
|
||||
middle = QPointF(docViewer.viewport().rect().center())
|
||||
docEvent = QDropEvent(middle, action, docMime, mouse, QtModNone)
|
||||
noneEvent = QDropEvent(middle, action, noneMime, mouse, QtModNone)
|
||||
with monkeypatch.context() as mp:
|
||||
|
||||
@@ -22,7 +22,7 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
||||
from novelwriter import SHARED
|
||||
from novelwriter.constants import nwLists
|
||||
|
||||
@@ -28,9 +28,9 @@ from shutil import copyfile
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QPalette
|
||||
from PyQt5.QtWidgets import QInputDialog, QMenu, QMessageBox
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QPalette
|
||||
from PyQt6.QtWidgets import QInputDialog, QMenu, QMessageBox
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwFiles
|
||||
@@ -782,11 +782,12 @@ def testGuiMain_Features(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
# Full Screen Mode
|
||||
# ================
|
||||
|
||||
assert nwGUI.windowState() & Qt.WindowFullScreen != Qt.WindowFullScreen
|
||||
fullScreen = Qt.WindowState.WindowFullScreen
|
||||
assert nwGUI.windowState() & fullScreen != fullScreen
|
||||
nwGUI.toggleFullScreenMode()
|
||||
assert nwGUI.windowState() & Qt.WindowFullScreen == Qt.WindowFullScreen
|
||||
assert nwGUI.windowState() & fullScreen == fullScreen
|
||||
nwGUI.toggleFullScreenMode()
|
||||
assert nwGUI.windowState() & Qt.WindowFullScreen != Qt.WindowFullScreen
|
||||
assert nwGUI.windowState() & fullScreen != fullScreen
|
||||
|
||||
# SideBar Menu
|
||||
# ============
|
||||
|
||||
@@ -24,7 +24,7 @@ import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
from PyQt6.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.dialogs.about import GuiAbout
|
||||
|
||||
@@ -24,8 +24,8 @@ from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtGui import QDesktopServices, QTextBlock, QTextCursor
|
||||
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
||||
from PyQt6.QtGui import QAction, QDesktopServices, QTextBlock, QTextCursor
|
||||
from PyQt6.QtWidgets import QFileDialog, QMessageBox
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwKeyWords, nwShortcode, nwStats, nwUnicode
|
||||
@@ -187,7 +187,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
|
||||
# Cut, Copy and Paste
|
||||
docEditor.setCursorPosition(54)
|
||||
docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
|
||||
mainMenu.aEditCut.activate(QAction.ActionEvent.Trigger)
|
||||
assert docEditor.getText()[54:104] == (
|
||||
@@ -200,7 +200,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
)
|
||||
|
||||
docEditor.setCursorPosition(54)
|
||||
docEditor._makeSelection(QTextCursor.WordUnderCursor)
|
||||
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
|
||||
|
||||
mainMenu.aEditCopy.activate(QAction.ActionEvent.Trigger)
|
||||
assert docEditor.getText()[54:104] == (
|
||||
|
||||
@@ -24,9 +24,9 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QEvent, QPoint, Qt
|
||||
from PyQt5.QtGui import QFocusEvent
|
||||
from PyQt5.QtWidgets import QInputDialog, QToolTip
|
||||
from PyQt6.QtCore import QEvent, QPoint, Qt
|
||||
from PyQt6.QtGui import QFocusEvent
|
||||
from PyQt6.QtWidgets import QInputDialog, QToolTip
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
@@ -225,7 +225,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
scItem = novelTree.topLevelItem(2)
|
||||
scItem.setSelected(True)
|
||||
assert scItem.isSelected()
|
||||
novelTree.focusOutEvent(QFocusEvent(QEvent.Type.None_, Qt.MouseFocusReason))
|
||||
novelTree.focusOutEvent(QFocusEvent(QEvent.Type.None_, Qt.FocusReason.MouseFocusReason))
|
||||
assert not scItem.isSelected()
|
||||
|
||||
# Close
|
||||
|
||||
@@ -26,7 +26,8 @@ from shutil import copyfile
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QFileDialog, QWidget
|
||||
from PyQt6.QtGui import QAction
|
||||
from PyQt6.QtWidgets import QFileDialog, QWidget
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwKeyWords
|
||||
|
||||
@@ -24,9 +24,9 @@ from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QEvent, QItemSelectionModel, QModelIndex, QPoint
|
||||
from PyQt5.QtGui import QMouseEvent
|
||||
from PyQt5.QtWidgets import QMenu, QMessageBox
|
||||
from PyQt6.QtCore import QEvent, QItemSelectionModel, QModelIndex, QPointF
|
||||
from PyQt6.QtGui import QMouseEvent
|
||||
from PyQt6.QtWidgets import QMenu, QMessageBox
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.dialogs.docmerge import GuiDocMerge
|
||||
@@ -516,14 +516,14 @@ def testGuiProjTree_MouseClicks(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
modifier = QtModNone
|
||||
|
||||
# Trigger the viewer
|
||||
pos = projTree.visualRect(model.indexFromHandle(C.hChapterDoc)).center()
|
||||
pos = QPointF(projTree.visualRect(model.indexFromHandle(C.hChapterDoc)).center())
|
||||
button = QtMouseMiddle
|
||||
event = QMouseEvent(eType, pos, button, button, modifier)
|
||||
projTree.mousePressEvent(event)
|
||||
assert nwGUI.docViewer.docHandle == C.hChapterDoc
|
||||
|
||||
# Trigger the left click clear
|
||||
pos = QPoint(5000, 5000)
|
||||
pos = QPointF(5000.0, 5000.0)
|
||||
button = QtMouseLeft
|
||||
event = QMouseEvent(eType, pos, button, button, modifier)
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ from time import time
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QAction
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QAction
|
||||
|
||||
from novelwriter.enum import nwView
|
||||
from novelwriter.gui.search import GuiProjectSearch
|
||||
|
||||
@@ -24,8 +24,8 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtGui import QColor, QIcon, QPalette, QPixmap
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt6.QtGui import QColor, QIcon, QPalette, QPixmap
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import NWConfigParser
|
||||
|
||||
Reference in New Issue
Block a user