diff --git a/bibtexparser/writer.py b/bibtexparser/writer.py index 421b274..ace8c69 100644 --- a/bibtexparser/writer.py +++ b/bibtexparser/writer.py @@ -64,7 +64,7 @@ def _treat_failed_block(block: ParsingFailedBlock, bibtex_format: "BibtexFormat" if block.raw is None: raise ValueError(_failed_blocks_without_raw_error([block])) lines = len(block.raw.splitlines()) - parsing_failed_comment = PARSING_FAILED_COMMENT.format(n=lines) + parsing_failed_comment = bibtex_format.parsing_failed_comment.format(n=lines) return [parsing_failed_comment, "\n", block.raw, "\n"] diff --git a/tests/test_writer.py b/tests/test_writer.py index 5e36cac..ec4aa99 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -172,12 +172,17 @@ def test_write_failed_block(): lines = string.splitlines() assert len(lines) == 5 - assert lines[0].startswith("% WARNING") + assert lines[0] == "% WARNING Parsing failed for the following 4 lines." assert lines[1] == "@article{irrelevant-for-this-test," assert lines[2] == "except = {that-there-need-to-be}," assert lines[3] == "other = {multiple-lines}" assert lines[4] == "}" + bib_format = BibtexFormat() + bib_format.parsing_failed_comment = "% CUSTOM {n} lines" + custom_string = writer.write(library, bib_format) + assert custom_string.splitlines()[0] == "% CUSTOM 4 lines" + def test_write_failed_block_without_raw_raises(): """A failed block with no raw bibtex cannot be written (issue #400)."""