-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into reproduce-441
- Loading branch information
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Smoke test for custom middleware, based on the #440 by @tdegeus""" | ||
|
||
import bibtexparser | ||
from bibtexparser.middlewares.middleware import BlockMiddleware | ||
|
||
bibtex_str = """ | ||
@ARTICLE{Cesar2013, | ||
author = {Jean César and T. W. J. de Geus}, | ||
title = {An amazing title}, | ||
year = {2013}, | ||
pages = {12--23}, | ||
volume = {12}, | ||
journal = {Nice Journal} | ||
} | ||
""" | ||
|
||
|
||
abbreviations = {"Nice Journal": "NJ", "Another Nice Journal": "ANJ"} | ||
|
||
|
||
class JournalAbbreviate(BlockMiddleware): | ||
def transform_entry(self, entry, *args, **kwargs): | ||
if entry["journal"] in abbreviations: | ||
entry["journal"] = abbreviations[entry["journal"]] | ||
return entry | ||
|
||
|
||
def test_custom_middleware_smoke(): | ||
"""Test that the very simple custom middleware above works.""" | ||
library = bibtexparser.parse_string( | ||
bibtex_str, append_middleware=[JournalAbbreviate(True)] | ||
) | ||
assert library.entries[0]["journal"] == "NJ" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters