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."""
|
"""Set the text for a comment and make sure it is a string."""
|
||||||
match comment.lower():
|
match comment.lower():
|
||||||
case "short" | "synopsis" | "summary":
|
case "short" | "synopsis" | "summary":
|
||||||
self._comments["summary"] = str(text)
|
self._appendCommentText("summary", text)
|
||||||
case "story" if key:
|
case "story" if key:
|
||||||
self._cache.story.add(key)
|
self._cache.story.add(key)
|
||||||
self._comments[f"story.{key}"] = str(text)
|
self._appendCommentText(f"story.{key}", text)
|
||||||
case "note" if key:
|
case "note" if key:
|
||||||
self._cache.note.add(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:
|
def setTag(self, tag: str) -> None:
|
||||||
"""Set the tag for references, and make sure it is a string."""
|
"""Set the tag for references, and make sure it is a string."""
|
||||||
@@ -371,6 +371,7 @@ class IndexHeading:
|
|||||||
|
|
||||||
def unpackData(self, data: dict) -> None:
|
def unpackData(self, data: dict) -> None:
|
||||||
"""Unpack a heading entry from a dictionary."""
|
"""Unpack a heading entry from a dictionary."""
|
||||||
|
self._comments = {} # These are accumulative and should be reset here
|
||||||
for key, entry in data.items():
|
for key, entry in data.items():
|
||||||
if key == "meta":
|
if key == "meta":
|
||||||
self.setLevel(entry.get("level", "H0"))
|
self.setLevel(entry.get("level", "H0"))
|
||||||
@@ -394,3 +395,13 @@ class IndexHeading:
|
|||||||
self.setComment(comment, compact(kind), str(entry))
|
self.setComment(comment, compact(kind), str(entry))
|
||||||
else:
|
else:
|
||||||
raise KeyError("Unknown key in heading entry")
|
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("-r", action="store_true", help="Generate reports")
|
||||||
parser.add_argument("-t", action="store_true", help="Generate terminal report")
|
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("-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("-m", help="Test modules", metavar="MARKEXPR")
|
||||||
parser.add_argument("-k", help="Test filters", metavar="EXPRESSION")
|
parser.add_argument("-k", help="Test filters", metavar="EXPRESSION")
|
||||||
|
|
||||||
@@ -30,6 +32,10 @@ if __name__ == "__main__":
|
|||||||
cmd += ["pytest", "-vv"]
|
cmd += ["pytest", "-vv"]
|
||||||
if args.o:
|
if args.o:
|
||||||
env["QT_QPA_PLATFORM"] = "offscreen"
|
env["QT_QPA_PLATFORM"] = "offscreen"
|
||||||
|
if args.lf:
|
||||||
|
cmd += ["--last-failed"]
|
||||||
|
if args.sw:
|
||||||
|
cmd += ["--stepwise"]
|
||||||
if args.m:
|
if args.m:
|
||||||
cmd += ["-m", args.m]
|
cmd += ["-m", args.m]
|
||||||
if args.k:
|
if args.k:
|
||||||
|
|||||||
@@ -251,13 +251,17 @@ def testCoreIndexData_IndexHeading():
|
|||||||
"note.consitency": "Only explode once",
|
"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
|
# Unpack KeyError
|
||||||
with pytest.raises(KeyError, match="Unknown key in heading entry"):
|
with pytest.raises(KeyError, match="Unknown key in heading entry"):
|
||||||
head.unpackData({"stuff": "more stuff"})
|
head.unpackData({"stuff": "more stuff"})
|
||||||
|
|
||||||
# Unpack Comments
|
# Unpack Comments
|
||||||
head.unpackData({"summary": "How it started ..."})
|
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
|
@pytest.mark.core
|
||||||
|
|||||||
Reference in New Issue
Block a user