Allow repeated named comments (#2543)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user