Add missing docstrings in tests
This commit is contained in:
@@ -136,7 +136,7 @@ ignore = [
|
||||
]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"tests/*" = ["ANN201", "ANN202", "ANN204", "ANN205", "D101", "D102", "D105", "PLC2701", "RUF069", "SLF", "TC"]
|
||||
"tests/*" = ["ANN201", "ANN202", "ANN204", "ANN205", "PLC2701", "RUF069", "SLF", "TC"]
|
||||
"utils/*" = ["SLF", "TC"]
|
||||
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
|
||||
@@ -32,11 +32,14 @@ from novelwriter.types import QtModNone, QtModShift
|
||||
|
||||
|
||||
class MockWidget(QWidget):
|
||||
"""Mock widget that counts wheel events."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(None)
|
||||
self.count = 0
|
||||
|
||||
def wheelEvent(self, event: QWheelEvent) -> None:
|
||||
"""Count the wheel event."""
|
||||
self.count += 1
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ from tests.mocked import MockGuiMain
|
||||
|
||||
|
||||
class MockWheelEvent(QWheelEvent):
|
||||
"""Mock wheel event that records being ignored."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
QPointF(0, 0),
|
||||
@@ -67,6 +69,7 @@ class MockWheelEvent(QWheelEvent):
|
||||
self.ignored = False
|
||||
|
||||
def ignore(self):
|
||||
"""Ignore the event and record it."""
|
||||
super().ignore()
|
||||
self.ignored = True
|
||||
|
||||
|
||||
@@ -38,67 +38,98 @@ from tests.mocked import MockGuiMain
|
||||
|
||||
|
||||
class MockSignalHolder(QObject):
|
||||
"""Mock object holding the data ready signal."""
|
||||
|
||||
dataReady = pyqtSignal(str, str)
|
||||
|
||||
|
||||
class MockRetriever:
|
||||
"""Mock retriever that only stores the signal."""
|
||||
|
||||
def __init__(self, signal: pyqtBoundSignal) -> None:
|
||||
self.signal = signal
|
||||
|
||||
|
||||
class MockDesktopServices:
|
||||
"""Mock desktop services that record the opened URL."""
|
||||
|
||||
url = None
|
||||
|
||||
@staticmethod
|
||||
def openUrl(url: QUrl) -> None:
|
||||
"""Record the URL instead of opening it."""
|
||||
MockDesktopServices.url = url
|
||||
|
||||
|
||||
class MockData:
|
||||
"""Mock release data."""
|
||||
|
||||
def decode(self, *a: Any) -> str:
|
||||
"""Return a release as JSON."""
|
||||
return '{"tag_name": "v1.0"}'
|
||||
|
||||
|
||||
class MockPayload:
|
||||
"""Mock release payload."""
|
||||
|
||||
def __enter__(self):
|
||||
"""Enter the payload context."""
|
||||
return self
|
||||
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
"""Exit the payload context."""
|
||||
return
|
||||
|
||||
def read(self):
|
||||
"""Return the release data."""
|
||||
return MockData()
|
||||
|
||||
|
||||
class MockListData:
|
||||
"""Mock empty release list data."""
|
||||
|
||||
def decode(self, *a: Any) -> str:
|
||||
"""Return an empty JSON list."""
|
||||
return "[]"
|
||||
|
||||
|
||||
class MockListPayload:
|
||||
"""Mock empty release list payload."""
|
||||
|
||||
def __enter__(self):
|
||||
"""Enter the payload context."""
|
||||
return self
|
||||
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
"""Exit the payload context."""
|
||||
return
|
||||
|
||||
def read(self):
|
||||
"""Return the empty list data."""
|
||||
return MockListData()
|
||||
|
||||
|
||||
class MockHTTPError:
|
||||
"""Mock payload that raises an HTTP error."""
|
||||
|
||||
def __enter__(self):
|
||||
"""Raise an HTTP error."""
|
||||
raise HTTPError("http://example.com", 403, "Rate limit", None, None) # type: ignore
|
||||
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
"""Exit the payload context."""
|
||||
return
|
||||
|
||||
|
||||
class MockException:
|
||||
"""Mock payload that raises a generic exception."""
|
||||
|
||||
def __enter__(self):
|
||||
"""Raise a generic exception."""
|
||||
raise Exception("Oh noes!")
|
||||
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
"""Exit the payload context."""
|
||||
return
|
||||
|
||||
|
||||
|
||||
@@ -44,13 +44,18 @@ TM2 = f"{TMH}:T0002"
|
||||
|
||||
|
||||
class BareTokenizer(Tokenizer):
|
||||
"""Tokenizer that calls the abstract base methods."""
|
||||
|
||||
def doConvert(self):
|
||||
"""Call the abstract convert method."""
|
||||
super().doConvert() # type: ignore (deliberate check)
|
||||
|
||||
def closeDocument(self):
|
||||
"""Call the abstract close method."""
|
||||
super().closeDocument() # type: ignore (deliberate check)
|
||||
|
||||
def saveDocument(self, path: Path) -> None:
|
||||
"""Call the abstract save method."""
|
||||
super().saveDocument(path) # type: ignore (deliberate check)
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ MOCK_TIME = datetime(2019, 5, 10, 18, 52, 0).timestamp()
|
||||
|
||||
|
||||
class C:
|
||||
"""Constants from the test project when the random generator is mocked."""
|
||||
|
||||
# Import and status items from test project when random generator is mocked
|
||||
sNew = "s000000"
|
||||
sNote = "s000001"
|
||||
@@ -264,6 +266,8 @@ def checkWidgetFreedOnRelease(factory: Callable[[], QWidget]) -> None:
|
||||
|
||||
|
||||
class SimpleDialog(QDialog):
|
||||
"""Dialog for showing a single widget in tests."""
|
||||
|
||||
def __init__(self, widget: QWidget | None = None) -> None:
|
||||
super().__init__()
|
||||
self._widget = widget
|
||||
@@ -278,6 +282,7 @@ class SimpleDialog(QDialog):
|
||||
return self._widget
|
||||
|
||||
def addWidget(self, widget: QWidget) -> None:
|
||||
"""Add a widget to the dialog."""
|
||||
self._widget = widget
|
||||
layout = self.layout()
|
||||
assert layout is not None
|
||||
|
||||
@@ -32,6 +32,8 @@ from novelwriter.extensions.modified import NPushButton
|
||||
|
||||
|
||||
class MockGuiMain(QWidget):
|
||||
"""Mock main GUI."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.mainStatus = MagicMock()
|
||||
@@ -41,25 +43,33 @@ class MockGuiMain(QWidget):
|
||||
self.projPath = ""
|
||||
|
||||
def postLaunchTasks(self, cmdOpen: str | None) -> None:
|
||||
"""Skip the post-launch tasks."""
|
||||
return
|
||||
|
||||
def setStatus(self, message: str) -> None:
|
||||
"""Ignore the status message."""
|
||||
return
|
||||
|
||||
def openProject(self, projPath: str) -> None:
|
||||
"""Record the project path."""
|
||||
self.projPath = projPath
|
||||
|
||||
def rebuildIndex(self):
|
||||
"""Skip rebuilding the index."""
|
||||
return
|
||||
|
||||
def closeMain(self):
|
||||
"""Return a marker string."""
|
||||
return "closeMain"
|
||||
|
||||
def close(self):
|
||||
"""Return a marker string."""
|
||||
return "close"
|
||||
|
||||
|
||||
class MockTheme:
|
||||
"""Mock GUI theme."""
|
||||
|
||||
def __init__(self):
|
||||
self.baseIconHeight = 20
|
||||
self.fontPixelSize = 20
|
||||
@@ -68,29 +78,38 @@ class MockTheme:
|
||||
self.guiFontBU = QFont()
|
||||
|
||||
def initThemes(self) -> None:
|
||||
"""Skip initialising the themes."""
|
||||
return
|
||||
|
||||
def getPixmap(self, *a: Any) -> QPixmap:
|
||||
"""Return an empty pixmap."""
|
||||
return QPixmap()
|
||||
|
||||
def getHeaderDecoration(self, *a: Any) -> QPixmap:
|
||||
"""Return an empty pixmap."""
|
||||
return QPixmap()
|
||||
|
||||
def getStandardButton(self, *a: Any) -> NPushButton:
|
||||
"""Return a minimal push button."""
|
||||
return NPushButton(None, "", QSize(1, 1)) # type: ignore
|
||||
|
||||
def getIcon(self, *a: Any) -> QIcon:
|
||||
"""Return an empty icon."""
|
||||
return QIcon()
|
||||
|
||||
def getItemIcon(self, *a: Any, **k: Any) -> QIcon:
|
||||
"""Return an empty icon."""
|
||||
return QIcon()
|
||||
|
||||
|
||||
class MockApp:
|
||||
"""Mock application."""
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
def installTranslator(self, language: QTranslator) -> None:
|
||||
"""Ignore the translator."""
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user