Initial version
This commit is contained in:
commit
42996b0f4e
31 changed files with 933 additions and 0 deletions
BIN
tests/__pycache__/test_formatter.cpython-313-pytest-8.3.5.pyc
Normal file
BIN
tests/__pycache__/test_formatter.cpython-313-pytest-8.3.5.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_identifiers.cpython-313-pytest-8.3.5.pyc
Normal file
BIN
tests/__pycache__/test_identifiers.cpython-313-pytest-8.3.5.pyc
Normal file
Binary file not shown.
44
tests/test_formatter.py
Normal file
44
tests/test_formatter.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
from citer.formatter import format_apa
|
||||
from citer.models import Author, WorkMetadata
|
||||
|
||||
|
||||
def test_format_doi_article():
|
||||
metadata = WorkMetadata(
|
||||
title="Sample study on testing",
|
||||
authors=[Author("Jane", "Doe"), Author("John", "Smith")],
|
||||
year=2020,
|
||||
container_title="Journal of Tests",
|
||||
volume="12",
|
||||
issue="3",
|
||||
pages="45-67",
|
||||
doi="10.1234/example.doi",
|
||||
url="https://doi.org/10.1234/example.doi",
|
||||
source="doi",
|
||||
identifier="10.1234/example.doi",
|
||||
)
|
||||
|
||||
citation = format_apa(metadata)
|
||||
assert (
|
||||
citation
|
||||
== "Doe, J., & Smith, J. (2020). Sample study on testing. "
|
||||
"Journal of Tests, 12(3), 45-67. https://doi.org/10.1234/example.doi"
|
||||
)
|
||||
|
||||
|
||||
def test_format_arxiv_preprint():
|
||||
metadata = WorkMetadata(
|
||||
title="Deep learning for cats",
|
||||
authors=[Author("Alice", "Nguyen"), Author("Bob", "Smith")],
|
||||
year=2021,
|
||||
container_title="arXiv preprint",
|
||||
url="https://arxiv.org/abs/2101.00001",
|
||||
source="arxiv",
|
||||
identifier="2101.00001",
|
||||
)
|
||||
|
||||
citation = format_apa(metadata)
|
||||
assert (
|
||||
citation
|
||||
== "Nguyen, A., & Smith, B. (2021). Deep learning for cats. "
|
||||
"arXiv preprint, arXiv:2101.00001. https://arxiv.org/abs/2101.00001"
|
||||
)
|
||||
25
tests/test_identifiers.py
Normal file
25
tests/test_identifiers.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import pytest
|
||||
|
||||
from citer.identifiers import normalize_arxiv_identifier, normalize_doi
|
||||
|
||||
|
||||
def test_normalize_arxiv_variants():
|
||||
assert normalize_arxiv_identifier("2106.01342v2") == "2106.01342"
|
||||
assert normalize_arxiv_identifier("https://arxiv.org/abs/2106.01342") == "2106.01342"
|
||||
assert normalize_arxiv_identifier("arXiv:hep-th/9901001") == "hep-th/9901001"
|
||||
|
||||
|
||||
def test_normalize_arxiv_invalid():
|
||||
with pytest.raises(Exception):
|
||||
normalize_arxiv_identifier("not-an-id")
|
||||
|
||||
|
||||
def test_normalize_doi_variants():
|
||||
assert normalize_doi("https://doi.org/10.1038/nphys1170") == "10.1038/nphys1170"
|
||||
assert normalize_doi("DOI:10.5555/12345678") == "10.5555/12345678"
|
||||
assert normalize_doi("10.1000/182") == "10.1000/182"
|
||||
|
||||
|
||||
def test_normalize_doi_invalid():
|
||||
with pytest.raises(Exception):
|
||||
normalize_doi("not-a-doi")
|
||||
Loading…
Add table
Add a link
Reference in a new issue