Skip to content
Draft
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
25 changes: 25 additions & 0 deletions tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bibtexparser.model import Entry
from bibtexparser.model import Field
from bibtexparser.model import ImplicitComment
from bibtexparser.model import String


def get_dummy_entry():
Expand All @@ -17,6 +18,10 @@ def get_dummy_entry():
)


def get_dummy_string():
return String(key="duplicateKey", value='"A value"')


def test_replace_with_duplicates():
"""Test that replace() works when there are duplicate values. See issue 404."""
library = Library()
Expand Down Expand Up @@ -97,6 +102,26 @@ def test_constructor_fails_on_duplicate_by_default():
assert len(library.failed_blocks) == 1


def test_add_string_fails_on_duplicate_by_default():
"""Strict duplicate handling applies to string blocks as well as entries."""
library = Library(blocks=[get_dummy_string()])

with pytest.raises(ValueError, match="duplicateKey"):
library.add(get_dummy_string())

assert len(library.strings) == 1
assert len(library.failed_blocks) == 0


def test_entry_and_string_keys_use_separate_namespaces():
"""An entry and string may share a key without becoming duplicate blocks."""
library = Library(blocks=[get_dummy_entry(), get_dummy_string()])

assert len(library.entries) == 1
assert len(library.strings) == 1
assert len(library.failed_blocks) == 0


def test_remove_prefers_identical_instance_over_equal_block():
"""With two equal blocks, remove() must remove the passed instance. See issue 537."""
first_comment = ImplicitComment("#same")
Expand Down
Loading