def dump(self, entry: Entry) -> str: # pdoc will inherit the docstring from the base class # noqa: D102 Event.PreBibtexDump.fire(entry) database = bibtexparser.bibdatabase.BibDatabase() stringified_entry = entry.stringify() stringified_entry["ID"] = stringified_entry.pop("label") if "month" in stringified_entry.keys(): # convert month to bibtexexpression stringified_entry[ "month"] = bibtexparser.bibtexexpression.BibDataStringExpression( [ bibtexparser.bibdatabase.BibDataString( database, stringified_entry["month"]) ]) database.entries = [stringified_entry] LOGGER.debug("Converting entry %s to BibTex format.", entry.label) writer = bibtexparser.bwriter.BibTexWriter() writer.common_strings = True string: str = writer.write(database) string = Event.PostBibtexDump.fire(string) or string return string
def test_stringify() -> None: """Test the `cobib.database.Entry.stringify` method.""" entry = Entry( "dummy", { "file": ["/tmp/a.txt", "/tmp/b.txt"], "month": 8, "tags": ["tag1", "tag2"], }, ) expected = { "label": "dummy", "file": "/tmp/a.txt, /tmp/b.txt", "month": "aug", "tags": "tag1, tag2", } assert entry.stringify() == expected