Skip to content
Merged
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: 2 additions & 0 deletions tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ReferenceCase:
expected_markdown: str
pmid: int | None = None
arxiv: str | None = None
skip_reason: str | None = None

@property
def expected_text(self) -> str:
Expand Down Expand Up @@ -465,6 +466,7 @@ def expected_text(self) -> str:
applications in drug development and beyond.},
}""").strip(),
expected_markdown=r"Manyi Yang, Duo Zhang, Xinyan Wang, Lingfeng Zhang, Tong Zhu, Han Wang, Ab initio Accuracy Neural Network Potential for Drug-like Molecules, *ChemRxiv*, 2024, DOI: [10.26434/chemrxiv-2024-sq8nh](https://doi.org/10.26434/chemrxiv-2024-sq8nh). [![Citations](https://citations.njzjz.win/10.26434/chemrxiv-2024-sq8nh)](https://badge.dimensions.ai/details/doi/10.26434/chemrxiv-2024-sq8nh)",
skip_reason="ChemRxiv API broken",
),
# chapter
ReferenceCase(
Expand Down
22 changes: 18 additions & 4 deletions tests/test_from_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@

from wenxian.from_identifier import from_identifier

from .cases import TEST_CASES
from .cases import TEST_CASES, ReferenceCase


def _create_test_param(test_case: ReferenceCase, identifier: str | None):
"""Create a pytest.param with skip marks if needed."""
return pytest.param(
identifier,
test_case.reference,
marks=pytest.mark.skip(reason=test_case.skip_reason)
if test_case.skip_reason
else (),
)


@pytest.mark.parametrize(
"identifier, expected",
[
*[(test_case.reference.doi, test_case.reference) for test_case in TEST_CASES],
*[
_create_test_param(test_case, test_case.reference.doi)
for test_case in TEST_CASES
],
*[
# from_identifier accept str
(str(test_case.pmid), test_case.reference)
_create_test_param(test_case, str(test_case.pmid))
for test_case in TEST_CASES
if test_case.pmid is not None
],
*[
(test_case.arxiv, test_case.reference)
_create_test_param(test_case, test_case.arxiv)
for test_case in TEST_CASES
if test_case.arxiv is not None
],
Expand Down
22 changes: 18 additions & 4 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,44 @@

import pytest

from .cases import TEST_CASES
from .cases import TEST_CASES, ReferenceCase

if TYPE_CHECKING:
from wenxian.reference import Reference


def _create_test_param(test_case: ReferenceCase, expected_value: str):
"""Create a pytest.param with skip marks if needed."""
return pytest.param(
test_case.reference,
expected_value,
marks=pytest.mark.skip(reason=test_case.skip_reason)
if test_case.skip_reason
else (),
)


@pytest.mark.parametrize(
"reference, expected", [(cc.reference, cc.expected_bibtex) for cc in TEST_CASES]
"reference, expected",
[_create_test_param(cc, cc.expected_bibtex) for cc in TEST_CASES],
)
def test_bibtex(reference: Reference, expected):
"""Test generating BibTeX entries from references."""
assert reference.bibtex.strip() == expected


@pytest.mark.parametrize(
"reference, expected", [(cc.reference, cc.expected_markdown) for cc in TEST_CASES]
"reference, expected",
[_create_test_param(cc, cc.expected_markdown) for cc in TEST_CASES],
)
def test_markdown(reference: Reference, expected):
"""Test generating Markdown from references."""
assert reference.markdown.strip() == expected


@pytest.mark.parametrize(
"reference, expected", [(cc.reference, cc.expected_text) for cc in TEST_CASES]
"reference, expected",
[_create_test_param(cc, cc.expected_text) for cc in TEST_CASES],
)
def test_text(reference: Reference, expected):
"""Test generating text from references."""
Expand Down