From 26f7bb4b324b2916ea0d3bd73f37deb9cef45d29 Mon Sep 17 00:00:00 2001
From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com>
Date: Mon, 7 Nov 2022 22:46:30 +0100
Subject: [PATCH] Change how spel checking and booleans in general are saved in
the XML
---
novelwriter/common.py | 11 +-
novelwriter/core/item.py | 6 +-
novelwriter/core/projectxml.py | 23 ++--
sample/nwProject.nwx | 103 +++++++++---------
tests/files/nwProject-1.5.nwx | 101 +++++++++--------
tests/lipsum/nwProject.nwx | 83 +++++++-------
.../coreProject_NewFileFolder_nwProject.nwx | 43 ++++----
.../coreProject_NewRoot_nwProject.nwx | 49 ++++-----
.../coreTools_NewCustomA_nwProject.nwx | 85 +++++++--------
.../coreTools_NewCustomB_nwProject.nwx | 61 +++++------
.../coreTools_NewMinimal_nwProject.nwx | 31 +++---
.../guiEditor_Main_Final_nwProject.nwx | 45 ++++----
.../guiEditor_Main_Initial_nwProject.nwx | 31 +++---
tests/reference/projectXML_ReadLegacy10.nwx | 83 +++++++-------
tests/reference/projectXML_ReadLegacy11.nwx | 83 +++++++-------
tests/reference/projectXML_ReadLegacy12.nwx | 91 ++++++++--------
tests/reference/projectXML_ReadLegacy13.nwx | 91 ++++++++--------
tests/reference/projectXML_ReadLegacy14.nwx | 99 +++++++++--------
tests/test_base/test_base_common.py | 67 ++++++++++--
tests/test_core/test_core_item.py | 8 +-
20 files changed, 622 insertions(+), 572 deletions(-)
diff --git a/novelwriter/common.py b/novelwriter/common.py
index 5a84302d..7eb1ec59 100644
--- a/novelwriter/common.py
+++ b/novelwriter/common.py
@@ -88,9 +88,10 @@ def checkBool(value, default):
if isinstance(value, bool):
return value
elif isinstance(value, str):
- if value == "True":
+ check = value.lower()
+ if check in ("true", "yes", "on"):
return True
- elif value == "False":
+ elif check in ("false", "no", "off"):
return False
else:
return default
@@ -259,6 +260,12 @@ def simplified(string):
return " ".join(str(string).strip().split())
+def yesNo(value):
+ """Convert a boolean evaluated variable to a yes or no.
+ """
+ return "yes" if value else "no"
+
+
def splitVersionNumber(value):
"""Split a version string on the form aa.bb.cc into major, minor
and patch, and computes an integer value aabbcc.
diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py
index 7b6530e0..9f472dab 100644
--- a/novelwriter/core/item.py
+++ b/novelwriter/core/item.py
@@ -27,7 +27,7 @@ import logging
from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout
from novelwriter.common import (
- checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified
+ checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified, yesNo
)
from novelwriter.constants import nwHeaders, nwLabels, trConst
@@ -162,7 +162,7 @@ class NWItem:
item["order"] = str(self._order)
item["type"] = str(self._type.name)
item["class"] = str(self._class.name)
- meta["expanded"] = str(self._expanded)
+ meta["expanded"] = yesNo(self._expanded)
name["status"] = str(self._status)
name["import"] = str(self._import)
@@ -173,7 +173,7 @@ class NWItem:
meta["wordCount"] = str(self._wordCount)
meta["paraCount"] = str(self._paraCount)
meta["cursorPos"] = str(self._cursorPos)
- name["active"] = str(self._active)
+ name["active"] = yesNo(self._active)
data = {
"name": str(self._name),
diff --git a/novelwriter/core/projectxml.py b/novelwriter/core/projectxml.py
index 618fb30a..cf78a587 100644
--- a/novelwriter/core/projectxml.py
+++ b/novelwriter/core/projectxml.py
@@ -33,7 +33,8 @@ from time import time
from pathlib import Path
from novelwriter.common import (
- checkBool, checkInt, checkStringNone, formatTimeStamp, simplified, checkString
+ checkBool, checkInt, checkString, checkStringNone, formatTimeStamp,
+ simplified, yesNo
)
from novelwriter.constants import nwFiles
@@ -270,10 +271,9 @@ class ProjectXMLReader:
projData.setDoBackup(xItem.text)
elif xItem.tag == "language":
projData.setLanguage(xItem.text)
- elif xItem.tag == "spellCheck":
- projData.setSpellCheck(xItem.text)
- elif xItem.tag == "spellLang":
+ elif xItem.tag == "spellChecking":
projData.setSpellLang(xItem.text)
+ projData.setSpellCheck(xItem.attrib.get("auto", False))
elif xItem.tag == "status":
self._parseStatusImport(xItem, projData.itemStatus)
elif xItem.tag == "importance":
@@ -296,7 +296,11 @@ class ProjectXMLReader:
# Deprecated Nodes
if self._version < HEX_VERSION:
for xItem in xSection:
- if xItem.tag == "novelWordCount": # Moved to content attribute in 1.5
+ if xItem.tag == "spellCheck": # Changed to spellChecking in 1.5
+ projData.setSpellCheck(xItem.text)
+ elif xItem.tag == "spellLang": # Changed to spellChecking in 1.5
+ projData.setSpellLang(xItem.text)
+ elif xItem.tag == "novelWordCount": # Moved to content attribute in 1.5
projData.setInitCounts(novel=xItem.text)
elif xItem.tag == "notesWordCount": # Moved to content attribute in 1.5
projData.setInitCounts(notes=xItem.text)
@@ -517,10 +521,11 @@ class ProjectXMLWriter:
# Save Project Settings
xSettings = etree.SubElement(xRoot, "settings")
- self._packSingleValue(xSettings, "doBackup", projData.doBackup)
+ self._packSingleValue(xSettings, "doBackup", yesNo(projData.doBackup))
self._packSingleValue(xSettings, "language", projData.language)
- self._packSingleValue(xSettings, "spellCheck", projData.spellCheck)
- self._packSingleValue(xSettings, "spellLang", projData.spellLang)
+ self._packSingleValue(xSettings, "spellChecking", projData.spellLang, attrib={
+ "auto": yesNo(projData.spellCheck)
+ })
self._packDictKeyValue(xSettings, "lastHandle", projData.lastHandle)
self._packDictKeyValue(xSettings, "autoReplace", projData.autoReplace)
self._packDictKeyValue(xSettings, "titleFormat", projData.titleFormat)
@@ -536,7 +541,7 @@ class ProjectXMLWriter:
# Save Tree Content
contAttr = {
- "itemCount": str(len(projContent)),
+ "items": str(len(projContent)),
"novelWords": str(projData.currCounts[0]),
"notesWords": str(projData.currCounts[1]),
}
diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx
index b1f151ac..de890f9b 100644
--- a/sample/nwProject.nwx
+++ b/sample/nwProject.nwx
@@ -1,16 +1,15 @@
-
-
+
+
Sample Project
Sample Project
Jane Smith
Jay Doh
- False
+ no
en_GB
- True
- None
+ None
636b6aa9b697b
636b6aa9b697b
@@ -45,114 +44,114 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Sequel
-
-
- Title Page
+
+ Title Page
-
-
- Chapter One
+
+ Chapter One
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Archive
-
-
+
Scenes
-
-
- Old File
+
+ Old File
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/files/nwProject-1.5.nwx b/tests/files/nwProject-1.5.nwx
index 28f03cef..ec8668f4 100644
--- a/tests/files/nwProject-1.5.nwx
+++ b/tests/files/nwProject-1.5.nwx
@@ -1,5 +1,5 @@
-
+
Sample Project
Sample Project
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
en_GB
- True
- en_GB
+ en_GB
636b6aa9b697b
636b6aa9b697b
@@ -45,114 +44,114 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Sequel
-
-
- Title Page
+
+ Title Page
-
-
- Chapter One
+
+ Chapter One
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Archive
-
-
+
Scenes
-
-
- Old File
+
+ Old File
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx
index d5b2b2c7..086183c6 100644
--- a/tests/lipsum/nwProject.nwx
+++ b/tests/lipsum/nwProject.nwx
@@ -1,15 +1,14 @@
-
-
+
+
Lorem Ipsum
Lorem Ipsum
lipsum.com
- False
+ no
en_GB
- False
- None
+ None
7a992350f3eb6
None
@@ -40,90 +39,90 @@
Main
-
+
-
-
+
Novel
-
-
- Lorem Ipsum
+
+ Lorem Ipsum
-
-
- Front Matter
+
+ Front Matter
-
-
- Prologue
+
+ Prologue
-
-
- Act One
+
+ Act One
-
-
+
Chapter One
-
-
- Chapter One
+
+ Chapter One
-
-
- Scene One
+
+ Scene One
-
-
- Scene Two
+
+ Scene Two
-
-
- Interlude
+
+ Interlude
-
-
+
Chapter Two
-
-
- Chapter Two
+
+ Chapter Two
-
-
- Scene Three
+
+ Scene Three
-
-
- Scene Four
+
+ Scene Four
-
-
- Scene Five
+
+ Scene Five
-
-
+
Characters
-
-
- Mr. Nobody
+
+ Mr. Nobody
-
-
+
Plot
-
-
- Main
+
+ Main
-
-
+
World
-
-
- Ancient Europe
+
+ Ancient Europe
diff --git a/tests/reference/coreProject_NewFileFolder_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx
index 520883e5..5000c7d9 100644
--- a/tests/reference/coreProject_NewFileFolder_nwProject.nwx
+++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx
@@ -1,15 +1,14 @@
-
-
+
+
New Project
New Novel
Jane Doe
- True
+ yes
None
- False
- None
+ None
None
None
@@ -37,50 +36,50 @@
Main
-
+
-
-
+
Novel
-
-
+
Plot
-
-
+
Characters
-
-
+
World
-
-
- Title Page
+
+ Title Page
-
-
+
New Chapter
-
-
- New Chapter
+
+ New Chapter
-
-
- New Scene
+
+ New Scene
-
-
+
Stuff
-
-
- Hello
+
+ Hello
-
-
- Jane
+
+ Jane
diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx
index 6e2c26af..06a0ca07 100644
--- a/tests/reference/coreProject_NewRoot_nwProject.nwx
+++ b/tests/reference/coreProject_NewRoot_nwProject.nwx
@@ -1,15 +1,14 @@
-
-
+
+
New Project
New Novel
Jane Doe
- True
+ yes
None
- False
- None
+ None
None
None
@@ -37,69 +36,69 @@
Main
-
+
-
-
+
Novel
-
-
+
Plot
-
-
+
Characters
-
-
+
World
-
-
- Title Page
+
+ Title Page
-
-
+
New Chapter
-
-
- New Chapter
+
+ New Chapter
-
-
- New Scene
+
+ New Scene
-
-
+
Novel
-
-
+
Plot
-
-
+
Characters
-
-
+
Locations
-
-
+
Timeline
-
-
+
Objects
-
-
+
Custom
-
-
+
Custom
diff --git a/tests/reference/coreTools_NewCustomA_nwProject.nwx b/tests/reference/coreTools_NewCustomA_nwProject.nwx
index e7775cd5..48330e5f 100644
--- a/tests/reference/coreTools_NewCustomA_nwProject.nwx
+++ b/tests/reference/coreTools_NewCustomA_nwProject.nwx
@@ -1,5 +1,5 @@
-
+
Test Custom
Test Novel
@@ -7,10 +7,9 @@
John Doh
- True
+ yes
None
- False
- None
+ None
None
None
@@ -38,93 +37,93 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- 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
-
-
- Scene 2.1
+
+ Scene 2.1
-
-
- Scene 2.2
+
+ Scene 2.2
-
-
- Scene 2.3
+
+ Scene 2.3
-
-
- Chapter 3
+
+ Chapter 3
-
-
- Scene 3.1
+
+ Scene 3.1
-
-
- Scene 3.2
+
+ Scene 3.2
-
-
- Scene 3.3
+
+ Scene 3.3
-
-
+
Plot
-
-
- Main Plot
+
+ Main Plot
-
-
+
Characters
-
-
- Protagonist
+
+ Protagonist
-
-
+
Locations
-
-
- Main Location
+
+ Main Location
-
-
+
Archive
-
-
+
Trash
diff --git a/tests/reference/coreTools_NewCustomB_nwProject.nwx b/tests/reference/coreTools_NewCustomB_nwProject.nwx
index 6937cb0a..161d1157 100644
--- a/tests/reference/coreTools_NewCustomB_nwProject.nwx
+++ b/tests/reference/coreTools_NewCustomB_nwProject.nwx
@@ -1,5 +1,5 @@
-
+
Test Custom
Test Novel
@@ -7,10 +7,9 @@
John Doh
- True
+ yes
None
- False
- None
+ None
None
None
@@ -38,69 +37,69 @@
Main
-
+
-
-
+
Novel
-
-
- 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
-
-
+
Plot
-
-
- Main Plot
+
+ Main Plot
-
-
+
Characters
-
-
- Protagonist
+
+ Protagonist
-
-
+
Locations
-
-
- Main Location
+
+ Main Location
-
-
+
Archive
-
-
+
Trash
diff --git a/tests/reference/coreTools_NewMinimal_nwProject.nwx b/tests/reference/coreTools_NewMinimal_nwProject.nwx
index ba168a0e..1ac190ee 100644
--- a/tests/reference/coreTools_NewMinimal_nwProject.nwx
+++ b/tests/reference/coreTools_NewMinimal_nwProject.nwx
@@ -1,14 +1,13 @@
-
+
New Project
New Project
- True
+ yes
None
- False
- None
+ None
None
None
@@ -36,37 +35,37 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- New Chapter
+
+ New Chapter
-
-
- New Scene
+
+ New Scene
-
-
+
Plot
-
-
+
Characters
-
-
+
Locations
-
-
+
Archive
diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx
index 74bae460..e384ef9e 100644
--- a/tests/reference/guiEditor_Main_Final_nwProject.nwx
+++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx
@@ -1,15 +1,14 @@
-
+
New Project
New Novel
Jane Doe
- True
+ yes
None
- True
- None
+ None
000000000000f
None
@@ -37,53 +36,53 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
+
New Chapter
-
-
- New Chapter
+
+ New Chapter
-
-
- New Scene
+
+ New Scene
-
-
+
Plot
-
-
- New Note
+
+ New Note
-
-
+
Characters
-
-
- New Note
+
+ New Note
-
-
+
World
-
-
- New Note
+
+ New Note
-
-
+
Trash
diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx
index b5fd4013..977f03c1 100644
--- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx
+++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx
@@ -1,15 +1,14 @@
-
+
New Project
New Novel
Jane Doe
- True
+ yes
None
- False
- None
+ None
None
None
@@ -37,37 +36,37 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
+
New Chapter
-
-
- New Chapter
+
+ New Chapter
-
-
- New Scene
+
+ New Scene
-
-
+
Plot
-
-
+
Characters
-
-
+
World
diff --git a/tests/reference/projectXML_ReadLegacy10.nwx b/tests/reference/projectXML_ReadLegacy10.nwx
index b08e3511..d4ef1259 100644
--- a/tests/reference/projectXML_ReadLegacy10.nwx
+++ b/tests/reference/projectXML_ReadLegacy10.nwx
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
None
- True
- None
+ None
None
None
@@ -45,94 +44,94 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
+
A Folder
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/reference/projectXML_ReadLegacy11.nwx b/tests/reference/projectXML_ReadLegacy11.nwx
index c8519300..c2bb4cf4 100644
--- a/tests/reference/projectXML_ReadLegacy11.nwx
+++ b/tests/reference/projectXML_ReadLegacy11.nwx
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
None
- True
- None
+ None
None
None
@@ -45,94 +44,94 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
+
A Folder
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/reference/projectXML_ReadLegacy12.nwx b/tests/reference/projectXML_ReadLegacy12.nwx
index c28d7e16..90408b3f 100644
--- a/tests/reference/projectXML_ReadLegacy12.nwx
+++ b/tests/reference/projectXML_ReadLegacy12.nwx
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
en_GB
- True
- en_GB
+ en_GB
None
None
@@ -45,106 +44,106 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
+
A Folder
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Outtakes
-
-
+
Scenes
-
-
- Old File
+
+ Old File
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/reference/projectXML_ReadLegacy13.nwx b/tests/reference/projectXML_ReadLegacy13.nwx
index 8e448959..226affe4 100644
--- a/tests/reference/projectXML_ReadLegacy13.nwx
+++ b/tests/reference/projectXML_ReadLegacy13.nwx
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
en_GB
- True
- en_GB
+ en_GB
None
None
@@ -45,106 +44,106 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
+
A Folder
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Archive
-
-
+
Scenes
-
-
- Old File
+
+ Old File
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/reference/projectXML_ReadLegacy14.nwx b/tests/reference/projectXML_ReadLegacy14.nwx
index 445817a3..8cd18728 100644
--- a/tests/reference/projectXML_ReadLegacy14.nwx
+++ b/tests/reference/projectXML_ReadLegacy14.nwx
@@ -7,10 +7,9 @@
Jay Doh
- True
+ yes
en_GB
- True
- en_GB
+ en_GB
None
None
@@ -45,114 +44,114 @@
Main
-
+
-
-
+
Novel
-
-
- Title Page
+
+ Title Page
-
-
- Page
+
+ Page
-
-
- Part One
+
+ Part One
-
-
- Chapter One
+
+ Chapter One
-
-
- Making a Scene
+
+ Making a Scene
-
-
- Another Scene
+
+ Another Scene
-
-
- Interlude
+
+ Interlude
-
-
- A Note on Structure
+
+ A Note on Structure
-
-
- Chapter Two
+
+ Chapter Two
-
-
- We Found John!
+
+ We Found John!
-
-
+
Sequel
-
-
- Title Page
+
+ Title Page
-
-
- Chapter One
+
+ Chapter One
-
-
+
Characters
-
-
+
Main Characters
-
-
- John Smith
+
+ John Smith
-
-
- Jane Smith
+
+ Jane Smith
-
-
+
Locations
-
-
- Earth
+
+ Earth
-
-
- Space
+
+ Space
-
-
- Mars
+
+ Mars
-
-
+
Archive
-
-
+
Scenes
-
-
- Old File
+
+ Old File
-
-
+
Trash
-
-
- Delete Me!
+
+ Delete Me!
diff --git a/tests/test_base/test_base_common.py b/tests/test_base/test_base_common.py
index ca487aa2..f6d60a1c 100644
--- a/tests/test_base/test_base_common.py
+++ b/tests/test_base/test_base_common.py
@@ -32,9 +32,9 @@ from novelwriter.common import (
checkStringNone, checkString, checkInt, checkFloat, checkBool, checkHandle,
checkUuid, isHandle, isTitleTag, isItemClass, isItemType, isItemLayout,
hexToInt, minmax, checkIntTuple, formatInt, formatTimeStamp, formatTime,
- simplified, splitVersionNumber, transferCase, fuzzyTime, numberToRoman,
- jsonEncode, readTextFile, makeFileNameSafe, ensureFolder, sha256sum,
- getGuiItem, NWConfigParser
+ simplified, yesNo, splitVersionNumber, transferCase, fuzzyTime,
+ numberToRoman, jsonEncode, readTextFile, makeFileNameSafe, ensureFolder,
+ sha256sum, getGuiItem, NWConfigParser
)
@@ -105,16 +105,41 @@ def testBaseCommon_CheckBool():
bool, or integer 1 or 0, are returned as bool. Otherwise, the
default is returned.
"""
+ # Bools
+ assert checkBool(True, False) is True
+ assert checkBool(False, True) is False
+
+ # Valid Strings
assert checkBool("True", False) is True
assert checkBool("False", True) is False
- assert checkBool("Boo", False) is False
- assert checkBool("Boo", True) is True
- assert checkBool(None, True) is True
- assert checkBool(None, False) is False
+ assert checkBool("true", False) is True
+ assert checkBool("false", True) is False
+ assert checkBool("Yes", False) is True
+ assert checkBool("No", True) is False
+ assert checkBool("yes", False) is True
+ assert checkBool("no", True) is False
+ assert checkBool("On", False) is True
+ assert checkBool("Off", True) is False
+ assert checkBool("on", False) is True
+ assert checkBool("off", True) is False
+
+ # Invalid Strings
+ assert checkBool("Foo", False) is False
+ assert checkBool("Foo", True) is True
+ assert checkBool("bar", False) is False
+ assert checkBool("bar", True) is True
+
+ # Valid Integers
assert checkBool(0, True) is False
assert checkBool(1, False) is True
+
+ # Inalid Integers
assert checkBool(2, True) is True
assert checkBool(2, False) is False
+
+ # Other Types
+ assert checkBool(None, True) is True
+ assert checkBool(None, False) is False
assert checkBool(0.0, True) is True
assert checkBool(1.0, False) is False
assert checkBool(2.0, True) is True
@@ -331,6 +356,34 @@ def testBaseCommon_Simplified():
# END Test testBaseCommon_Simplified
+@pytest.mark.base
+def testBaseCommon_YesNo():
+ """Test the yesNo function.
+ """
+ # Bool
+ assert yesNo(True) == "yes"
+ assert yesNo(False) == "no"
+
+ # None
+ assert yesNo(None) == "no"
+
+ # String
+ assert yesNo("foo") == "yes"
+ assert yesNo("") == "no"
+
+ # Integer
+ assert yesNo(0) == "no"
+ assert yesNo(1) == "yes"
+ assert yesNo(2) == "yes"
+
+ # Float
+ assert yesNo(0.0) == "no"
+ assert yesNo(1.0) == "yes"
+ assert yesNo(2.0) == "yes"
+
+# END Test testBaseCommon_YesNo
+
+
@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 f02f21f3..16d2ffe2 100644
--- a/tests/test_core/test_core_item.py
+++ b/tests/test_core/test_core_item.py
@@ -564,7 +564,7 @@ def testCoreItem_PackUnpack(mockGUI, caplog, mockRnd):
"layout": "DOCUMENT",
},
"metaAttr": {
- "expanded": "True",
+ "expanded": "yes",
"heading": "H1",
"charCount": "100",
"wordCount": "20",
@@ -574,7 +574,7 @@ def testCoreItem_PackUnpack(mockGUI, caplog, mockRnd):
"nameAttr": {
"status": "s000000",
"import": "i000001",
- "active": "False",
+ "active": "no",
}
}
@@ -635,7 +635,7 @@ def testCoreItem_PackUnpack(mockGUI, caplog, mockRnd):
"class": "NOVEL",
},
"metaAttr": {
- "expanded": "True",
+ "expanded": "yes",
},
"nameAttr": {
"status": "s000000",
@@ -700,7 +700,7 @@ def testCoreItem_PackUnpack(mockGUI, caplog, mockRnd):
"class": "NOVEL",
},
"metaAttr": {
- "expanded": "True",
+ "expanded": "yes",
},
"nameAttr": {
"status": "s000000",