Skip to content

Commit

Permalink
Add checking start_line and raw value
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Nov 4, 2023
1 parent d1b8d08 commit e15129b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bibtexparser/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _handle_entry(self, m, m_val) -> Union[Entry, ParsingFailedBlock]:
entry_type=entry_type,
key=key,
fields=fields,
raw=self.bibstr[m.start() : end_index + 1],
raw=self.bibstr[m.start() : end_index],
)

# If there were duplicate field keys, we return a DuplicateFieldKeyBlock wrapping
Expand Down
80 changes: 50 additions & 30 deletions tests/splitter_tests/test_splitter_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,57 +321,77 @@ def test_handles_duplicate_strings():
)


blocks_not_starting_on_new_lines = """
blocks_not_starting_on_new_lines = """\
@article{KUEH2023S98,
title = {Myocardial Characterisation Using Delayed Dual-Energy Cardiac Computed Tomography},
journal = {Heart, Lung and Circulation},
volume = {32},
pages = {S98},
year = {2023},
note = {Abstracts for the Cardiac Society of Australia and New Zealand Annual Scientific Meeting (New Zealand) 2023, 15 - 17 June 2023, Auckland, New Zealand},
issn = {1443-9506},
doi = {https://doi.org/10.1016/j.hlc.2023.04.262},
url = {https://www.sciencedirect.com/science/article/pii/S1443950623004390},
author = {S.-H. Kueh and J. Benatar and R. Stewart}
}@INPROCEEDINGS{9837531,
author={Hassan, Mona Bakri and Saeed, Rashid A. and Khalifa, Othman and Ali, Elmustafa Sayed and Mokhtar, Rania A. and Hashim, Aisha A.},
booktitle={2022 IEEE 2nd International Maghreb Meeting of the Conference on Sciences and Techniques of Automatic Control and Computer Engineering (MI-STA)},
title={Green Machine Learning for Green Cloud Energy Efficiency},
year={2022},
volume={},
number={},
pages={288-294},
doi={10.1109/MI-STA54861.2022.9837531}}@ARTICLE{9372936,
author={Hu, Ning and Tian, Zhihong and Du, Xiaojiang and Guizani, Nadra and Zhu, Zhihan},
journal={IEEE Transactions on Green Communications and Networking},
title={Deep-Green: A Dispersed Energy-Efficiency Computing Paradigm for Green Industrial IoT},
year={2021},
volume={5},
number={2},
pages={750-764},
doi={10.1109/TGCN.2021.3064683}}@ARTICLE{5445167,
author={Kumar, Karthik and Lu, Yung-Hsiang},
journal={Computer},
title={Cloud Computing for Mobile Users: Can Offloading Computation Save Energy?},
year={2010},
volume={43},
number={4},
pages={51-56},
doi={10.1109/MC.2010.98}}
"""


def test_blocks_not_starting_on_new_lines():
@pytest.mark.parametrize(
"expected",
[
{
"key": "KUEH2023S98",
"type": "article",
"raw": "@article{KUEH2023S98,\n"
"title = {Myocardial Characterisation Using Delayed Dual-Energy Cardiac Computed Tomography},\n"
"author = {S.-H. Kueh and J. Benatar and R. Stewart}\n}",
"start_line": 0,
},
{
"key": "9837531",
"type": "inproceedings",
"raw": "@INPROCEEDINGS{9837531,\n"
" author={Hassan, Mona Bakri and Saeed, Rashid A. and Khalifa, Othman and Ali, Elmustafa Sayed and Mokhtar, Rania A. and Hashim, Aisha A.},\n"
" title={Green Machine Learning for Green Cloud Energy Efficiency},\n"
" doi={10.1109/MI-STA54861.2022.9837531}}",
"start_line": 3,
},
{
"key": "9372936",
"type": "article",
"raw": "@ARTICLE{9372936,\n"
" author={Hu, Ning and Tian, Zhihong and Du, Xiaojiang and Guizani, Nadra and Zhu, Zhihan},\n"
" title={Deep-Green: A Dispersed Energy-Efficiency Computing Paradigm for Green Industrial IoT},\n"
" doi={10.1109/TGCN.2021.3064683}}",
"start_line": 6,
},
{
"key": "5445167",
"type": "article",
"raw": "@ARTICLE{5445167,\n"
" author={Kumar, Karthik and Lu, Yung-Hsiang},\n"
" title={Cloud Computing for Mobile Users: Can Offloading Computation Save Energy?},\n"
" doi={10.1109/MC.2010.98}}",
"start_line": 9,
},
],
)
def test_blocks_not_starting_on_new_lines(expected: Dict[str, Any]):
"""Test the new blocks that are not on new lines.
Discussed at https://github.com/sciunto-org/python-bibtexparser/issues/411.
"""
import bibtexparser

lib = bibtexparser.parse_string(blocks_not_starting_on_new_lines)
assert len(lib.blocks) == 4
assert len(lib.entries) == 4
assert lib.entries[0].entry_type == "article"
assert lib.entries[1].entry_type == "inproceedings"
assert lib.entries[2].entry_type == "article"
assert lib.entries[3].entry_type == "article"
entry_by_key = lib.entries_dict
assert len(entry_by_key) == 4

entry = entry_by_key[expected["key"]]
assert entry.key == expected["key"]
assert entry.entry_type == expected["type"]
assert entry.raw == expected["raw"]
assert entry.start_line == expected["start_line"]

0 comments on commit e15129b

Please sign in to comment.