Add back extra column content

This commit is contained in:
Veronica Berglyd Olsen
2025-03-23 16:41:40 +01:00
parent 9d63a018e8
commit 95d8e3ac98
7 changed files with 113 additions and 301 deletions
+23 -15
View File
@@ -22,6 +22,7 @@ from __future__ import annotations
import pytest
from novelwriter.core.index import TagsIndex
from novelwriter.core.indexdata import IndexHeading, IndexNode
from novelwriter.core.item import NWItem
from novelwriter.core.project import NWProject
@@ -33,9 +34,10 @@ def testCoreIndexData_IndexNode(mockGUI):
handle = "0123456789abc"
project = NWProject()
item = NWItem(project, handle)
tags = TagsIndex()
# Defaults
node = IndexNode(handle, item)
node = IndexNode(tags, handle, item)
assert node.handle == handle
assert node.item is item
assert str(node) == f"<IndexNode handle='{handle}'>"
@@ -44,8 +46,8 @@ def testCoreIndexData_IndexNode(mockGUI):
assert "T0000" in node # Placeholder heading
# Add a heading
head1 = IndexHeading(node.nextHeading(), line=1, level="H1", title="Heading 1")
head2 = IndexHeading(node.nextHeading(), line=10, level="H2", title="Heading 2")
head1 = IndexHeading(tags, node.nextHeading(), line=1, level="H1", title="Heading 1")
head2 = IndexHeading(tags, node.nextHeading(), line=10, level="H2", title="Heading 2")
node.addHeading(head1)
node.addHeading(head2)
assert len(node) == 2
@@ -105,11 +107,12 @@ def testCoreIndexData_IndexNodePackUnpack(mockGUI):
handle = "0123456789abc"
project = NWProject()
item = NWItem(project, handle)
node = IndexNode(handle, item)
tags = TagsIndex()
node = IndexNode(tags, handle, item)
# Add some headings and notes
head1 = IndexHeading(node.nextHeading(), line=1, level="H1", title="Heading 1")
head2 = IndexHeading(node.nextHeading(), line=10, level="H2", title="Heading 2")
head1 = IndexHeading(tags, node.nextHeading(), line=1, level="H1", title="Heading 1")
head2 = IndexHeading(tags, node.nextHeading(), line=10, level="H2", title="Heading 2")
node.addHeading(head1)
node.addHeading(head2)
node.setHeadingCounts("T0001", 42, 13, 3)
@@ -128,7 +131,7 @@ def testCoreIndexData_IndexNodePackUnpack(mockGUI):
assert set(data["document"]["footnotes"]) == {"key1", "key2"}
# Create a new node
new = IndexNode(handle, item)
new = IndexNode(tags, handle, item)
# Unpack heading one
data = {"T0001": {"meta": {
@@ -165,7 +168,8 @@ def testCoreIndexData_IndexNodePackUnpack(mockGUI):
def testCoreIndexData_IndexHeading():
"""Test the IndexHeading class."""
# Defaults
head = IndexHeading("T0001")
tags = TagsIndex()
head = IndexHeading(tags, "T0001")
assert str(head) == "<IndexHeading key='T0001'>"
assert repr(head) == "<IndexHeading key='T0001'>"
assert head.key == "T0001"
@@ -234,11 +238,13 @@ def testCoreIndexData_IndexHeading():
@pytest.mark.core
def testCoreIndexData_IndexHeadingUnpackMeta():
"""Test IndexHeading class meta unpacking."""
tags = TagsIndex()
# Valid
data = {"meta": {
"level": "H1", "title": "So it Begins", "line": 1, "tag": "begins", "counts": [95, 18, 1]
}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
head.unpackData(data)
assert head.level == "H1"
assert head.title == "So it Begins"
@@ -252,7 +258,7 @@ def testCoreIndexData_IndexHeadingUnpackMeta():
data = {"meta": {
"level": "H9", "title": None, "line": None, "tag": None, "counts": [42]
}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
head.unpackData(data)
assert head.level == "H0"
assert head.title == "None"
@@ -264,7 +270,7 @@ def testCoreIndexData_IndexHeadingUnpackMeta():
# Empty
data = {"meta": {}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
head.unpackData(data)
assert head.level == "H0"
assert head.title == ""
@@ -278,11 +284,13 @@ def testCoreIndexData_IndexHeadingUnpackMeta():
@pytest.mark.core
def testCoreIndexData_IndexHeadingUnpackRefs():
"""Test IndexHeading class refs unpacking."""
tags = TagsIndex()
# Valid
data = {"refs": {
"jane": "@char,@pov", "john": "@char", "earth": "@location", "space": "@mention,@location"
}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
head.unpackData(data)
assert head.references["jane"] == {"@char", "@pov"}
assert head.references["john"] == {"@char"}
@@ -291,18 +299,18 @@ def testCoreIndexData_IndexHeadingUnpackRefs():
# Invalid key
data = {"refs": {0: "@char,@pov"}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
with pytest.raises(ValueError, match="Heading reference key must be a string"):
head.unpackData(data)
# Invalid value
data = {"refs": {"jane": None}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
with pytest.raises(ValueError, match="Heading reference value must be a string"):
head.unpackData(data)
# Invalid keyword
data = {"refs": {"jane": "@char,@pov,@stuff"}}
head = IndexHeading("T0001")
head = IndexHeading(tags, "T0001")
with pytest.raises(ValueError, match="Heading reference contains an invalid keyword"):
head.unpackData(data)
+4 -4
View File
@@ -27,7 +27,7 @@ import pytest
from novelwriter.constants import nwFiles
from novelwriter.core.options import OptionState
from novelwriter.core.project import NWProject
from novelwriter.gui.noveltree import NovelTreeColumn
from novelwriter.enum import nwNovelExtra
from tests.mocked import causeOSError
@@ -110,7 +110,7 @@ def testCoreOptions_SetGet(mockGUI):
project = NWProject()
options = OptionState(project)
nwColHidden = NovelTreeColumn.HIDDEN
nwColHidden = nwNovelExtra.HIDDEN
# Set invalid values
assert options.setValue("MockGroup", "mockItem", None) is False
@@ -141,7 +141,7 @@ def testCoreOptions_SetGet(mockGUI):
assert options.getFloat("GuiNovelDetails", "mockItem", None) is None # type: ignore
assert options.getBool("GuiNovelDetails", "clearDouble", None) is True # type: ignore
assert options.getBool("GuiNovelDetails", "mockItem", None) is None # type: ignore
assert options.getEnum("GuiNovelView", "lastCol", NovelTreeColumn, nwColHidden) == nwColHidden
assert options.getEnum("GuiNovelView", "lastCol", nwNovelExtra, nwColHidden) == nwColHidden
# Get from non-existent groups
assert options.getValue("SomeGroup", "mockItem", None) is None
@@ -149,4 +149,4 @@ def testCoreOptions_SetGet(mockGUI):
assert options.getInt("SomeGroup", "mockItem", None) is None # type: ignore
assert options.getFloat("SomeGroup", "mockItem", None) is None # type: ignore
assert options.getBool("SomeGroup", "mockItem", None) is None # type: ignore
assert options.getEnum("SomeGroup", "mockItem", NovelTreeColumn, None) is None # type: ignore
assert options.getEnum("SomeGroup", "mockItem", nwNovelExtra, None) is None # type: ignore