Skip to content

Commit

Permalink
Entry: mimic in (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Feb 7, 2024
1 parent 443978e commit a751587
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bibtexparser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def pop_field(self, key: str) -> Optional[Field]:
self._fields = [f for f in self._fields if f.key != key]
return field

def __contains__(self, key: str) -> bool:
"""Dict-mimicking ``in`` operator."""
return key in self.fields_dict

def __getitem__(self, key: str) -> Any:
"""Dict-mimicking index.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def test_entry_deepcopy():
assert entry_1.fields_dict["field"] == entry_2.fields_dict["field"]


def test_entry_contain():
entry = Entry("article", "key", [Field("field", "value", 1)], 1, "raw")
assert "field" in entry
assert "other" not in entry


def test_string_equality():
# Equal to itself
string_1 = String(
Expand Down

0 comments on commit a751587

Please sign in to comment.