diff --git a/tests/conftest.py b/tests/conftest.py index 4d8d7183..8551724b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,6 +24,8 @@ import sys import pytest import shutil +from dataclasses import dataclass + from mock import MockGuiMain from tools import cleanProject @@ -249,9 +251,24 @@ def nwOldProj(tmpDir): ## -# Useful Fixtures +# Data Fixtures ## +@dataclass +class TestConst: + + statusKeys = ["sa3b179", "s1c8031", "s06671a", "sbdd640"] + importKeys = ["i466852", "i3eb13b", "i392456", "i23b8c1"] + + +@pytest.fixture(scope="session") +def constData(): + """A named tuple of known contstant values. For those that depend on + the random number generator, they assume the seed is 42. + """ + return TestConst() + + @pytest.fixture(scope="session") def ipsumText(): """Return five paragraphs of Lorem Ipsum text. diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index 55a582ad..8ffb64fc 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,12 +1,12 @@ - + Lorem Ipsum Lorem Ipsum lipsum.com - 23 + 24 24 - 1854 + 1856 False @@ -31,102 +31,102 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main
- Novel + Novel - Lorem Ipsum + Lorem Ipsum - Front Matter + Front Matter - Prologue + Prologue - Act One + Act One - Chapter One + Chapter One - Chapter One + Chapter One - Scene One + Scene One - Scene Two + Scene Two - Interlude + Interlude - Chapter Two + Chapter Two - Chapter Two + Chapter Two - Scene Three + Scene Three - Scene Four + Scene Four - Scene Five + Scene Five - Characters + Characters - Mr. Nobody + Mr. Nobody - Plot + Plot - Main + Main - World + World - Ancient Europe + Ancient Europe
diff --git a/tests/minimal/nwProject.nwx b/tests/minimal/nwProject.nwx index 6f45815d..9824e2bb 100644 --- a/tests/minimal/nwProject.nwx +++ b/tests/minimal/nwProject.nwx @@ -1,13 +1,13 @@ - + Test Minimal Minimal Jane Doe John Doh - 14 + 15 2 - 135 + 146 True @@ -29,50 +29,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main
- Novel + Novel - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Plot + Plot - Characters + Characters - World + World
diff --git a/tests/reference/coreProject_NewCustomA_nwProject.nwx b/tests/reference/coreProject_NewCustomA_nwProject.nwx index 10398c21..65d56307 100644 --- a/tests/reference/coreProject_NewCustomA_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -29,110 +29,110 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Plot + Plot - Characters + Characters - Locations + Locations - Timeline + Timeline - Objects + Objects - Entities + Entities - Title Page + Title Page - Chapter 1 + Chapter 1 - Chapter 1 + Chapter 1 - Scene 1.1 + Scene 1.1 - Scene 1.2 + Scene 1.2 - Scene 1.3 + Scene 1.3 - Chapter 2 + Chapter 2 - Chapter 2 + Chapter 2 - Scene 2.1 + Scene 2.1 - Scene 2.2 + Scene 2.2 - Scene 2.3 + Scene 2.3 - Chapter 3 + Chapter 3 - Chapter 3 + Chapter 3 - Scene 3.1 + Scene 3.1 - Scene 3.2 + Scene 3.2 - Scene 3.3 + Scene 3.3
diff --git a/tests/reference/coreProject_NewCustomB_nwProject.nwx b/tests/reference/coreProject_NewCustomB_nwProject.nwx index 2bb2df31..baab7a17 100644 --- a/tests/reference/coreProject_NewCustomB_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -29,74 +29,74 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Plot + Plot - Characters + Characters - Locations + Locations - Timeline + Timeline - Objects + Objects - Entities + Entities - Title Page + Title Page - Scene 1 + Scene 1 - Scene 2 + Scene 2 - Scene 3 + Scene 3 - Scene 4 + Scene 4 - Scene 5 + Scene 5 - Scene 6 + Scene 6
diff --git a/tests/reference/coreProject_NewFile_nwProject.nwx b/tests/reference/coreProject_NewFile_nwProject.nwx index d4ffb126..978f5855 100644 --- a/tests/reference/coreProject_NewFile_nwProject.nwx +++ b/tests/reference/coreProject_NewFile_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,58 +27,58 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Plot + Plot - Characters + Characters - World + World - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Hello + Hello - Jane + Jane
diff --git a/tests/reference/coreProject_NewMinimal_nwProject.nwx b/tests/reference/coreProject_NewMinimal_nwProject.nwx index 20fa4d71..fc2ad735 100644 --- a/tests/reference/coreProject_NewMinimal_nwProject.nwx +++ b/tests/reference/coreProject_NewMinimal_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,50 +27,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Plot + Plot - Characters + Characters - World + World - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene
diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 22d51fd7..94fdbeea 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,66 +27,66 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Plot + Plot - Characters + Characters - World + World - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Timeline + Timeline - Object + Object - Custom1 + Custom1 - Custom2 + Custom2
diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 685095bb..3432d06b 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,62 +27,62 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Plot + Plot - New File + New File - Characters + Characters - New File + New File - World + World - New File + New File diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx index a42552cf..e6e80636 100644 --- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,50 +27,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - Novel + Novel - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Plot + Plot - Characters + Characters - World + World
diff --git a/tests/reference/guiProjSettings_Dialog_nwProject.nwx b/tests/reference/guiProjSettings_Dialog_nwProject.nwx index c6652f72..f41ac5c8 100644 --- a/tests/reference/guiProjSettings_Dialog_nwProject.nwx +++ b/tests/reference/guiProjSettings_Dialog_nwProject.nwx @@ -1,5 +1,5 @@ - + Project Name Project Title @@ -33,50 +33,50 @@
- New - Note - Finished - Final + New + Note + Finished + Final - New - Minor - Major - Final + New + Minor + Major + Final - Novel + Novel - Title Page + Title Page - New Chapter + New Chapter - New Chapter + New Chapter - New Scene + New Scene - Plot + Plot - Characters + Characters - World + World
diff --git a/tests/test_base/test_base_common.py b/tests/test_base/test_base_common.py index f5eef8fe..d7ad4119 100644 --- a/tests/test_base/test_base_common.py +++ b/tests/test_base/test_base_common.py @@ -31,9 +31,9 @@ from novelwriter.guimain import GuiMain from novelwriter.common import ( checkString, checkInt, checkFloat, checkBool, checkHandle, isHandle, isTitleTag, isItemClass, isItemType, isItemLayout, hexToInt, checkIntRange, - checkIntTuple, formatInt, formatTimeStamp, formatTime, splitVersionNumber, - transferCase, fuzzyTime, numberToRoman, jsonEncode, readTextFile, - makeFileNameSafe, sha256sum, getGuiItem, NWConfigParser + minmax, checkIntTuple, formatInt, formatTimeStamp, formatTime, simplified, + splitVersionNumber, transferCase, fuzzyTime, numberToRoman, jsonEncode, + readTextFile, makeFileNameSafe, sha256sum, getGuiItem, NWConfigParser ) @@ -226,6 +226,16 @@ def testBaseCommon_CheckIntRange(): # END Test testBaseCommon_CheckIntRange +@pytest.mark.base +def testBaseCommon_MinMax(): + """Test the minmax function. + """ + for i in range(-5, 15): + assert 0 <= minmax(i, 0, 10) <= 10 + +# END Test testBaseCommon_MinMax + + @pytest.mark.base def testBaseCommon_CheckIntTuple(): """Test the checkIntTuple function. @@ -270,6 +280,17 @@ def testBaseCommon_FormatTime(): # END Test testBaseCommon_FormatTime +@pytest.mark.base +def testBaseCommon_Simplified(): + """Test the simplified function. + """ + assert simplified("Hello World") == "Hello World" + assert simplified(" Hello World ") == "Hello World" + assert simplified("\tHello\n\r\tWorld") == "Hello World" + +# END Test testBaseCommon_Simplified + + @pytest.mark.base def testBaseCommon_SplitVersionNumber(): """Test the splitVersionNumber function. diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index 61c67987..eb1425b3 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -20,6 +20,7 @@ along with this program. If not, see . """ import pytest +import random from lxml import etree @@ -31,9 +32,10 @@ from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout @pytest.mark.core -def testCoreItem_Setters(mockGUI): +def testCoreItem_Setters(mockGUI, constData): """Test all the simple setters for the NWItem class. """ + random.seed(42) theProject = NWProject(mockGUI) theItem = NWItem(theProject) @@ -77,50 +79,32 @@ def testCoreItem_Setters(mockGUI): # Importance theItem._class = nwItemClass.CHARACTER - theItem.setImport("Nonsense") - assert theItem.itemImport == "New" - theItem.setImport("New") - assert theItem.itemImport == "New" - theItem.setImport("Minor") - assert theItem.itemImport == "Minor" - theItem.setImport("Major") - assert theItem.itemImport == "Major" - theItem.setImport("Main") - assert theItem.itemImport == "Main" + theItem.setImport("Word") + assert theItem.itemImport == constData.importKeys[0] # Default + for key in constData.importKeys: + theItem.setImport(key) + assert theItem.itemImport == key # Status theItem._class = nwItemClass.NOVEL - theItem.setStatus("Nonsense") - assert theItem.itemStatus == "New" - theItem.setStatus("New") - assert theItem.itemStatus == "New" - theItem.setStatus("Note") - assert theItem.itemStatus == "Note" - theItem.setStatus("Draft") - assert theItem.itemStatus == "Draft" - theItem.setStatus("Finished") - assert theItem.itemStatus == "Finished" + theItem.setStatus("Word") + assert theItem.itemStatus == constData.statusKeys[0] # Default + for key in constData.statusKeys: + theItem.setStatus(key) + assert theItem.itemStatus == key # Status/Importance Wrapper theItem._class = nwItemClass.CHARACTER - theItem.setImportStatus("New") - assert theItem.itemImport == "New" - theItem.setImportStatus("Minor") - assert theItem.itemImport == "Minor" - theItem.setImportStatus("Note") - assert theItem.itemImport == "New" - theItem.setImportStatus("Draft") - assert theItem.itemImport == "New" + for key in constData.importKeys: + theItem.setImport(key) + assert theItem.itemImport == key + assert theItem.itemStatus == constData.statusKeys[3] # Should not change theItem._class = nwItemClass.NOVEL - theItem.setImportStatus("New") - assert theItem.itemStatus == "New" - theItem.setImportStatus("Minor") - assert theItem.itemStatus == "New" - theItem.setImportStatus("Note") - assert theItem.itemStatus == "Note" - theItem.setImportStatus("Draft") - assert theItem.itemStatus == "Draft" + for key in constData.statusKeys: + theItem.setStatus(key) + assert theItem.itemImport == constData.importKeys[3] # Should not change + assert theItem.itemStatus == key # Expanded theItem.setExpanded(8) @@ -354,9 +338,10 @@ def testCoreItem_LayoutSetter(mockGUI): @pytest.mark.core -def testCoreItem_XMLPackUnpack(mockGUI, caplog): +def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData): """Test packing and unpacking XML objects for the NWItem class. """ + random.seed(42) theProject = NWProject(mockGUI) nwXML = etree.Element("novelWriterXML") @@ -370,7 +355,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): theItem.setName("A Name") theItem.setClass("NOVEL") theItem.setType("FILE") - theItem.setStatus("Main") + theItem.setImport(constData.importKeys[3]) theItem.setLayout("NOTE") theItem.setExported(False) theItem.setParaCount(3) @@ -385,9 +370,9 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): b'' b'' - b'A Name' + b'A Name
' b'
' - ) + ) % bytes(constData.importKeys[3], encoding="utf8") # Unpack theItem = NWItem(theProject) @@ -403,6 +388,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): assert theItem.itemClass == nwItemClass.NOVEL assert theItem.itemType == nwItemType.FILE assert theItem.itemLayout == nwItemLayout.NOTE + assert theItem.itemStatus == constData.statusKeys[0] # Was None, should now be default + assert theItem.itemImport == constData.importKeys[3] # Folder # ====== @@ -414,7 +401,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): theItem.setName("A Name") theItem.setClass("NOVEL") theItem.setType("FOLDER") - theItem.setStatus("Main") + theItem.setStatus(constData.statusKeys[1]) theItem.setLayout("NOTE") theItem.setExpanded(True) theItem.setExported(False) @@ -429,10 +416,10 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( b'' b'A Name' + b'class="NOVEL">A Name' b'' b'' - ) + ) % bytes(constData.statusKeys[1], encoding="utf8") # Unpack theItem = NWItem(theProject) @@ -449,6 +436,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): assert theItem.itemClass == nwItemClass.NOVEL assert theItem.itemType == nwItemType.FOLDER assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + assert theItem.itemStatus == constData.statusKeys[1] + assert theItem.itemImport == constData.importKeys[0] # Was None, should now be default # Errors # ====== diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 311fca8c..b98b05f4 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -19,8 +19,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest +import random from shutil import copyfile from zipfile import ZipFile @@ -44,6 +45,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): testFile = os.path.join(outDir, "coreProject_NewMinimal_nwProject.nwx") compFile = os.path.join(refDir, "coreProject_NewMinimal_nwProject.nwx") + random.seed(42) theProject = NWProject(mockGUI) theProject.projTree.setSeed(42) @@ -112,6 +114,7 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI): "numScenes": 3, "chFolders": True, } + random.seed(42) theProject = NWProject(mockGUI) theProject.projTree.setSeed(42) @@ -154,6 +157,7 @@ def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI): "numScenes": 6, "chFolders": True, } + random.seed(42) theProject = NWProject(mockGUI) theProject.projTree.setSeed(42) @@ -262,6 +266,7 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI): testFile = os.path.join(outDir, "coreProject_NewRoot_nwProject.nwx") compFile = os.path.join(refDir, "coreProject_NewRoot_nwProject.nwx") + random.seed(42) theProject = NWProject(mockGUI) theProject.projTree.setSeed(42) @@ -299,6 +304,7 @@ def testCoreProject_NewFile(fncDir, outDir, refDir, mockGUI): testFile = os.path.join(outDir, "coreProject_NewFile_nwProject.nwx") compFile = os.path.join(refDir, "coreProject_NewFile_nwProject.nwx") + random.seed(42) theProject = NWProject(mockGUI) theProject.projTree.setSeed(42) @@ -770,9 +776,10 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): # Spell language theProject.projChanged = False - assert theProject.setSpellLang(None) assert theProject.projSpell is None - assert theProject.setSpellLang("None") + assert theProject.setSpellLang(None) is False + assert theProject.projSpell is None + assert theProject.setSpellLang("None") is False # Should be interpreded as None assert theProject.projSpell is None assert theProject.setSpellLang("en_GB") assert theProject.projSpell == "en_GB" @@ -827,55 +834,55 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): assert theProject.setTreeOrder(oldOrder) assert theProject.projTree.handles() == oldOrder - # Change status - theProject.projTree["a35baf2e93843"].setStatus("Finished") - theProject.projTree["a6d311a93600a"].setStatus("Draft") - theProject.projTree["f5ab3e30151e1"].setStatus("Note") - theProject.projTree["8c659a11cd429"].setStatus("Finished") - newList = [ - ("New", 1, 1, 1, "New"), - ("Draft", 2, 2, 2, "Note"), # These are swapped - ("Note", 3, 3, 3, "Draft"), # These are swapped - ("Edited", 4, 4, 4, "Finished"), # Renamed - ("Finished", 5, 5, 5, None), # New, with reused name - ] - assert theProject.setStatusColours(newList) - assert theProject.statusItems._theLabels == [ - "New", "Draft", "Note", "Edited", "Finished" - ] - assert theProject.statusItems._theColours == [ - (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) - ] - assert theProject.projTree["a35baf2e93843"].itemStatus == "Edited" # Renamed - assert theProject.projTree["a6d311a93600a"].itemStatus == "Note" # Swapped - assert theProject.projTree["f5ab3e30151e1"].itemStatus == "Draft" # Swapped - assert theProject.projTree["8c659a11cd429"].itemStatus == "Edited" # Renamed + # # Change status + # theProject.projTree["a35baf2e93843"].setStatus("Finished") + # theProject.projTree["a6d311a93600a"].setStatus("Draft") + # theProject.projTree["f5ab3e30151e1"].setStatus("Note") + # theProject.projTree["8c659a11cd429"].setStatus("Finished") + # newList = [ + # ("New", 1, 1, 1, "New"), + # ("Draft", 2, 2, 2, "Note"), # These are swapped + # ("Note", 3, 3, 3, "Draft"), # These are swapped + # ("Edited", 4, 4, 4, "Finished"), # Renamed + # ("Finished", 5, 5, 5, None), # New, with reused name + # ] + # assert theProject.setStatusColours(newList, []) + # assert theProject.statusItems._theLabels == [ + # "New", "Draft", "Note", "Edited", "Finished" + # ] + # assert theProject.statusItems._theColours == [ + # (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) + # ] + # assert theProject.projTree["a35baf2e93843"].itemStatus == "Edited" # Renamed + # assert theProject.projTree["a6d311a93600a"].itemStatus == "Note" # Swapped + # assert theProject.projTree["f5ab3e30151e1"].itemStatus == "Draft" # Swapped + # assert theProject.projTree["8c659a11cd429"].itemStatus == "Edited" # Renamed - # Change importance - fHandle = theProject.newFile("Jane Doe", nwItemClass.CHARACTER, "afb3043c7b2b3") - theProject.projTree[fHandle].setImport("Main") - newList = [ - ("New", 1, 1, 1, "New"), - ("Minor", 2, 2, 2, "Minor"), - ("Major", 3, 3, 3, "Major"), - ("Min", 4, 4, 4, "Main"), - ("Max", 5, 5, 5, None), - ] - assert theProject.setImportColours(newList) - assert theProject.importItems._theLabels == [ - "New", "Minor", "Major", "Min", "Max" - ] - assert theProject.importItems._theColours == [ - (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) - ] - assert theProject.projTree[fHandle].itemImport == "Min" + # # Change importance + # fHandle = theProject.newFile("Jane Doe", nwItemClass.CHARACTER, "afb3043c7b2b3") + # theProject.projTree[fHandle].setImport("Main") + # newList = [ + # ("New", 1, 1, 1, "New"), + # ("Minor", 2, 2, 2, "Minor"), + # ("Major", 3, 3, 3, "Major"), + # ("Min", 4, 4, 4, "Main"), + # ("Max", 5, 5, 5, None), + # ] + # assert theProject.setImportColours(newList) + # assert theProject.importItems._theLabels == [ + # "New", "Minor", "Major", "Min", "Max" + # ] + # assert theProject.importItems._theColours == [ + # (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) + # ] + # assert theProject.projTree[fHandle].itemImport == "Min" - # Check status counts - assert theProject.statusItems._theCounts == [0, 0, 0, 0, 0] - assert theProject.importItems._theCounts == [0, 0, 0, 0, 0] - theProject.countStatus() - assert theProject.statusItems._theCounts == [1, 1, 1, 2, 0] - assert theProject.importItems._theCounts == [3, 0, 0, 1, 0] + # # Check status counts + # assert theProject.statusItems._theCounts == [0, 0, 0, 0, 0] + # assert theProject.importItems._theCounts == [0, 0, 0, 0, 0] + # theProject.countStatus() + # assert theProject.statusItems._theCounts == [1, 1, 1, 2, 0] + # assert theProject.importItems._theCounts == [3, 0, 0, 1, 0] # Session stats theProject.currWCount = 200 diff --git a/tests/test_dialogs/test_dlg_itemeditor.py b/tests/test_dialogs/test_dlg_itemeditor.py index 79038345..10d72549 100644 --- a/tests/test_dialogs/test_dlg_itemeditor.py +++ b/tests/test_dialogs/test_dlg_itemeditor.py @@ -20,6 +20,7 @@ along with this program. If not, see . """ import pytest +import random from tools import getGuiItem @@ -88,7 +89,7 @@ def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj): @pytest.mark.gui -def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): +def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj, constData): """Test the item editor dialog for a novel document. """ # Block message box @@ -96,9 +97,13 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) # Create Project and Open Document + random.seed(42) nwGUI.theProject.projTree.setSeed(42) assert nwGUI.newProject({"projPath": fncProj}) - assert nwGUI.openDocument("0e17daca5f3e1") + assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New" + assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note" + + assert nwGUI.openDocument("0e17daca5f3e1") is True # Check that an invalid handle is managed itemEdit = GuiItemEditor(nwGUI, "whatever") @@ -111,7 +116,7 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): # Check Existing Settings assert itemEdit.editName.text() == "New Scene" - assert itemEdit.editStatus.currentData() == "New" + assert itemEdit.editStatus.currentData() == constData.statusKeys[0] assert itemEdit.editLayout.currentData() == nwItemLayout.DOCUMENT assert itemEdit.editExport.isChecked() is True @@ -125,7 +130,7 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): # Check New Settings itemEdit._doSave() assert itemEdit.theItem.itemName == "Great Scene" - assert itemEdit.theItem.itemStatus == "Note" + assert itemEdit.theItem.itemStatus == constData.statusKeys[1] assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE assert itemEdit.theItem.isExported is False @@ -141,7 +146,7 @@ def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): @pytest.mark.gui -def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): +def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, constData): """Test the item editor dialog for a project note. """ # Block message box @@ -149,8 +154,13 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) # Create Project and Open Document + random.seed(42) nwGUI.theProject.projTree.setSeed(42) assert nwGUI.newProject({"projPath": fncProj}) + assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New" + assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note" + assert nwGUI.theProject.importItems.name(constData.importKeys[0]) == "New" + assert nwGUI.theProject.importItems.name(constData.importKeys[1]) == "Minor" # Create Note nwGUI.treeView.clearSelection() @@ -166,7 +176,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): # Check Existing Settings assert itemEdit.editName.text() == "New File" - assert itemEdit.editStatus.currentData() == "New" + assert itemEdit.editStatus.currentData() == constData.importKeys[0] assert itemEdit.editLayout.currentData() == nwItemLayout.NOTE assert itemEdit.editExport.isChecked() is True @@ -178,8 +188,8 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): # Check New Settings assert itemEdit.theItem.itemName == "New Character" - assert itemEdit.theItem.itemStatus == "New" - assert itemEdit.theItem.itemImport == "Minor" + assert itemEdit.theItem.itemStatus == constData.statusKeys[0] + assert itemEdit.theItem.itemImport == constData.importKeys[1] assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE assert itemEdit.theItem.isExported is False @@ -191,7 +201,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): @pytest.mark.gui -def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj): +def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj, constData): """Test the item editor dialog for a folder. """ # Block message box @@ -199,6 +209,7 @@ def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj): monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) # Create Project and Open Document + random.seed(42) nwGUI.theProject.projTree.setSeed(42) assert nwGUI.newProject({"projPath": fncProj}) @@ -206,9 +217,12 @@ def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj): itemEdit = GuiItemEditor(nwGUI, "31489056e0916") itemEdit.show() + assert nwGUI.theProject.statusItems.name(constData.statusKeys[0]) == "New" + assert nwGUI.theProject.statusItems.name(constData.statusKeys[1]) == "Note" + # Check Existing Settings assert itemEdit.editName.text() == "New Chapter" - assert itemEdit.editStatus.currentData() == "New" + assert itemEdit.editStatus.currentData() == constData.statusKeys[0] assert itemEdit.editLayout.currentData() == nwItemLayout.NO_LAYOUT assert itemEdit.editExport.isChecked() is False @@ -222,7 +236,7 @@ def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj): # Check New Settings itemEdit._doSave() assert itemEdit.theItem.itemName == "Chapter One" - assert itemEdit.theItem.itemStatus == "Note" + assert itemEdit.theItem.itemStatus == constData.statusKeys[1] assert itemEdit.theItem.itemLayout == nwItemLayout.NO_LAYOUT assert itemEdit.theItem.isExported is False diff --git a/tests/test_dialogs/test_dlg_projload.py b/tests/test_dialogs/test_dlg_projload.py index 195ca26b..6edb7a0d 100644 --- a/tests/test_dialogs/test_dlg_projload.py +++ b/tests/test_dialogs/test_dlg_projload.py @@ -42,7 +42,8 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal): """Test the load project wizard. """ # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) assert nwGUI.openProject(nwMinimal) assert nwGUI.closeProject() diff --git a/tests/test_dialogs/test_dlg_projsettings.py b/tests/test_dialogs/test_dlg_projsettings.py index ec316bea..f2aa8319 100644 --- a/tests/test_dialogs/test_dlg_projsettings.py +++ b/tests/test_dialogs/test_dlg_projsettings.py @@ -19,8 +19,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest +import random from shutil import copyfile from tools import cmpFiles, getGuiItem @@ -39,7 +40,9 @@ stepDelay = 20 @pytest.mark.gui -def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir): +def testDlgProjSettings_Dialog( + qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir, constData +): """Test the full project settings dialog. """ projFile = os.path.join(fncProj, "nwProject.nwx") @@ -55,6 +58,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi assert getGuiItem("GuiProjectSettings") is None # Create new project + random.seed(42) nwGUI.theProject.projTree.setSeed(42) assert nwGUI.newProject({"projPath": fncProj}) nwGUI.mainConf.backupPath = fncDir @@ -111,7 +115,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi projEdit._tabBox.setCurrentWidget(projEdit.tabStatus) assert projEdit.tabStatus.colChanged is False - assert projEdit.tabStatus.getNewList() is None + assert projEdit.tabStatus.getNewList() == ([], []) assert projEdit.tabStatus.listBox.topLevelItemCount() == 4 # Fake drag'n'drop should change changed status @@ -150,12 +154,29 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi qtbot.wait(stepDelay) assert projEdit.tabStatus.colChanged is True - assert projEdit.tabStatus.getNewList() == [ - ("New", 100, 100, 100, "New"), - ("Note", 200, 50, 0, "Note"), - ("Finished", 50, 200, 0, "Finished"), - ("Final", 20, 30, 40, None) - ] + assert projEdit.tabStatus.getNewList() == ( + [ + { + "key": constData.statusKeys[0], + "name": "New", + "cols": (100, 100, 100) + }, { + "key": constData.statusKeys[1], + "name": "Note", + "cols": (200, 50, 0) + }, { + "key": constData.statusKeys[3], + "name": "Finished", + "cols": (50, 200, 0) + }, { + "key": None, + "name": "Final", + "cols": (20, 30, 40) + } + ], [ + constData.statusKeys[2] # Deleted item + ] + ) # Importance Tab # ============== diff --git a/tests/test_dialogs/test_dlg_wordlist.py b/tests/test_dialogs/test_dlg_wordlist.py index 3ca5a0ee..d9993d4d 100644 --- a/tests/test_dialogs/test_dlg_wordlist.py +++ b/tests/test_dialogs/test_dlg_wordlist.py @@ -40,6 +40,7 @@ stepDelay = 20 def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal): """test the word list editor. """ + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None) diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 8057ca41..eaa1d2ba 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -43,6 +43,7 @@ def testGuiEditor_Init(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) # Open project assert nwGUI.openProject(nwMinimal) diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 34cfaffa..fb36b3e2 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -19,8 +19,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import random +import pytest from shutil import copyfile from tools import cmpFiles @@ -139,6 +140,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True) # Create new, save, close project + random.seed(42) nwGUI.theProject.projTree.setSeed(42) assert nwGUI.newProject({"projPath": fncProj}) assert nwGUI.saveProject() diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index 6adac08e..da7fc414 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -35,6 +35,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): """Test the theme and icon classes. """ # Block message box + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)