Update test coverage

This commit is contained in:
Veronica Berglyd Olsen
2025-10-26 03:16:22 +01:00
parent a703e0bb7d
commit f2c2833985
4 changed files with 31 additions and 14 deletions
+2 -6
View File
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" # noqa """ # noqa
from __future__ import annotations from __future__ import annotations
from PyQt6.QtGui import QColor, QFont, QPalette, QPixmap from PyQt6.QtGui import QColor, QFont, QPalette
from PyQt6.QtWidgets import ( from PyQt6.QtWidgets import (
QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea, QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
QVBoxLayout, QWidget QVBoxLayout, QWidget
@@ -170,7 +170,7 @@ class NScrollableForm(QScrollArea):
def addRow( def addRow(
self, self,
label: str | None, label: str | None,
widget: QWidget | list[QWidget | QPixmap | int], widget: QWidget | list[QWidget | int],
helpText: str = "", helpText: str = "",
unit: str | None = None, unit: str | None = None,
button: QWidget | None = None, button: QWidget | None = None,
@@ -187,10 +187,6 @@ class NScrollableForm(QScrollArea):
for item in widget: for item in widget:
if isinstance(item, QWidget): if isinstance(item, QWidget):
wBox.addWidget(item) wBox.addWidget(item)
elif isinstance(item, QPixmap):
icon = QLabel(self)
icon.setPixmap(item)
wBox.addWidget(icon)
elif isinstance(item, int): elif isinstance(item, int):
wBox.addSpacing(item) wBox.addSpacing(item)
qWidget = QWidget(self) qWidget = QWidget(self)
+4 -4
View File
@@ -241,9 +241,9 @@ class NIconToolButton(QToolButton):
if icon: if icon:
self.setThemeIcon(icon, color) self.setThemeIcon(icon, color)
def setThemeIcon(self, iconKey: str, color: str | None = None) -> None: def setThemeIcon(self, icon: str, color: str | None = None) -> None:
"""Set an icon from the current theme.""" """Set an icon from the current theme."""
self.setIcon(SHARED.theme.getIcon(iconKey, color)) self.setIcon(SHARED.theme.getIcon(icon, color))
class NIconToggleButton(QToolButton): class NIconToggleButton(QToolButton):
@@ -262,10 +262,10 @@ class NIconToggleButton(QToolButton):
if icon: if icon:
self.setThemeIcon(icon) self.setThemeIcon(icon)
def setThemeIcon(self, iconKey: str) -> None: def setThemeIcon(self, icon: str) -> None:
"""Set an icon from the current theme.""" """Set an icon from the current theme."""
size = self.iconSize() size = self.iconSize()
self.setIcon(SHARED.theme.getToggleIcon(iconKey, (size.width(), size.height()))) self.setIcon(SHARED.theme.getToggleIcon(icon, (size.width(), size.height())))
class NClickableLabel(QLabel): class NClickableLabel(QLabel):
+24 -3
View File
@@ -22,12 +22,13 @@ from __future__ import annotations
import pytest import pytest
from PyQt6.QtCore import QEvent, QPoint, QPointF, Qt from PyQt6.QtCore import QEvent, QPoint, QPointF, QSize, Qt
from PyQt6.QtGui import QKeyEvent, QMouseEvent, QStandardItem, QStandardItemModel, QWheelEvent from PyQt6.QtGui import QKeyEvent, QMouseEvent, QStandardItem, QStandardItemModel, QWheelEvent
from PyQt6.QtWidgets import QWidget from PyQt6.QtWidgets import QWidget
from novelwriter.extensions.modified import ( from novelwriter.extensions.modified import (
NClickableLabel, NComboBox, NDialog, NDoubleSpinBox, NSpinBox, NTreeView NClickableLabel, NComboBox, NDialog, NDoubleSpinBox, NIconToggleButton,
NIconToolButton, NSpinBox, NTreeView
) )
from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected
@@ -168,7 +169,7 @@ def testExtModified_NDoubleSpinBox(qtbot, monkeypatch):
@pytest.mark.gui @pytest.mark.gui
def testExtModified_NClickableLabel(qtbot, monkeypatch): def testExtModified_NClickableLabel(qtbot):
"""Test the NClickableLabel class.""" """Test the NClickableLabel class."""
widget = NClickableLabel() widget = NClickableLabel()
dialog = SimpleDialog(widget) dialog = SimpleDialog(widget)
@@ -181,3 +182,23 @@ def testExtModified_NClickableLabel(qtbot, monkeypatch):
with qtbot.waitSignal(widget.mouseClicked): with qtbot.waitSignal(widget.mouseClicked):
widget.mousePressEvent(event) widget.mousePressEvent(event)
@pytest.mark.gui
def testExtModified_ToolButtons(qtbot):
"""Test the NIconToolButton and NIconToggleButton classes."""
dialog = SimpleDialog(None)
size = QSize(16, 16)
button1 = NIconToolButton(dialog, size, "add", "green")
button2 = NIconToggleButton(dialog, size, "bullet")
assert button1.iconSize() == size
assert button2.iconSize() == size
assert button1.icon().isNull() is False
assert button2.icon().isNull() is False
dialog.addWidget(button1)
dialog.addWidget(button2)
dialog.show()
+1 -1
View File
@@ -152,7 +152,7 @@ def testToolManuscript_Builds(qtbot, nwGUI, projPath):
assert new.name == "Test Build 2" assert new.name == "Test Build 2"
# Trigger a theme update, which should propagate to settings # Trigger a theme update, which should propagate to settings
manus.updateTheme() nwGUI.refreshThemeColors()
# Close the dialog should also close the child dialogs # Close the dialog should also close the child dialogs
manus.btnClose.click() manus.btnClose.click()