Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bibtexparser/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down
7 changes: 6 additions & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand Down