Remove the old project wizard

This commit is contained in:
Veronica Berglyd Olsen
2023-12-20 22:00:52 +01:00
parent 41b7495a06
commit 8b6691c056
8 changed files with 6 additions and 907 deletions
-42
View File
@@ -297,48 +297,6 @@ def testCoreStorage_ZipIt(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd):
# END Test testCoreStorage_ZipIt
# @pytest.mark.core
# def testCoreStorage_PrepareStorage(monkeypatch, fncPath):
# """Test the project path preparation functions."""
# storage = NWStorage(MockProject()) # type: ignore
# assert storage.isOpen() is False
# # No path set
# assert storage._prepareStorage() is False
# # Set path to home
# storage._runtimePath = fncPath
# with monkeypatch.context() as mp:
# mp.setattr("pathlib.Path.home", lambda: fncPath)
# assert storage._prepareStorage() is False
# # Fail on mkdir
# storage._runtimePath = fncPath
# with monkeypatch.context() as mp:
# mp.setattr("pathlib.Path.mkdir", causeOSError)
# assert storage._prepareStorage() is False
# # Set up the folder
# storage._runtimePath = fncPath
# assert storage._prepareStorage(checkLegacy=False) is True
# assert (fncPath / "content").exists()
# assert (fncPath / "meta").exists()
# assert not (fncPath / "cache").exists() # Removed in 2.1b1
# # Add a legacy folder
# storage._runtimePath = fncPath
# dataDir = fncPath / "data_0"
# dataDir.mkdir()
# assert storage._prepareStorage(checkLegacy=True) is True
# assert not dataDir.exists()
# # We cannot add a new project here
# storage._runtimePath = fncPath
# assert storage._prepareStorage(checkLegacy=False, newProject=True) is False
# # END Test testCoreStorage_PrepareStorage
@pytest.mark.core
def testCoreStorage_LegacyDataFolder(monkeypatch, fncPath):
"""Test project file format 1.0 folder structure conversion."""
+2 -40
View File
@@ -26,16 +26,15 @@ import pytest
from shutil import copyfile
from tools import (
C, NWD_IGNORE, cmpFiles, buildTestProject, XML_IGNORE, getGuiItem, writeFile
C, NWD_IGNORE, cmpFiles, buildTestProject, XML_IGNORE, getGuiItem
)
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QInputDialog
from PyQt5.QtWidgets import QDialog, QMenu, QInputDialog
from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwItemType, nwView, nwWidget
from novelwriter.constants import nwFiles
from novelwriter.gui.outline import GuiOutlineView
from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.gui.doceditor import GuiDocEditor
@@ -43,7 +42,6 @@ from novelwriter.gui.noveltree import GuiNovelView
from novelwriter.dialogs.about import GuiAbout
from novelwriter.dialogs.projload import GuiProjectLoad
from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.tools.projwizard import GuiProjectWizard
KEY_DELAY = 1
@@ -114,42 +112,6 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
# END Test testGuiMain_Launch
@pytest.mark.gui
def testGuiMain_NewProject(monkeypatch, nwGUI, projPath):
"""Test creating a new project."""
# Open wizard, but return no data
with monkeypatch.context() as mp:
mp.setattr(GuiProjectWizard, "exec_", lambda *a: None)
assert nwGUI.newProject(projData=None) is False
# Close project
with monkeypatch.context() as mp:
SHARED.project._valid = True
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
assert nwGUI.newProject(projData={"projPath": projPath}) is False
SHARED.project._valid = False
# No project path
assert nwGUI.newProject(projData={}) is False
# Project file already exists
projFile = projPath / nwFiles.PROJ_FILE
writeFile(projFile, "Stuff")
assert nwGUI.newProject(projData={"projPath": projPath}) is False
projFile.unlink()
# An unreachable path should also fail
stuffPath = projPath / "stuff" / "stuff" / "stuff"
assert nwGUI.newProject(projData={"projPath": stuffPath}) is False
# This one should work just fine
assert nwGUI.newProject(projData={"projPath": projPath}) is True
assert (projPath / nwFiles.PROJ_FILE).is_file()
assert (projPath / "content").is_dir()
# END Test testGuiMain_NewProject
@pytest.mark.gui
def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
"""Test handling of project tree items based on GUI focus states."""
-249
View File
@@ -1,249 +0,0 @@
"""
novelWriter New Project Wizard Class Tester
=============================================
This file is a part of novelWriter
Copyright 20182023, Veronica Berglyd Olsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
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 __future__ import annotations
import sys
import pytest
from tools import buildTestProject, getGuiItem
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QFileDialog, QWizard, QDialog
from novelwriter.enum import nwItemClass
from novelwriter.tools.projwizard import (
GuiProjectWizard, ProjWizardIntroPage, ProjWizardFolderPage,
ProjWizardPopulatePage, ProjWizardCustomPage, ProjWizardFinalPage
)
@pytest.mark.gui
@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin")
def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, projPath):
"""Test the launch of the project wizard.
Disabled for macOS because the test segfaults on QWizard.show()
"""
# Test New Project Function
# ========================
# New with a project open should cause an error
buildTestProject(nwGUI, projPath)
with monkeypatch.context() as mp:
mp.setattr(nwGUI, "closeProject", lambda *a: False)
assert nwGUI.newProject() is False
# Close project, but call with invalid path
assert nwGUI.closeProject()
with monkeypatch.context() as mp:
mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: None)
assert nwGUI.newProject() is False
# Now, with an empty dictionary
mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {})
assert nwGUI.newProject() is False
# Now, with a non-empty folder
mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": projPath})
assert nwGUI.newProject() is False
# Test the Wizard Launching
# =========================
monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None)
result = nwGUI.showNewProjectDialog()
qtbot.waitUntil(lambda: getGuiItem("GuiProjectWizard") is not None, timeout=1000)
nwWiz = getGuiItem("GuiProjectWizard")
assert isinstance(nwWiz, GuiProjectWizard)
nwWiz.show()
qtbot.mouseClick(nwWiz.button(QWizard.CancelButton), Qt.LeftButton)
assert result is None
with monkeypatch.context() as mp:
mp.setattr(GuiProjectWizard, "result", lambda *a: QDialog.Accepted)
result = nwGUI.showNewProjectDialog()
nwWiz.button(QWizard.CancelButton).click()
assert isinstance(result, dict)
nwWiz.reject()
nwWiz.close()
# qtbot.stop()
# END Test testToolProjectWizard_Handling
@pytest.mark.gui
@pytest.mark.parametrize("prjType", ["minimal", "custom1", "custom2", "sample"])
@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin")
def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncPath, prjType):
"""Test the new project wizard with a set of selection scenarios.
"""
monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None)
nwWiz = GuiProjectWizard(nwGUI)
nwWiz.show()
qtbot.addWidget(nwWiz)
# Intro Page
# ==========
introPage = nwWiz.currentPage()
assert isinstance(introPage, ProjWizardIntroPage)
assert not nwWiz.button(QWizard.NextButton).isEnabled()
introPage.projName.setText("Test Wizard")
introPage.projTitle.setText("My Novel")
introPage.projAuthor.setText("Jane Doe")
# Setting projName should activate the button
assert nwWiz.button(QWizard.NextButton).isEnabled()
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
# Folder Page
# ===========
storagePage = nwWiz.currentPage()
assert isinstance(storagePage, ProjWizardFolderPage)
assert not nwWiz.button(QWizard.NextButton).isEnabled()
assert storagePage.errLabel.text() == ""
# Set an invalid path
storagePage.projPath.setText(str(fncPath / "not" / "a" / "path"))
assert not nwWiz.button(QWizard.NextButton).isEnabled()
assert storagePage.errLabel.text().startswith("Error")
# Set an existing path
storagePage.projPath.setText(str(fncPath))
assert not nwWiz.button(QWizard.NextButton).isEnabled()
assert storagePage.errLabel.text().startswith("Error")
# Return a non-result from browse
with monkeypatch.context() as mp:
mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: "")
qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100)
assert storagePage.errLabel.text() == ""
# Let the browse feature handle it
projPath = fncPath / "Test Wizard"
with monkeypatch.context() as mp:
mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: str(fncPath))
qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100)
assert storagePage.projPath.text() == str(projPath)
assert storagePage.errLabel.text() == ""
# Setting projPath should activate the button
assert nwWiz.button(QWizard.NextButton).isEnabled()
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
# Populate Page
# =============
popPage = nwWiz.currentPage()
assert isinstance(popPage, ProjWizardPopulatePage)
assert nwWiz.button(QWizard.NextButton).isEnabled()
if prjType.startswith("minimal"):
popPage.popMinimal.setChecked(True)
elif prjType.startswith("custom"):
popPage.popCustom.setChecked(True)
elif prjType.startswith("sample"):
popPage.popSample.setChecked(True)
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
# Custom Page
# ===========
if prjType.startswith("custom"):
customPage = nwWiz.currentPage()
assert isinstance(customPage, ProjWizardCustomPage)
assert nwWiz.button(QWizard.NextButton).isEnabled()
# Make sure the fourth option is also turned off
customPage.addPlot.setChecked(False)
customPage.addChar.setChecked(False)
customPage.addWorld.setChecked(False)
customPage._syncSwitches()
assert not customPage.addNotes.isChecked()
# Switch everything back on again
customPage.addPlot.setChecked(True)
customPage.addChar.setChecked(True)
customPage.addWorld.setChecked(True)
customPage.addNotes.setChecked(True)
if prjType == "custom2":
customPage.numChapters.setValue(0)
customPage.numScenes.setValue(10)
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
# Final Page
# ==========
finalPage = nwWiz.currentPage()
assert isinstance(finalPage, ProjWizardFinalPage)
assert nwWiz.button(QWizard.FinishButton).isEnabled() # But we don't click it
# Check Data
# ==========
projData = nwGUI._assembleProjectWizardData(nwWiz)
assert projData["projName"] == "Test Wizard"
assert projData["projTitle"] == "My Novel"
assert projData["projAuthor"] == "Jane Doe"
assert projData["projPath"] == str(projPath)
assert projData["popMinimal"] == prjType.startswith("minimal")
assert projData["popCustom"] == prjType.startswith("custom")
assert projData["popSample"] == prjType.startswith("sample")
if prjType.startswith("custom"):
assert projData["addRoots"] == [
nwItemClass.PLOT,
nwItemClass.CHARACTER,
nwItemClass.WORLD,
]
if prjType == "custom1":
assert projData["numChapters"] == 5
assert projData["numScenes"] == 5
assert projData["addNotes"] is True
else:
assert projData["numChapters"] == 0
assert projData["numScenes"] == 10
assert projData["addNotes"] is True
else:
assert projData["addRoots"] == []
assert projData["numChapters"] == 0
assert projData["numScenes"] == 0
assert projData["addNotes"] is False
# Cleanup
nwWiz.reject()
nwWiz.close()
# qtbot.stop()
# END Test testToolProjectWizard_Run