Update tests
This commit is contained in:
@@ -20,6 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
from PyQt5.QtGui import QDesktopServices
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -32,10 +34,10 @@ from novelwriter.guimain import GuiMain
|
|||||||
from novelwriter.common import (
|
from novelwriter.common import (
|
||||||
checkBool, checkFloat, checkHandle, checkInt, checkIntTuple, checkPath,
|
checkBool, checkFloat, checkHandle, checkInt, checkIntTuple, checkPath,
|
||||||
checkString, checkStringNone, checkUuid, formatInt, formatTime,
|
checkString, checkStringNone, checkUuid, formatInt, formatTime,
|
||||||
formatTimeStamp, fuzzyTime, getGuiItem, hexToInt, isHandle, isItemClass,
|
formatTimeStamp, fuzzyTime, getFileSize, getGuiItem, hexToInt, isHandle,
|
||||||
isItemLayout, isItemType, isTitleTag, jsonEncode, makeFileNameSafe, minmax,
|
isItemClass, isItemLayout, isItemType, isTitleTag, jsonEncode,
|
||||||
numberToRoman, NWConfigParser, readTextFile, simplified, transferCase,
|
makeFileNameSafe, minmax, numberToRoman, NWConfigParser, openExternalPath,
|
||||||
xmlIndent, yesNo
|
readTextFile, simplified, transferCase, xmlIndent, yesNo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -621,6 +623,37 @@ def testBaseCommon_makeFileNameSafe():
|
|||||||
# END Test 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
|
@pytest.mark.base
|
||||||
def testBaseCommon_getGuiItem(nwGUI):
|
def testBaseCommon_getGuiItem(nwGUI):
|
||||||
"""Check the GUI item function."""
|
"""Check the GUI item function."""
|
||||||
|
|||||||
@@ -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/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
from PyQt5.QtGui import QDesktopServices
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -132,6 +134,19 @@ def testManuscriptBuild_Main(
|
|||||||
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
|
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
|
||||||
assert manus._runBuild() is False
|
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
|
# Finish
|
||||||
manus._dialogButtonClicked(manus.dlgButtons.button(QDialogButtonBox.Close))
|
manus._dialogButtonClicked(manus.dlgButtons.button(QDialogButtonBox.Close))
|
||||||
# qtbot.stop()
|
# qtbot.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user