From 20e1126a625e3e199ab6ceef4febdf9f6c86b2cc Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:11:56 +0200 Subject: [PATCH 1/3] Allow named comments to be repeated (#2483) --- novelwriter/core/indexdata.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/novelwriter/core/indexdata.py b/novelwriter/core/indexdata.py index b7867bd3..78477312 100644 --- a/novelwriter/core/indexdata.py +++ b/novelwriter/core/indexdata.py @@ -300,13 +300,13 @@ class IndexHeading: """Set the text for a comment and make sure it is a string.""" match comment.lower(): case "short" | "synopsis" | "summary": - self._comments["summary"] = str(text) + self._appendCommentText("summary", text) case "story" if key: self._cache.story.add(key) - self._comments[f"story.{key}"] = str(text) + self._appendCommentText(f"story.{key}", text) case "note" if key: self._cache.note.add(key) - self._comments[f"note.{key}"] = str(text) + self._appendCommentText(f"note.{key}", text) def setTag(self, tag: str) -> None: """Set the tag for references, and make sure it is a string.""" @@ -371,6 +371,7 @@ class IndexHeading: def unpackData(self, data: dict) -> None: """Unpack a heading entry from a dictionary.""" + self._comments = {} # These are accumulative and should be reset here for key, entry in data.items(): if key == "meta": self.setLevel(entry.get("level", "H0")) @@ -394,3 +395,13 @@ class IndexHeading: self.setComment(comment, compact(kind), str(entry)) else: raise KeyError("Unknown key in heading entry") + + ## + # Internal Functions + ## + + def _appendCommentText(self, key: str, text: str) -> None: + """Append text to a comment.""" + if current := self._comments.get(key): + text = f"{current:s}\n\n{text:s}" + self._comments[key] = str(text) From 10f0f6440bbcfb0550dadb02a565c833b75e75bc Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:12:11 +0200 Subject: [PATCH 2/3] Extend tests --- tests/test_core/test_core_indexdata.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_core/test_core_indexdata.py b/tests/test_core/test_core_indexdata.py index faef5d51..cb749be7 100644 --- a/tests/test_core/test_core_indexdata.py +++ b/tests/test_core/test_core_indexdata.py @@ -251,13 +251,17 @@ def testCoreIndexData_IndexHeading(): "note.consitency": "Only explode once", } + # Append Synopsis + head.setComment(nwComment.SYNOPSIS.name, "", "How it started ...") + assert head.synopsis == "In the beginning ...\n\nHow it started ..." + # Unpack KeyError with pytest.raises(KeyError, match="Unknown key in heading entry"): head.unpackData({"stuff": "more stuff"}) # Unpack Comments head.unpackData({"summary": "How it started ..."}) - assert head.synopsis == "How it started ..." + assert head.synopsis == "How it started ..." # This resets the comments dictionary @pytest.mark.core From f23ce71620a8cd7901d5b137c097d80da08a9945 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:12:27 +0200 Subject: [PATCH 3/3] Add stepwise and rerun commands to test runner script --- run_tests.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/run_tests.py b/run_tests.py index a2b8e937..18e1eeae 100755 --- a/run_tests.py +++ b/run_tests.py @@ -14,6 +14,8 @@ if __name__ == "__main__": parser.add_argument("-r", action="store_true", help="Generate reports") parser.add_argument("-t", action="store_true", help="Generate terminal report") parser.add_argument("-u", action="store_true", help="Generate uncovered terminal report") + parser.add_argument("-lf", action="store_true", help="Re-run failed tests") + parser.add_argument("-sw", action="store_true", help="Run tests stepwise") parser.add_argument("-m", help="Test modules", metavar="MARKEXPR") parser.add_argument("-k", help="Test filters", metavar="EXPRESSION") @@ -30,6 +32,10 @@ if __name__ == "__main__": cmd += ["pytest", "-vv"] if args.o: env["QT_QPA_PLATFORM"] = "offscreen" + if args.lf: + cmd += ["--last-failed"] + if args.sw: + cmd += ["--stepwise"] if args.m: cmd += ["-m", args.m] if args.k: