diff --git a/nw/core/item.py b/nw/core/item.py index ead16ab8..477f2df9 100644 --- a/nw/core/item.py +++ b/nw/core/item.py @@ -43,7 +43,7 @@ class NWItem(): self.itemName = "" self.itemHandle = None self.itemParent = None - self.itemOrder = None + self.itemOrder = 0 self.itemType = nwItemType.NO_TYPE self.itemClass = nwItemClass.NO_CLASS self.itemLayout = nwItemLayout.NO_LAYOUT diff --git a/tests/conftest.py b/tests/conftest.py index 97aafd7d..863818eb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,7 @@ import os from nwdummy import DummyMain -# from PyQt5.QtWidgets import QMessageBox +from PyQt5.QtWidgets import QMessageBox sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) @@ -33,28 +33,10 @@ def tmpDir(): os.mkdir(tempDir) return tempDir -# @pytest.fixture(scope="session") -# def nwRef(): -# """The folder where all the reference files are stored for verifying -# the results of tests. -# """ -# testDir = os.path.dirname(__file__) -# refDir = os.path.join(testDir, "reference") -# return refDir - ## # novelWriter Objects ## -# @pytest.fixture(scope="session") -# def tmpConf(nwTemp): -# """Create a temporary novelWriter configuration object. -# """ -# theConf = Config() -# theConf.initConfig(nwTemp, nwTemp) -# theConf.setLastPath("") -# return theConf - @pytest.fixture(scope="session") def tmpConf(tmpDir): """Create a temporary novelWriter configuration object. @@ -64,15 +46,6 @@ def tmpConf(tmpDir): theConf.setLastPath("") return theConf -# @pytest.fixture(scope="session") -# def nwConf(nwRef, nwTemp): -# """Temporary novelWriter configuration used for the dummy instance -# of novelWriter's main GUI. -# """ -# theConf = Config() -# theConf.initConfig(nwRef, nwTemp) -# return theConf - @pytest.fixture(scope="session") def dummyGUI(tmpConf): """Create a dummy instance of novelWriter's main GUI class. @@ -81,131 +54,159 @@ def dummyGUI(tmpConf): theDummy.mainConf = tmpConf return theDummy +# =============================================================================================== # + +## +# Core Test Folders +## + +@pytest.fixture(scope="session") +def nwRef(): + """The folder where all the reference files are stored for verifying + the results of tests. + """ + testDir = os.path.dirname(__file__) + refDir = os.path.join(testDir, "reference") + return refDir + +## +# novelWriter Objects +## + +@pytest.fixture(scope="session") +def nwConf(nwRef, tmpDir): + """Temporary novelWriter configuration used for the dummy instance + of novelWriter's main GUI. + """ + theConf = Config() + theConf.initConfig(nwRef, tmpDir) + return theConf + ## # Temporary Test Folders ## -# @pytest.fixture(scope="session") -# def nwTempProj(nwTemp): -# """A temporary folder for project tests. -# """ -# projDir = os.path.join(nwTemp, "proj") -# if not os.path.isdir(projDir): -# os.mkdir(projDir) -# return projDir +@pytest.fixture(scope="session") +def nwTempProj(tmpDir): + """A temporary folder for project tests. + """ + projDir = os.path.join(tmpDir, "proj") + if not os.path.isdir(projDir): + os.mkdir(projDir) + return projDir -# @pytest.fixture(scope="session") -# def nwTempGUI(nwTemp): -# """A temporary folder for GUI tests. -# """ -# guiDir = os.path.join(nwTemp, "gui") -# if not os.path.isdir(guiDir): -# os.mkdir(guiDir) -# return guiDir +@pytest.fixture(scope="session") +def nwTempGUI(tmpDir): + """A temporary folder for GUI tests. + """ + guiDir = os.path.join(tmpDir, "gui") + if not os.path.isdir(guiDir): + os.mkdir(guiDir) + return guiDir -# @pytest.fixture(scope="session") -# def nwTempBuild(nwTemp): -# """A temporary folder for build tests. -# """ -# buildDir = os.path.join(nwTemp, "build") -# if not os.path.isdir(buildDir): -# os.mkdir(buildDir) -# return buildDir +@pytest.fixture(scope="session") +def nwTempBuild(tmpDir): + """A temporary folder for build tests. + """ + buildDir = os.path.join(tmpDir, "build") + if not os.path.isdir(buildDir): + os.mkdir(buildDir) + return buildDir -# @pytest.fixture(scope="function") -# def nwFuncTemp(nwTemp): -# """A temporary folder for a single test function. -# """ -# funcDir = os.path.join(nwTemp, "ftemp") -# if os.path.isdir(funcDir): -# shutil.rmtree(funcDir) -# if not os.path.isdir(funcDir): -# os.mkdir(funcDir) -# yield funcDir -# if os.path.isdir(funcDir): -# shutil.rmtree(funcDir) -# return +@pytest.fixture(scope="function") +def nwFuncTemp(tmpDir): + """A temporary folder for a single test function. + """ + funcDir = os.path.join(tmpDir, "ftemp") + if os.path.isdir(funcDir): + shutil.rmtree(funcDir) + if not os.path.isdir(funcDir): + os.mkdir(funcDir) + yield funcDir + if os.path.isdir(funcDir): + shutil.rmtree(funcDir) + return ## # Temp Folders for Projects ## -# @pytest.fixture(scope="function") -# def nwMinimal(nwTemp): -# """A minimal novelWriter example project. -# """ -# testDir = os.path.dirname(__file__) -# minimalStore = os.path.join(testDir, "minimal") -# minimalDir = os.path.join(nwTemp, "minimal") -# if os.path.isdir(minimalDir): -# shutil.rmtree(minimalDir) -# shutil.copytree(minimalStore, minimalDir) -# cacheDir = os.path.join(minimalDir, "cache") -# if os.path.isdir(cacheDir): -# shutil.rmtree(cacheDir) -# metaDir = os.path.join(minimalDir, "meta") -# if os.path.isdir(metaDir): -# shutil.rmtree(metaDir) -# yield minimalDir -# if os.path.isdir(minimalDir): -# shutil.rmtree(minimalDir) -# return +@pytest.fixture(scope="function") +def nwMinimal(tmpDir): + """A minimal novelWriter example project. + """ + testDir = os.path.dirname(__file__) + minimalStore = os.path.join(testDir, "minimal") + minimalDir = os.path.join(tmpDir, "minimal") + if os.path.isdir(minimalDir): + shutil.rmtree(minimalDir) + shutil.copytree(minimalStore, minimalDir) + cacheDir = os.path.join(minimalDir, "cache") + if os.path.isdir(cacheDir): + shutil.rmtree(cacheDir) + metaDir = os.path.join(minimalDir, "meta") + if os.path.isdir(metaDir): + shutil.rmtree(metaDir) + yield minimalDir + if os.path.isdir(minimalDir): + shutil.rmtree(minimalDir) + return -# @pytest.fixture(scope="function") -# def nwLipsum(nwTemp): -# """A medium sized novelWriter example project with a lot of Lorem -# Ipsum dummy text. -# """ -# testDir = os.path.dirname(__file__) -# lipsumStore = os.path.join(testDir, "lipsum") -# lipsumDir = os.path.join(nwTemp, "lipsum") -# if os.path.isdir(lipsumDir): -# shutil.rmtree(lipsumDir) -# shutil.copytree(lipsumStore, lipsumDir) -# cacheDir = os.path.join(lipsumDir, "cache") -# if os.path.isdir(cacheDir): -# shutil.rmtree(cacheDir) -# metaDir = os.path.join(lipsumDir, "meta") -# if os.path.isdir(metaDir): -# shutil.rmtree(metaDir) -# yield lipsumDir -# if os.path.isdir(lipsumDir): -# shutil.rmtree(lipsumDir) -# return +@pytest.fixture(scope="function") +def nwLipsum(tmpDir): + """A medium sized novelWriter example project with a lot of Lorem + Ipsum dummy text. + """ + testDir = os.path.dirname(__file__) + lipsumStore = os.path.join(testDir, "lipsum") + lipsumDir = os.path.join(tmpDir, "lipsum") + if os.path.isdir(lipsumDir): + shutil.rmtree(lipsumDir) + shutil.copytree(lipsumStore, lipsumDir) + cacheDir = os.path.join(lipsumDir, "cache") + if os.path.isdir(cacheDir): + shutil.rmtree(cacheDir) + metaDir = os.path.join(lipsumDir, "meta") + if os.path.isdir(metaDir): + shutil.rmtree(metaDir) + yield lipsumDir + if os.path.isdir(lipsumDir): + shutil.rmtree(lipsumDir) + return -# @pytest.fixture(scope="function") -# def nwOldProj(nwTemp): -# """A minimal movelWriter project using the old folder structure. -# """ -# testDir = os.path.dirname(__file__) -# oldProjStore = os.path.join(testDir, "oldproj") -# oldProjDir = os.path.join(nwTemp, "oldproj") -# if os.path.isdir(oldProjDir): -# shutil.rmtree(oldProjDir) -# shutil.copytree(oldProjStore, oldProjDir) -# yield oldProjDir -# if os.path.isdir(oldProjDir): -# shutil.rmtree(oldProjDir) -# return +@pytest.fixture(scope="function") +def nwOldProj(tmpDir): + """A minimal movelWriter project using the old folder structure. + """ + testDir = os.path.dirname(__file__) + oldProjStore = os.path.join(testDir, "oldproj") + oldProjDir = os.path.join(tmpDir, "oldproj") + if os.path.isdir(oldProjDir): + shutil.rmtree(oldProjDir) + shutil.copytree(oldProjStore, oldProjDir) + yield oldProjDir + if os.path.isdir(oldProjDir): + shutil.rmtree(oldProjDir) + return ## # Monkey Patch Dialogs ## -# @pytest.fixture(scope="function") -# def yesToAll(monkeypatch): -# """Make the message boxes/questions always say yes. -# """ -# monkeypatch.setattr( -# QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes -# ) -# monkeypatch.setattr( -# QMessageBox, "information", lambda *args, **kwargs: QMessageBox.Yes -# ) -# monkeypatch.setattr( -# QMessageBox, "warning", lambda *args, **kwargs: QMessageBox.Yes -# ) -# monkeypatch.setattr( -# QMessageBox, "critical", lambda *args, **kwargs: QMessageBox.Yes -# ) -# return +@pytest.fixture(scope="function") +def yesToAll(monkeypatch): + """Make the message boxes/questions always say yes. + """ + monkeypatch.setattr( + QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes + ) + monkeypatch.setattr( + QMessageBox, "information", lambda *args, **kwargs: QMessageBox.Yes + ) + monkeypatch.setattr( + QMessageBox, "warning", lambda *args, **kwargs: QMessageBox.Yes + ) + monkeypatch.setattr( + QMessageBox, "critical", lambda *args, **kwargs: QMessageBox.Yes + ) + return diff --git a/tests/reference/proj/1_nwProject.nwx b/tests/reference/proj/1_nwProject.nwx index 61ece12f..d8b774bb 100644 --- a/tests/reference/proj/1_nwProject.nwx +++ b/tests/reference/proj/1_nwProject.nwx @@ -39,35 +39,35 @@ - + Novel ROOT NOVEL New False - + Plot ROOT PLOT New False - + Characters ROOT CHARACTER New False - + World ROOT WORLD New False - + Title Page FILE NOVEL @@ -79,14 +79,14 @@ 0 0 - + New Chapter FOLDER NOVEL New False - + New Chapter FILE NOVEL @@ -98,7 +98,7 @@ 0 0 - + New Scene FILE NOVEL diff --git a/tests/reference/proj/2_nwProject.nwx b/tests/reference/proj/2_nwProject.nwx index cc7b54ea..9ea0617f 100644 --- a/tests/reference/proj/2_nwProject.nwx +++ b/tests/reference/proj/2_nwProject.nwx @@ -39,35 +39,35 @@ - + Novel ROOT NOVEL New False - + Plot ROOT PLOT New False - + Characters ROOT CHARACTER New False - + World ROOT WORLD New False - + Title Page FILE NOVEL @@ -79,14 +79,14 @@ 0 0 - + New Chapter FOLDER NOVEL New False - + New Chapter FILE NOVEL @@ -98,7 +98,7 @@ 0 0 - + New Scene FILE NOVEL @@ -110,28 +110,28 @@ 0 0 - + Timeline ROOT TIMELINE New False - + Object ROOT OBJECT New False - + Custom1 ROOT CUSTOM New False - + Custom2 ROOT CUSTOM diff --git a/tests/reference/proj/3_nwProject.nwx b/tests/reference/proj/3_nwProject.nwx index c9e450d6..66488434 100644 --- a/tests/reference/proj/3_nwProject.nwx +++ b/tests/reference/proj/3_nwProject.nwx @@ -39,35 +39,35 @@ - + Novel ROOT NOVEL New False - + Plot ROOT PLOT New False - + Characters ROOT CHARACTER New False - + World ROOT WORLD New False - + Title Page FILE NOVEL @@ -79,14 +79,14 @@ 0 0 - + New Chapter FOLDER NOVEL New False - + New Chapter FILE NOVEL @@ -98,7 +98,7 @@ 0 0 - + New Scene FILE NOVEL @@ -110,7 +110,7 @@ 0 0 - + Hello FILE NOVEL @@ -122,7 +122,7 @@ 0 0 - + Jane FILE CHARACTER diff --git a/tests/reference/proj/4_nwProject.nwx b/tests/reference/proj/4_nwProject.nwx index 4c9c30eb..fc7e7ab2 100644 --- a/tests/reference/proj/4_nwProject.nwx +++ b/tests/reference/proj/4_nwProject.nwx @@ -41,56 +41,56 @@ - + Novel ROOT NOVEL New False - + Plot ROOT PLOT New False - + Characters ROOT CHARACTER New False - + Locations ROOT WORLD New False - + Timeline ROOT TIMELINE New False - + Objects ROOT OBJECT New False - + Entity ROOT ENTITY New False - + Title Page FILE NOVEL @@ -102,14 +102,14 @@ 0 0 - + Chapter 1 FOLDER NOVEL New False - + Chapter 1 FILE NOVEL @@ -121,7 +121,7 @@ 0 0 - + Scene 1.1 FILE NOVEL @@ -133,7 +133,7 @@ 0 0 - + Scene 1.2 FILE NOVEL @@ -145,7 +145,7 @@ 0 0 - + Scene 1.3 FILE NOVEL @@ -157,14 +157,14 @@ 0 0 - + Chapter 2 FOLDER NOVEL New False - + Chapter 2 FILE NOVEL @@ -176,7 +176,7 @@ 0 0 - + Scene 2.1 FILE NOVEL @@ -188,7 +188,7 @@ 0 0 - + Scene 2.2 FILE NOVEL @@ -200,7 +200,7 @@ 0 0 - + Scene 2.3 FILE NOVEL @@ -212,14 +212,14 @@ 0 0 - + Chapter 3 FOLDER NOVEL New False - + Chapter 3 FILE NOVEL @@ -231,7 +231,7 @@ 0 0 - + Scene 3.1 FILE NOVEL @@ -243,7 +243,7 @@ 0 0 - + Scene 3.2 FILE NOVEL @@ -255,7 +255,7 @@ 0 0 - + Scene 3.3 FILE NOVEL diff --git a/tests/reference/proj/5_nwProject.nwx b/tests/reference/proj/5_nwProject.nwx index 9935736e..11d007aa 100644 --- a/tests/reference/proj/5_nwProject.nwx +++ b/tests/reference/proj/5_nwProject.nwx @@ -41,56 +41,56 @@ - + Novel ROOT NOVEL New False - + Plot ROOT PLOT New False - + Characters ROOT CHARACTER New False - + Locations ROOT WORLD New False - + Timeline ROOT TIMELINE New False - + Objects ROOT OBJECT New False - + Entity ROOT ENTITY New False - + Title Page FILE NOVEL @@ -102,7 +102,7 @@ 0 0 - + Scene 1 FILE NOVEL @@ -114,7 +114,7 @@ 0 0 - + Scene 2 FILE NOVEL @@ -126,7 +126,7 @@ 0 0 - + Scene 3 FILE NOVEL @@ -138,7 +138,7 @@ 0 0 - + Scene 4 FILE NOVEL @@ -150,7 +150,7 @@ 0 0 - + Scene 5 FILE NOVEL @@ -162,7 +162,7 @@ 0 0 - + Scene 6 FILE NOVEL diff --git a/tests/test_config.py b/tests/test_config.py index 5d72cdfd..ad83ddd5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -8,11 +8,11 @@ import os from nwtools import cmpFiles @pytest.mark.core -def testConfigCore(tmpConf, nwTemp, nwRef): +def testConfigCore(tmpConf, tmpDir, nwRef): refConf = os.path.join(nwRef, "novelwriter.conf") testConf = os.path.join(tmpConf.confPath, "novelwriter.conf") - assert tmpConf.confPath == nwTemp + assert tmpConf.confPath == tmpDir assert tmpConf.saveConfig() assert cmpFiles(testConf, refConf, [2, 9]) assert not tmpConf.confChanged @@ -21,29 +21,29 @@ def testConfigCore(tmpConf, nwTemp, nwRef): assert not tmpConf.confChanged @pytest.mark.core -def testConfigSetConfPath(tmpConf, nwTemp): +def testConfigSetConfPath(tmpConf, tmpDir): assert tmpConf.setConfPath(None) assert not tmpConf.setConfPath(os.path.join("somewhere", "over", "the", "rainbow")) - assert tmpConf.setConfPath(os.path.join(nwTemp, "novelwriter.conf")) - assert tmpConf.confPath == nwTemp + assert tmpConf.setConfPath(os.path.join(tmpDir, "novelwriter.conf")) + assert tmpConf.confPath == tmpDir assert tmpConf.confFile == "novelwriter.conf" assert not tmpConf.confChanged @pytest.mark.core -def testConfigSetDataPath(tmpConf, nwTemp): +def testConfigSetDataPath(tmpConf, tmpDir): assert tmpConf.setDataPath(None) assert not tmpConf.setDataPath(os.path.join("somewhere", "over", "the", "rainbow")) - assert tmpConf.setDataPath(nwTemp) - assert tmpConf.dataPath == nwTemp + assert tmpConf.setDataPath(tmpDir) + assert tmpConf.dataPath == tmpDir assert not tmpConf.confChanged @pytest.mark.core -def testConfigSetWinSize(tmpConf, nwTemp, nwRef): +def testConfigSetWinSize(tmpConf, tmpDir, nwRef): refConf = os.path.join(nwRef, "novelwriter.conf") testConf = os.path.join(tmpConf.confPath, "novelwriter.conf") tmpConf.guiScale = 1.0 - assert tmpConf.confPath == nwTemp + assert tmpConf.confPath == tmpDir assert tmpConf.setWinSize(1205, 655) assert not tmpConf.confChanged assert tmpConf.setWinSize(70, 70) @@ -55,11 +55,11 @@ def testConfigSetWinSize(tmpConf, nwTemp, nwRef): assert not tmpConf.confChanged @pytest.mark.core -def testConfigSetTreeColWidths(tmpConf, nwTemp, nwRef): +def testConfigSetTreeColWidths(tmpConf, tmpDir, nwRef): refConf = os.path.join(nwRef, "novelwriter.conf") testConf = os.path.join(tmpConf.confPath, "novelwriter.conf") - assert tmpConf.confPath == nwTemp + assert tmpConf.confPath == tmpDir tmpConf.guiScale = 1.0 assert tmpConf.setTreeColWidths([10, 20, 25]) @@ -77,11 +77,11 @@ def testConfigSetTreeColWidths(tmpConf, nwTemp, nwRef): assert not tmpConf.confChanged @pytest.mark.core -def testConfigSetPanePos(tmpConf, nwTemp, nwRef): +def testConfigSetPanePos(tmpConf, tmpDir, nwRef): refConf = os.path.join(nwRef, "novelwriter.conf") testConf = os.path.join(tmpConf.confPath, "novelwriter.conf") - assert tmpConf.confPath == nwTemp + assert tmpConf.confPath == tmpDir tmpConf.guiScale = 2.0 assert tmpConf.setMainPanePos([200, 700]) @@ -113,11 +113,11 @@ def testConfigSetPanePos(tmpConf, nwTemp, nwRef): assert not tmpConf.confChanged @pytest.mark.core -def testConfigFlags(tmpConf, nwTemp, nwRef): +def testConfigFlags(tmpConf, tmpDir, nwRef): refConf = os.path.join(nwRef, "novelwriter.conf") testConf = os.path.join(tmpConf.confPath, "novelwriter.conf") - assert tmpConf.confPath == nwTemp + assert tmpConf.confPath == tmpDir assert not tmpConf.setShowRefPanel(False) assert tmpConf.setShowRefPanel(True) @@ -137,8 +137,8 @@ def testConfigFlags(tmpConf, nwTemp, nwRef): assert not tmpConf.confChanged @pytest.mark.core -def testTextSizes(tmpConf, nwTemp, nwRef): - assert tmpConf.confPath == nwTemp +def testTextSizes(tmpConf, tmpDir, nwRef): + assert tmpConf.confPath == tmpDir tmpConf.guiScale = 2.0 assert tmpConf.getTextWidth() == 1200 diff --git a/tests/test_core_tree.py b/tests/test_core_tree.py index f8c9e42b..c3b68964 100644 --- a/tests/test_core_tree.py +++ b/tests/test_core_tree.py @@ -345,30 +345,30 @@ def testCoreTree_XMLPackUnpack(dummyGUI, dummyItems): assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == ( b"" b"" - b"" + b"" b"NovelROOTNOVELNone" b"True" - b"" + b"" b"Act OneFOLDERNOVELNone" b"True" - b"" + b"" b"Chapter OneFILENOVELNone" b"TrueUNNUMBERED300" b"5020" - b"" + b"" b"Scene OneFILENOVELNone" b"TrueSCENE3000" b"500200" - b"" + b"" b"OuttakesROOTARCHIVENone" b"False" - b"" + b"" b"TrashTRASHTRASHNone" b"False" - b"" + b"" b"CharactersROOTCHARACTERNone" b"True" - b"" + b"" b"Jane DoeFILECHARACTERNone" b"TrueNOTE2000" b"400160" diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index 4c1f1885..5e9a319f 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -30,8 +30,8 @@ typeDelay = 1 stepDelay = 20 @pytest.mark.gui -def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) +def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwRef, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -145,8 +145,8 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwR nwGUI.closeMain() @pytest.mark.gui -def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) +def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -218,8 +218,8 @@ def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, n nwGUI.closeMain() @pytest.mark.gui -def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) +def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -357,8 +357,8 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTemp): nwGUI.closeMain() @pytest.mark.gui -def testAboutBox(qtbot, monkeypatch, nwFuncTemp, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) +def testAboutBox(qtbot, monkeypatch, nwFuncTemp, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -397,9 +397,9 @@ def testAboutBox(qtbot, monkeypatch, nwFuncTemp, nwTemp): nwGUI.closeMain() @pytest.mark.gui -def testBuildTool(qtbot, yesToAll, nwTempBuild, nwLipsum, nwRef, nwTemp): +def testBuildTool(qtbot, yesToAll, nwTempBuild, nwLipsum, nwRef, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -589,9 +589,9 @@ def testBuildTool(qtbot, yesToAll, nwTempBuild, nwLipsum, nwRef, nwTemp): nwGUI.closeMain() @pytest.mark.gui -def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef, nwTemp): +def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -740,7 +740,7 @@ def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef nwGUI.closeMain() @pytest.mark.gui -def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): +def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, tmpDir): if sys.platform.startswith("darwin"): # Disable for macOS because the test segfaults on QWizard.show() @@ -752,7 +752,7 @@ def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): ProjWizardCustomPage, ProjWizardFinalPage ) - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -937,8 +937,8 @@ def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): nwGUI.close() @pytest.mark.gui -def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp]) +def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1017,8 +1017,8 @@ def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): nwGUI.close() @pytest.mark.gui -def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpConf): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp]) +def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, tmpDir, nwRef, tmpConf): + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1205,7 +1205,7 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC refConf = os.path.join(nwRef, "novelwriter_prefs.conf") projConf = os.path.join(nwGUI.mainConf.confPath, "novelwriter.conf") - testConf = os.path.join(nwTemp, "novelwriter_prefs.conf") + testConf = os.path.join(tmpDir, "novelwriter_prefs.conf") copyfile(projConf, testConf) ignoreLines = [ 2, # Timestamp @@ -1216,8 +1216,8 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC assert cmpFiles(testConf, refConf, ignoreLines) @pytest.mark.gui -def testQuotesDialog(qtbot, yesToAll, nwMinimal, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal]) +def testQuotesDialog(qtbot, yesToAll, nwMinimal, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1246,15 +1246,15 @@ def testQuotesDialog(qtbot, yesToAll, nwMinimal, nwTemp): nwGUI.close() @pytest.mark.gui -def testDialogsOpenClose(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal]) +def testDialogsOpenClose(qtbot, monkeypatch, yesToAll, nwMinimal, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) qtbot.wait(stepDelay) - monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: nwTemp) - assert nwGUI.selectProjectPath() == nwTemp + monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: tmpDir) + assert nwGUI.selectProjectPath() == tmpDir # qtbot.stopForInteraction() nwGUI.closeMain() diff --git a/tests/test_error.py b/tests/test_error.py index 179efa68..7ad07269 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -10,9 +10,9 @@ from PyQt5.QtWidgets import qApp from nw.error import NWErrorMessage, exceptionHandler @pytest.mark.error -def testErrorDialog(qtbot, nwFuncTemp, nwTemp): +def testErrorDialog(qtbot, nwFuncTemp, tmpDir): qApp.closeAllWindows() - nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) diff --git a/tests/test_gui.py b/tests/test_gui.py index fcf96c06..2b10b5de 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -27,11 +27,11 @@ typeDelay = 1 stepDelay = 20 @pytest.mark.gui -def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): +def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): # Defaults nwGUI = nw.main( - ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp, "--style=Fusion"] + ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir, "--style=Fusion"] ) assert nw.logger.getEffectiveLevel() == logging.WARNING nwGUI.closeMain() @@ -39,21 +39,21 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): # Log Levels nwGUI = nw.main( - ["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == logging.INFO nwGUI.closeMain() nwGUI.close() nwGUI = nw.main( - ["--testmode", "--debug", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--debug", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == logging.DEBUG nwGUI.closeMain() nwGUI.close() nwGUI = nw.main( - ["--testmode", "--verbose", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--verbose", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == 5 nwGUI.closeMain() @@ -62,7 +62,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): # Help and Version with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -70,7 +70,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--version", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--version", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -79,7 +79,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): # Invalid options with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -92,7 +92,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): monkeypatch.setattr("nw.CONFIG.verPyQtValue", 50000) with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] + ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -103,9 +103,9 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp): monkeypatch.undo() @pytest.mark.gui -def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp): +def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -414,9 +414,9 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp): nwGUI.close() @pytest.mark.gui -def testDocViewer(qtbot, yesToAll, nwLipsum, nwTemp): +def testDocViewer(qtbot, yesToAll, nwLipsum, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -566,9 +566,9 @@ def testDocViewer(qtbot, yesToAll, nwLipsum, nwTemp): nwGUI.close() @pytest.mark.gui -def testProjectTree(qtbot, yesToAll, nwMinimal, nwTemp): +def testProjectTree(qtbot, yesToAll, nwMinimal, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -690,9 +690,9 @@ def testProjectTree(qtbot, yesToAll, nwMinimal, nwTemp): nwGUI.close() @pytest.mark.gui -def testEditFormatMenu(qtbot, yesToAll, nwLipsum, nwTemp): +def testEditFormatMenu(qtbot, yesToAll, nwLipsum, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -927,9 +927,9 @@ def testEditFormatMenu(qtbot, yesToAll, nwLipsum, nwTemp): nwGUI.close() @pytest.mark.gui -def testContextMenu(qtbot, yesToAll, nwLipsum, nwTemp): +def testContextMenu(qtbot, yesToAll, nwLipsum, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1013,8 +1013,8 @@ def testContextMenu(qtbot, yesToAll, nwLipsum, nwTemp): nwGUI.close() @pytest.mark.gui -def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp): - nwGUI = nw.main(["--testmode", "--config=%s" % nwTemp, "--data=%s" % nwTemp]) +def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1162,7 +1162,7 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp): assert not nwGUI.importDocument() # Then a valid path, but bot a file that exists - theFile = os.path.join(nwTemp, "import.txt") + theFile = os.path.join(tmpDir, "import.txt") monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: (theFile, "")) assert not nwGUI.importDocument() @@ -1212,9 +1212,9 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp): nwGUI.close() @pytest.mark.gui -def testTextSearch(qtbot, monkeypatch, yesToAll, nwLipsum, nwTemp): +def testTextSearch(qtbot, monkeypatch, yesToAll, nwLipsum, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1392,9 +1392,9 @@ def testTextSearch(qtbot, monkeypatch, yesToAll, nwLipsum, nwTemp): nwGUI.close() @pytest.mark.gui -def testOutline(qtbot, yesToAll, nwLipsum, nwTemp): +def testOutline(qtbot, yesToAll, nwLipsum, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1453,9 +1453,9 @@ def testOutline(qtbot, yesToAll, nwLipsum, nwTemp): nwGUI.close() @pytest.mark.gui -def testThemes(qtbot, yesToAll, nwMinimal, nwTemp): +def testThemes(qtbot, yesToAll, nwMinimal, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) @@ -1478,7 +1478,7 @@ def testThemes(qtbot, yesToAll, nwMinimal, nwTemp): # Re-open assert nw.CONFIG.confPath == nwMinimal - nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal]) + nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % tmpDir, nwMinimal]) assert nwGUI.mainConf.confPath == nwMinimal qtbot.addWidget(nwGUI) nwGUI.show() diff --git a/tests/test_index.py b/tests/test_index.py index 9fabae5b..dd5add5c 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -15,7 +15,7 @@ from nw.core.index import NWIndex from nw.constants import nwItemClass, nwItemLayout @pytest.mark.project -def testIndexBuildCheck(monkeypatch, nwLipsum, nwDummy, nwTempProj, nwRef): +def testIndexBuildCheck(monkeypatch, nwLipsum, dummyGUI, nwTempProj, nwRef): """Test core functionality of scaning, saving, loading and checking the index cache file. """ @@ -23,13 +23,13 @@ def testIndexBuildCheck(monkeypatch, nwLipsum, nwDummy, nwTempProj, nwRef): testFile = os.path.join(nwTempProj, "1_tagsIndex.json") refFile = os.path.join(nwRef, "proj", "1_tagsIndex.json") - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwLipsum) monkeypatch.setattr("nw.core.index.time", lambda: 123.4) - theIndex = NWIndex(theProject, nwDummy) + theIndex = NWIndex(theProject, dummyGUI) notIndexable = { "b3643d0f92e32": False, # Novel ROOT "45e6b01ca35c1": False, # Chapter One FOLDER @@ -139,14 +139,14 @@ def testIndexBuildCheck(monkeypatch, nwLipsum, nwDummy, nwTempProj, nwRef): assert cmpFiles(testFile, refFile) @pytest.mark.project -def testIndexScanThis(nwMinimal, nwDummy): +def testIndexScanThis(nwMinimal, dummyGUI): """Test the tag scanner function scanThis. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, nwDummy) + theIndex = NWIndex(theProject, dummyGUI) isValid, theBits, thePos = theIndex.scanThis("tag: this, and this") assert not isValid @@ -188,14 +188,14 @@ def testIndexScanThis(nwMinimal, nwDummy): assert theProject.closeProject() @pytest.mark.project -def testIndexCheckThese(nwMinimal, nwDummy): +def testIndexCheckThese(nwMinimal, dummyGUI): """Test the tag checker function checkThese. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, nwDummy) + theIndex = NWIndex(theProject, dummyGUI) nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") nItem = theProject.projTree[nHandle] @@ -224,14 +224,14 @@ def testIndexCheckThese(nwMinimal, nwDummy): assert theProject.closeProject() @pytest.mark.project -def testIndexScanText(nwMinimal, nwDummy): +def testIndexScanText(nwMinimal, dummyGUI): """Check the index data extraction functions. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, nwDummy) + theIndex = NWIndex(theProject, dummyGUI) # Some items for fail to scan tests dHandle = theProject.newFolder("Folder", nwItemClass.NOVEL, "a508bb932959c") @@ -399,14 +399,14 @@ def testIndexScanText(nwMinimal, nwDummy): assert theProject.closeProject() @pytest.mark.project -def testIndexExtractData(nwMinimal, nwDummy): +def testIndexExtractData(nwMinimal, dummyGUI): """Check the index data extraction functions. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, nwDummy) + theIndex = NWIndex(theProject, dummyGUI) nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") diff --git a/tests/test_project.py b/tests/test_project.py index 5ed9d261..b8a49aa9 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -16,14 +16,14 @@ from nw.core.spellcheck import NWSpellEnchant, NWSpellSimple from nw.constants import nwConst, nwItemClass, nwItemType, nwItemLayout, nwFiles @pytest.mark.project -def testProjectNewOpenSave(nwFuncTemp, nwTempProj, nwRef, nwTemp, nwDummy): +def testProjectNewOpenSave(nwFuncTemp, nwTempProj, nwRef, tmpDir, dummyGUI): """Test that a basic project can be created, and opened and saved. """ projFile = os.path.join(nwFuncTemp, "nwProject.nwx") testFile = os.path.join(nwTempProj, "1_nwProject.nwx") refFile = os.path.join(nwRef, "proj", "1_nwProject.nwx") - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) # Setting no data should fail @@ -62,14 +62,14 @@ def testProjectNewOpenSave(nwFuncTemp, nwTempProj, nwRef, nwTemp, nwDummy): assert cmpFiles(testFile, refFile, [2, 6, 7, 8]) @pytest.mark.project -def testProjectNewRoot(nwFuncTemp, nwTempProj, nwRef, nwDummy): +def testProjectNewRoot(nwFuncTemp, nwTempProj, nwRef, dummyGUI): """Check that new root folders can be added to the project. """ projFile = os.path.join(nwFuncTemp, "nwProject.nwx") testFile = os.path.join(nwTempProj, "2_nwProject.nwx") refFile = os.path.join(nwRef, "proj", "2_nwProject.nwx") - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.newProject({"projPath": nwFuncTemp}) @@ -96,14 +96,14 @@ def testProjectNewRoot(nwFuncTemp, nwTempProj, nwRef, nwDummy): assert not theProject.projChanged @pytest.mark.project -def testProjectNewFile(nwFuncTemp, nwTempProj, nwRef, nwDummy): +def testProjectNewFile(nwFuncTemp, nwTempProj, nwRef, dummyGUI): """Check that new files can be added to the project. """ projFile = os.path.join(nwFuncTemp, "nwProject.nwx") testFile = os.path.join(nwTempProj, "3_nwProject.nwx") refFile = os.path.join(nwRef, "proj", "3_nwProject.nwx") - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.newProject({"projPath": nwFuncTemp}) @@ -123,7 +123,7 @@ def testProjectNewFile(nwFuncTemp, nwTempProj, nwRef, nwDummy): assert not theProject.projChanged @pytest.mark.project -def testProjectNewCustomA(nwFuncTemp, nwTempProj, nwRef, nwDummy): +def testProjectNewCustomA(nwFuncTemp, nwTempProj, nwRef, dummyGUI): """Create a new project from a project wizard dictionary. Custom type with chapters and scenes. """ @@ -151,7 +151,7 @@ def testProjectNewCustomA(nwFuncTemp, nwTempProj, nwRef, nwDummy): "numScenes": 3, "chFolders": True, } - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.newProject(projData) @@ -162,7 +162,7 @@ def testProjectNewCustomA(nwFuncTemp, nwTempProj, nwRef, nwDummy): assert cmpFiles(testFile, refFile, [2, 6, 7, 8]) @pytest.mark.project -def testProjectNewCustomB(nwFuncTemp, nwTempProj, nwRef, nwDummy): +def testProjectNewCustomB(nwFuncTemp, nwTempProj, nwRef, dummyGUI): """Create a new project from a project wizard dictionary. Custom type without chapters, but with scenes. """ @@ -190,7 +190,7 @@ def testProjectNewCustomB(nwFuncTemp, nwTempProj, nwRef, nwDummy): "numScenes": 6, "chFolders": True, } - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.newProject(projData) @@ -201,7 +201,7 @@ def testProjectNewCustomB(nwFuncTemp, nwTempProj, nwRef, nwDummy): assert cmpFiles(testFile, refFile, [2, 6, 7, 8]) @pytest.mark.project -def testProjectNewSampleA(nwFuncTemp, nwConf, nwDummy, nwTemp): +def testProjectNewSampleA(nwFuncTemp, nwConf, dummyGUI, tmpDir): """Check that we can create a new project can be created from the provided sample project via a zip file. """ @@ -214,7 +214,7 @@ def testProjectNewSampleA(nwFuncTemp, nwConf, nwDummy, nwTemp): "popMinimal": False, "popCustom": False, } - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) theProject.mainConf = nwConf @@ -223,8 +223,8 @@ def testProjectNewSampleA(nwFuncTemp, nwConf, nwDummy, nwTemp): # Force the lookup path for assets to our temp folder srcSample = os.path.abspath(os.path.join(nwConf.appRoot, "sample")) - dstSample = os.path.join(nwTemp, "sample.zip") - nwConf.assetPath = nwTemp + dstSample = os.path.join(tmpDir, "sample.zip") + nwConf.assetPath = tmpDir # Create and open a defective zip file with open(dstSample, mode="w+") as outFile: @@ -248,7 +248,7 @@ def testProjectNewSampleA(nwFuncTemp, nwConf, nwDummy, nwTemp): os.unlink(dstSample) @pytest.mark.project -def testProjectNewSampleB(monkeypatch, nwFuncTemp, nwConf, nwDummy, nwTemp): +def testProjectNewSampleB(monkeypatch, nwFuncTemp, nwConf, dummyGUI, tmpDir): """Check that we can create a new project can be created from the provided sample project folder. """ @@ -261,12 +261,12 @@ def testProjectNewSampleB(monkeypatch, nwFuncTemp, nwConf, nwDummy, nwTemp): "popMinimal": False, "popCustom": False, } - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) theProject.mainConf = nwConf # Make sure we do not pick up the nw/assets/sample.zip file - nwConf.assetPath = nwTemp + nwConf.assetPath = tmpDir # Set a fake project file name monkeypatch.setattr(nwFiles, "PROJ_FILE", "nothing.nwx") @@ -280,14 +280,14 @@ def testProjectNewSampleB(monkeypatch, nwFuncTemp, nwConf, nwDummy, nwTemp): assert theProject.closeProject() # Misdirect the appRoot path so neither is possible - nwConf.appRoot = nwTemp + nwConf.appRoot = tmpDir assert not theProject.newProject(projData) @pytest.mark.project -def testProjectMethods(monkeypatch, nwMinimal, nwDummy): +def testProjectMethods(monkeypatch, nwMinimal, dummyGUI): """Test other project class methods and functions. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) assert theProject.projPath == nwMinimal @@ -326,14 +326,14 @@ def testProjectMethods(monkeypatch, nwMinimal, nwDummy): assert theProject.bookAuthors == ["Jane Doe", "John Doh"] @pytest.mark.project -def testDocMeta(nwDummy, nwLipsum): +def testDocMeta(dummyGUI, nwLipsum): """Check that the document meta data string is parsed correctly. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.projTree.setSeed(42) assert theProject.openProject(nwLipsum) - aDoc = NWDoc(theProject, nwDummy) + aDoc = NWDoc(theProject, dummyGUI) assert aDoc.openDocument("47666c91c7ccf") theName, theParent, theClass, theLayout = aDoc.getMeta() @@ -350,8 +350,8 @@ def testDocMeta(nwDummy, nwLipsum): assert theLayout is None @pytest.mark.project -def testSpellEnchant(nwTemp, nwConf): - wList = os.path.join(nwTemp, "wordlist.txt") +def testSpellEnchant(tmpDir, nwConf): + wList = os.path.join(tmpDir, "wordlist.txt") with open(wList, mode="w") as wFile: wFile.write("a_word\nb_word\nc_word\n") @@ -379,8 +379,8 @@ def testSpellEnchant(nwTemp, nwConf): assert aName != "" @pytest.mark.project -def testSpellSimple(nwTemp, nwConf): - wList = os.path.join(nwTemp, "wordlist.txt") +def testSpellSimple(tmpDir, nwConf): + wList = os.path.join(tmpDir, "wordlist.txt") with open(wList, mode="w") as wFile: wFile.write("a_word\nb_word\nc_word\n") @@ -408,12 +408,12 @@ def testSpellSimple(nwTemp, nwConf): assert aName == nwConst.SP_INTERNAL @pytest.mark.project -def testProjectOptions(nwDummy, nwLipsum): +def testProjectOptions(dummyGUI, nwLipsum): """Test the class that holds all the GUI state user options that are tied to the current open project. Non-project related GUI options are handled by the Config class. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) assert theProject.projMeta is None theOpts = theProject.optState @@ -471,13 +471,13 @@ def testProjectOptions(nwDummy, nwLipsum): assert theOpts.getFloat("GuiWritingStats", "winWidth", False) is False @pytest.mark.project -def testProjectOrphanedFiles(nwDummy, nwLipsum): +def testProjectOrphanedFiles(dummyGUI, nwLipsum): """Check that files in the content folder that are not tracked in the project XML file are handled correctly by the orphaned files function. It should also restore as much meta data as possible from the meta line at the top of the document file. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) assert theProject.openProject(nwLipsum) assert theProject.projTree["636b6aa9b697b"] is None assert theProject.closeProject() @@ -540,13 +540,13 @@ def testProjectOrphanedFiles(nwDummy, nwLipsum): assert theProject.closeProject() @pytest.mark.project -def testProjectOldFormat(nwDummy, nwOldProj): +def testProjectOldFormat(dummyGUI, nwOldProj): """Test that a project folder structure of version 1.0 can be converted to the latest folder structure. Version 1.0 split the documents into 'data_0' ... 'data_f' folders, which are now all contained in a single 'content' folder. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) theProject.mainConf.showGUI = False # Create dummy files for known legacy files @@ -630,13 +630,13 @@ def testProjectOldFormat(nwDummy, nwOldProj): assert os.path.isfile(os.path.join(nwOldProj, "ToC.txt")) @pytest.mark.project -def testProjectBackup(nwDummy, nwMinimal, nwTemp): +def testProjectBackup(dummyGUI, nwMinimal, tmpDir): """Test the automated backup feature of the project class. The test creates a backup of the Minimal test project, and then unzips the backupd file and checks that the project XML file is identical to the original file. """ - theProject = NWProject(nwDummy) + theProject = NWProject(dummyGUI) assert theProject.openProject(nwMinimal) # Test faulty settings @@ -645,12 +645,12 @@ def testProjectBackup(nwDummy, nwMinimal, nwTemp): assert not theProject.zipIt(doNotify=False) # Missing project name - theProject.mainConf.backupPath = nwTemp + theProject.mainConf.backupPath = tmpDir theProject.projName = "" assert not theProject.zipIt(doNotify=False) # Non-existent folder - theProject.mainConf.backupPath = os.path.join(nwTemp, "nonexistent") + theProject.mainConf.backupPath = os.path.join(tmpDir, "nonexistent") theProject.projName = "Test Minimal" assert not theProject.zipIt(doNotify=False) @@ -659,10 +659,10 @@ def testProjectBackup(nwDummy, nwMinimal, nwTemp): assert not theProject.zipIt(doNotify=False) # Test correct settings - theProject.mainConf.backupPath = nwTemp + theProject.mainConf.backupPath = tmpDir assert theProject.zipIt(doNotify=False) - theFiles = os.listdir(os.path.join(nwTemp, "Test Minimal")) + theFiles = os.listdir(os.path.join(tmpDir, "Test Minimal")) assert len(theFiles) == 1 theZip = theFiles[0] @@ -670,10 +670,10 @@ def testProjectBackup(nwDummy, nwMinimal, nwTemp): assert theZip[-4:] == ".zip" # Extract the archive - with ZipFile(os.path.join(nwTemp, "Test Minimal", theZip), "r") as inZip: - inZip.extractall(os.path.join(nwTemp, "extract")) + with ZipFile(os.path.join(tmpDir, "Test Minimal", theZip), "r") as inZip: + inZip.extractall(os.path.join(tmpDir, "extract")) # Check that the main project file was restored assert cmpFiles( - os.path.join(nwMinimal, "nwProject.nwx"), os.path.join(nwTemp, "extract", "nwProject.nwx") + os.path.join(nwMinimal, "nwProject.nwx"), os.path.join(tmpDir, "extract", "nwProject.nwx") )