From d274c418d141d51e1cbb45248c39963ce79dca77 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 5 Dec 2020 21:08:42 +0100 Subject: [PATCH] Remove nwFuncTemp fixture --- tests/conftest.py | 14 ------------- tests/test_dialogs.py | 40 ++++++++++++++++++------------------- tests/test_error.py | 4 ++-- tests/test_gui.py | 46 +++++++++++++++++++++---------------------- 4 files changed, 45 insertions(+), 59 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1f7b88ae..5195b841 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -198,17 +198,3 @@ def nwTempBuild(tmpDir): if not os.path.isdir(buildDir): os.mkdir(buildDir) return buildDir - -@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 diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index b8e3b276..96f64da4 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -30,7 +30,7 @@ typeDelay = 1 stepDelay = 20 @pytest.mark.gui -def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): +def testProjectSettings(qtbot, monkeypatch, yesToAll, fncDir, nwTempGUI, refDir, tmpDir): nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() @@ -43,8 +43,8 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, ref # Create new project nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": nwFuncTemp}) - nwGUI.mainConf.backupPath = nwFuncTemp + assert nwGUI.newProject({"projPath": fncDir}) + nwGUI.mainConf.backupPath = fncDir # Get the dialog object monkeypatch.setattr(GuiProjectSettings, "exec_", lambda *args: None) @@ -135,7 +135,7 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, ref qtbot.wait(stepDelay) # Check the files - projFile = os.path.join(nwFuncTemp, "nwProject.nwx") + projFile = os.path.join(fncDir, "nwProject.nwx") testFile = os.path.join(nwTempGUI, "2_nwProject.nwx") refFile = os.path.join(refDir, "gui", "2_nwProject.nwx") copyfile(projFile, testFile) @@ -145,7 +145,7 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, ref nwGUI.closeMain() @pytest.mark.gui -def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, refDir, tmpDir): +def testItemEditor(qtbot, yesToAll, monkeypatch, fncDir, nwTempGUI, refDir, tmpDir): nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() @@ -154,7 +154,7 @@ def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, refDir, # Create new, save, open project nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": nwFuncTemp}) + assert nwGUI.newProject({"projPath": fncDir}) assert nwGUI.openDocument("0e17daca5f3e1") assert nwGUI.treeView.setSelectedHandle("0e17daca5f3e1", doScroll=True) @@ -208,7 +208,7 @@ def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, refDir, qtbot.wait(stepDelay) # Check the files - projFile = os.path.join(nwFuncTemp, "nwProject.nwx") + projFile = os.path.join(fncDir, "nwProject.nwx") testFile = os.path.join(nwTempGUI, "3_nwProject.nwx") refFile = os.path.join(refDir, "gui", "3_nwProject.nwx") copyfile(projFile, testFile) @@ -218,7 +218,7 @@ def testItemEditor(qtbot, yesToAll, monkeypatch, nwFuncTemp, nwTempGUI, refDir, nwGUI.closeMain() @pytest.mark.gui -def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): +def testWritingStatsExport(qtbot, monkeypatch, yesToAll, fncDir, tmpDir): nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() @@ -227,13 +227,13 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): # Create new, save, close project nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": nwFuncTemp}) + assert nwGUI.newProject({"projPath": fncDir}) qtbot.wait(200) assert nwGUI.saveProject() assert nwGUI.closeProject() qtbot.wait(stepDelay) - sessFile = os.path.join(nwFuncTemp, "meta", nwFiles.SESS_STATS) + sessFile = os.path.join(fncDir, "meta", nwFiles.SESS_STATS) with open(sessFile, mode="w+", encoding="utf-8") as outFile: outFile.write( "# Start Time End Time Novel Notes\n" @@ -244,10 +244,10 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): ) # Open again, and check the stats - assert nwGUI.openProject(nwFuncTemp) + assert nwGUI.openProject(fncDir) qtbot.wait(stepDelay) - nwGUI.mainConf.lastPath = nwFuncTemp + nwGUI.mainConf.lastPath = fncDir nwGUI.mainMenu.aWritingStats.activate(QAction.Trigger) qtbot.waitUntil(lambda: getGuiItem("GuiWritingStats") is not None, timeout=1000) @@ -264,7 +264,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(100) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.load(inFile) @@ -282,7 +282,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(stepDelay) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.loads(inFile.read()) @@ -299,7 +299,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(stepDelay) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.load(inFile) @@ -316,7 +316,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(stepDelay) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.load(inFile) @@ -329,7 +329,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(stepDelay) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.load(inFile) @@ -341,7 +341,7 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): assert sessLog._saveData(sessLog.FMT_JSON) qtbot.wait(stepDelay) - jsonStats = os.path.join(nwFuncTemp, "sessionStats.json") + jsonStats = os.path.join(fncDir, "sessionStats.json") with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.load(inFile) @@ -357,8 +357,8 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, tmpDir): nwGUI.closeMain() @pytest.mark.gui -def testAboutBox(qtbot, monkeypatch, nwFuncTemp, tmpDir): - nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir]) +def testAboutBox(qtbot, monkeypatch, fncDir, tmpDir): + nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) diff --git a/tests/test_error.py b/tests/test_error.py index 7ad07269..192fb6cb 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, tmpDir): +def testErrorDialog(qtbot, fncDir, tmpDir): qApp.closeAllWindows() - nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir]) + nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) diff --git a/tests/test_gui.py b/tests/test_gui.py index a6438d0a..a10c0582 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, tmpDir): +def testLaunch(qtbot, monkeypatch, fncDir, tmpDir): # Defaults nwGUI = nw.main( - ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir, "--style=Fusion"] + ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir, "--style=Fusion"] ) assert nw.logger.getEffectiveLevel() == logging.WARNING nwGUI.closeMain() @@ -39,21 +39,21 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): # Log Levels nwGUI = nw.main( - ["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--info", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == logging.INFO nwGUI.closeMain() nwGUI.close() nwGUI = nw.main( - ["--testmode", "--debug", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--debug", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == logging.DEBUG nwGUI.closeMain() nwGUI.close() nwGUI = nw.main( - ["--testmode", "--verbose", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--verbose", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) assert nw.logger.getEffectiveLevel() == 5 nwGUI.closeMain() @@ -62,7 +62,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): # Help and Version with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--help", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -70,7 +70,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--version", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--version", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -79,7 +79,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): # Invalid options with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--invalid", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -92,7 +92,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): monkeypatch.setattr("nw.CONFIG.verPyQtValue", 50000) with pytest.raises(SystemExit) as ex: nwGUI = nw.main( - ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % tmpDir] + ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir] ) nwGUI.closeMain() nwGUI.close() @@ -103,7 +103,7 @@ def testLaunch(qtbot, monkeypatch, nwFuncTemp, tmpDir): monkeypatch.undo() @pytest.mark.gui -def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): +def testDocEditor(qtbot, yesToAll, fncDir, nwTempGUI, refDir, tmpDir): nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) @@ -113,7 +113,7 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): # Create new, save, close project nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": nwFuncTemp}) + assert nwGUI.newProject({"projPath": fncDir}) assert nwGUI.saveProject() assert nwGUI.closeProject() @@ -130,7 +130,7 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): assert not nwGUI.theProject.spellCheck # Check the files - projFile = os.path.join(nwFuncTemp, "nwProject.nwx") + projFile = os.path.join(fncDir, "nwProject.nwx") testFile = os.path.join(nwTempGUI, "0_nwProject.nwx") refFile = os.path.join(refDir, "gui", "0_nwProject.nwx") copyfile(projFile, testFile) @@ -140,7 +140,7 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): # qtbot.stopForInteraction() # Re-open project - assert nwGUI.openProject(nwFuncTemp) + assert nwGUI.openProject(fncDir) qtbot.wait(stepDelay) # Check that we loaded the data @@ -148,8 +148,8 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): assert len(nwGUI.theProject.projTree._treeOrder) == 8 assert len(nwGUI.theProject.projTree._treeRoots) == 4 assert nwGUI.theProject.projTree.trashRoot() is None - assert nwGUI.theProject.projPath == nwFuncTemp - assert nwGUI.theProject.projMeta == os.path.join(nwFuncTemp, "meta") + assert nwGUI.theProject.projPath == fncDir + assert nwGUI.theProject.projMeta == os.path.join(fncDir, "meta") assert nwGUI.theProject.projFile == "nwProject.nwx" assert nwGUI.theProject.projName == "New Project" assert nwGUI.theProject.bookTitle == "" @@ -379,31 +379,31 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, refDir, tmpDir): assert nwGUI.saveProject() # Check the files - projFile = os.path.join(nwFuncTemp, "nwProject.nwx") + projFile = os.path.join(fncDir, "nwProject.nwx") testFile = os.path.join(nwTempGUI, "1_nwProject.nwx") refFile = os.path.join(refDir, "gui", "1_nwProject.nwx") copyfile(projFile, testFile) assert cmpFiles(testFile, refFile, [2, 6, 7, 8]) - projFile = os.path.join(nwFuncTemp, "content", "031b4af5197ec.nwd") + projFile = os.path.join(fncDir, "content", "031b4af5197ec.nwd") testFile = os.path.join(nwTempGUI, "1_031b4af5197ec.nwd") refFile = os.path.join(refDir, "gui", "1_031b4af5197ec.nwd") copyfile(projFile, testFile) assert cmpFiles(testFile, refFile) - projFile = os.path.join(nwFuncTemp, "content", "1a6562590ef19.nwd") + projFile = os.path.join(fncDir, "content", "1a6562590ef19.nwd") testFile = os.path.join(nwTempGUI, "1_1a6562590ef19.nwd") refFile = os.path.join(refDir, "gui", "1_1a6562590ef19.nwd") copyfile(projFile, testFile) assert cmpFiles(testFile, refFile) - projFile = os.path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd") + projFile = os.path.join(fncDir, "content", "0e17daca5f3e1.nwd") testFile = os.path.join(nwTempGUI, "1_0e17daca5f3e1.nwd") refFile = os.path.join(refDir, "gui", "1_0e17daca5f3e1.nwd") copyfile(projFile, testFile) assert cmpFiles(testFile, refFile) - projFile = os.path.join(nwFuncTemp, "content", "41cfc0d1f2d12.nwd") + projFile = os.path.join(fncDir, "content", "41cfc0d1f2d12.nwd") testFile = os.path.join(nwTempGUI, "1_41cfc0d1f2d12.nwd") refFile = os.path.join(refDir, "gui", "1_41cfc0d1f2d12.nwd") copyfile(projFile, testFile) @@ -1013,7 +1013,7 @@ def testContextMenu(qtbot, yesToAll, nwLipsum, tmpDir): nwGUI.close() @pytest.mark.gui -def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, tmpDir): +def testInsertMenu(qtbot, monkeypatch, fncDir, tmpDir): nwGUI = nw.main(["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() @@ -1021,7 +1021,7 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, tmpDir): qtbot.wait(stepDelay) nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": nwFuncTemp}) + assert nwGUI.newProject({"projPath": fncDir}) assert nwGUI.treeView._getTreeItem("0e17daca5f3e1") is not None @@ -1205,7 +1205,7 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, tmpDir): assert len(theBits) == 3 assert theBits[0] == "File details for the currently open file" assert theBits[1] == "Handle: 0e17daca5f3e1" - assert theBits[2] == "Location: %s" % os.path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd") + assert theBits[2] == "Location: %s" % os.path.join(fncDir, "content", "0e17daca5f3e1.nwd") # qtbot.stopForInteraction() nwGUI.closeMain()