Fix broken tests
This commit is contained in:
@@ -31,7 +31,7 @@ from tools import (
|
||||
|
||||
from PyQt5.QtGui import QColor, QPalette
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QDialog, QMenu, QInputDialog
|
||||
from PyQt5.QtWidgets import QMenu, QInputDialog
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.enum import nwItemType, nwView, nwWidget
|
||||
@@ -39,8 +39,8 @@ from novelwriter.gui.outline import GuiOutlineView
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.gui.noveltree import GuiNovelView
|
||||
from novelwriter.tools.welcome import GuiWelcome
|
||||
from novelwriter.dialogs.about import GuiAbout
|
||||
from novelwriter.dialogs.projload import GuiProjectLoad
|
||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
|
||||
KEY_DELAY = 1
|
||||
@@ -68,8 +68,8 @@ def testGuiMain_ProjectBlocker(nwGUI):
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
|
||||
"""Test the handling of launch tasks."""
|
||||
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None)
|
||||
monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
|
||||
monkeypatch.setattr(GuiWelcome, "exec_", lambda *a: None)
|
||||
# monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
|
||||
CONFIG.lastNotes = "0x0"
|
||||
buildTestProject(nwGUI, projPath)
|
||||
|
||||
@@ -101,11 +101,10 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
|
||||
|
||||
# Check that project open dialog launches
|
||||
nwGUI.postLaunchTasks(None)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000)
|
||||
nwLoad = getGuiItem("GuiProjectLoad")
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
nwLoad.reject()
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiWelcome") is not None, timeout=1000)
|
||||
assert isinstance(welcome := getGuiItem("GuiWelcome"), GuiWelcome)
|
||||
welcome.show()
|
||||
welcome.close()
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ def testGuiTheme_Syntax(qtbot, monkeypatch, nwGUI):
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiTheme_Icons(qtbot, caplog, monkeypatch, nwGUI, tstPaths):
|
||||
def testGuiTheme_IconThemes(qtbot, caplog, monkeypatch, tstPaths):
|
||||
"""Test the icon cache class."""
|
||||
iconCache = SHARED.theme.iconCache
|
||||
|
||||
@@ -305,38 +305,16 @@ def testGuiTheme_Icons(qtbot, caplog, monkeypatch, nwGUI, tstPaths):
|
||||
assert iconCache.loadTheme("typicons_dark") is True
|
||||
assert "add" in iconCache._themeMap
|
||||
|
||||
# Load Decorations
|
||||
# ================
|
||||
# qtbot.stop()
|
||||
|
||||
# Invalid name should return empty pixmap
|
||||
qPix = iconCache.loadDecoration("stuff")
|
||||
assert qPix.isNull() is True
|
||||
# END Test testGuiTheme_IconThemes
|
||||
|
||||
# Load an image
|
||||
qPix = iconCache.loadDecoration("wiz-back")
|
||||
assert qPix.isNull() is False
|
||||
|
||||
# Fail finding the file
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("pathlib.Path.is_file", lambda *a: False)
|
||||
qPix = iconCache.loadDecoration("wiz-back")
|
||||
assert qPix.isNull() is True
|
||||
|
||||
# Test image sizes
|
||||
qPix = iconCache.loadDecoration("wiz-back", w=100, h=None)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() == 100
|
||||
assert qPix.height() > 100
|
||||
|
||||
qPix = iconCache.loadDecoration("wiz-back", w=None, h=100)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() < 100
|
||||
assert qPix.height() == 100
|
||||
|
||||
qPix = iconCache.loadDecoration("wiz-back", w=100, h=100)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() == 100
|
||||
assert qPix.height() == 100
|
||||
@pytest.mark.gui
|
||||
def testGuiTheme_LoadIcons(qtbot):
|
||||
"""Test the icon cache class."""
|
||||
iconCache = SHARED.theme.iconCache
|
||||
assert iconCache.loadTheme("typicons_dark") is True
|
||||
|
||||
# Load Icons
|
||||
# ==========
|
||||
@@ -368,6 +346,19 @@ def testGuiTheme_Icons(qtbot, caplog, monkeypatch, nwGUI, tstPaths):
|
||||
assert isinstance(qIcon, QIcon)
|
||||
assert qIcon.isNull() is False
|
||||
|
||||
# Toggle icon
|
||||
qIcon = iconCache.getToggleIcon("bullet", (24, 24))
|
||||
assert isinstance(qIcon, QIcon)
|
||||
assert qIcon.isNull() is False
|
||||
pOn = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.On)
|
||||
pOff = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.Off)
|
||||
assert pOn != pOff
|
||||
|
||||
# Unknown toggle icon
|
||||
qIcon = iconCache.getToggleIcon("stuff", (24, 24))
|
||||
assert isinstance(qIcon, QIcon)
|
||||
assert qIcon.isNull() is True
|
||||
|
||||
# Load Item Icons
|
||||
# ===============
|
||||
|
||||
@@ -421,6 +412,50 @@ def testGuiTheme_Icons(qtbot, caplog, monkeypatch, nwGUI, tstPaths):
|
||||
nwItemType.NO_TYPE, nwItemClass.NOVEL, nwItemLayout.DOCUMENT, hLevel="H0"
|
||||
).isNull() is True
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testGuiTheme_LoadIcons
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiTheme_LoadDecorations(qtbot, monkeypatch):
|
||||
"""Test the icon cache class."""
|
||||
iconCache = SHARED.theme.iconCache
|
||||
assert iconCache.loadTheme("typicons_dark") is True
|
||||
|
||||
# Load Decorations
|
||||
# ================
|
||||
|
||||
# Invalid name should return empty pixmap
|
||||
qPix = iconCache.loadDecoration("stuff")
|
||||
assert qPix.isNull() is True
|
||||
|
||||
# Load an image
|
||||
qPix = iconCache.loadDecoration("welcome")
|
||||
assert qPix.isNull() is False
|
||||
|
||||
# Fail finding the file
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("pathlib.Path.is_file", lambda *a: False)
|
||||
qPix = iconCache.loadDecoration("welcome")
|
||||
assert qPix.isNull() is True
|
||||
|
||||
# Test image sizes
|
||||
qPix = iconCache.loadDecoration("welcome", w=100, h=None)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() == 100
|
||||
assert qPix.height() > 50
|
||||
|
||||
qPix = iconCache.loadDecoration("welcome", w=None, h=100)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() > 100
|
||||
assert qPix.height() == 100
|
||||
|
||||
qPix = iconCache.loadDecoration("welcome", w=100, h=100)
|
||||
assert qPix.isNull() is False
|
||||
assert qPix.width() == 100
|
||||
assert qPix.height() == 100
|
||||
|
||||
# Header Decorations
|
||||
# ==================
|
||||
|
||||
@@ -432,6 +467,18 @@ def testGuiTheme_Icons(qtbot, caplog, monkeypatch, nwGUI, tstPaths):
|
||||
assert iconCache.getHeaderDecoration(4) == iconCache._headerDec[4]
|
||||
assert iconCache.getHeaderDecoration(5) == iconCache._headerDec[4]
|
||||
|
||||
# Narrow Header Decorations
|
||||
# =========================
|
||||
|
||||
assert iconCache.getHeaderDecorationNarrow(-1) == iconCache._headerDecNarrow[0]
|
||||
assert iconCache.getHeaderDecorationNarrow(0) == iconCache._headerDecNarrow[0]
|
||||
assert iconCache.getHeaderDecorationNarrow(1) == iconCache._headerDecNarrow[1]
|
||||
assert iconCache.getHeaderDecorationNarrow(2) == iconCache._headerDecNarrow[2]
|
||||
assert iconCache.getHeaderDecorationNarrow(3) == iconCache._headerDecNarrow[3]
|
||||
assert iconCache.getHeaderDecorationNarrow(4) == iconCache._headerDecNarrow[4]
|
||||
assert iconCache.getHeaderDecorationNarrow(5) == iconCache._headerDecNarrow[5]
|
||||
assert iconCache.getHeaderDecorationNarrow(6) == iconCache._headerDecNarrow[5]
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testGuiTheme_Icons
|
||||
# END Test testGuiTheme_LoadDecorations
|
||||
|
||||
Reference in New Issue
Block a user