Update tests

This commit is contained in:
Veronica Berglyd Olsen
2023-11-23 16:45:14 +01:00
parent 4bd830f0d6
commit 2998f2c363
2 changed files with 52 additions and 4 deletions
+37 -4
View File
@@ -20,6 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import time
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
import pytest
from pathlib import Path
@@ -32,10 +34,10 @@ from novelwriter.guimain import GuiMain
from novelwriter.common import (
checkBool, checkFloat, checkHandle, checkInt, checkIntTuple, checkPath,
checkString, checkStringNone, checkUuid, formatInt, formatTime,
formatTimeStamp, fuzzyTime, getGuiItem, hexToInt, isHandle, isItemClass,
isItemLayout, isItemType, isTitleTag, jsonEncode, makeFileNameSafe, minmax,
numberToRoman, NWConfigParser, readTextFile, simplified, transferCase,
xmlIndent, yesNo
formatTimeStamp, fuzzyTime, getFileSize, getGuiItem, hexToInt, isHandle,
isItemClass, isItemLayout, isItemType, isTitleTag, jsonEncode,
makeFileNameSafe, minmax, numberToRoman, NWConfigParser, openExternalPath,
readTextFile, simplified, transferCase, xmlIndent, yesNo
)
@@ -621,6 +623,37 @@ def testBaseCommon_makeFileNameSafe():
# END Test testBaseCommon_makeFileNameSafe
@pytest.mark.base
def testBaseCommon_getFileSize(fncPath):
"""Test the getFileSize function."""
(fncPath / "one.txt").write_bytes(b"foobar")
(fncPath / "two.txt").touch()
assert getFileSize(fncPath / "nope.txt") == -1
assert getFileSize(fncPath / "one.txt") == 6
assert getFileSize(fncPath / "two.txt") == 0
# END Test testBaseCommon_getFileSize
@pytest.mark.base
def testBaseCommon_openExternalPath(monkeypatch, tstPaths):
"""Test the openExternalPath function."""
lastUrl = ""
def mockOpenUrl(url: QUrl) -> None:
nonlocal lastUrl
lastUrl = url.toString()
return
monkeypatch.setattr(QDesktopServices, "openUrl", mockOpenUrl)
assert openExternalPath(Path("/foo/bar")) is False
assert openExternalPath(tstPaths.tmpDir) is True
assert lastUrl.startswith("file://")
# END Test testBaseCommon_openExternalPath
@pytest.mark.base
def testBaseCommon_getGuiItem(nwGUI):
"""Check the GUI item function."""
+15
View File
@@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
import pytest
from pathlib import Path
@@ -132,6 +134,19 @@ def testManuscriptBuild_Main(
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
assert manus._runBuild() is False
# Test that the open button works
lastUrl = ""
def mockOpenUrl(url: QUrl) -> None:
nonlocal lastUrl
lastUrl = url.toString()
return
with monkeypatch.context() as mp:
mp.setattr(QDesktopServices, "openUrl", mockOpenUrl)
manus.btnOpen.click()
assert lastUrl.startswith("file://")
# Finish
manus._dialogButtonClicked(manus.dlgButtons.button(QDialogButtonBox.Close))
# qtbot.stop()