| import pytest |
| from astroparse_api.references import parse_references, _build_bibcode |
|
|
| |
| REF_APJL = ( |
| "Carnall, A. C., McLure, R. J., Dunlop, J. S., & Davé, R. 2018, " |
| "ApJL, 873, L14. doi:10.3847/2041-8213/ab0a7e" |
| ) |
| REF_MNRAS = ( |
| "Schreiber, C., Glazebrook, K., & Nanayakkara, T. 2018, MNRAS, 489, 3023. " |
| "arXiv:1906.08978" |
| ) |
| REF_ARXIV_ONLY = ( |
| "Weibel, A., Oesch, P. A., Barrufet, L. et al. 2024, arXiv:2409.03829" |
| ) |
|
|
| CORPUS_ARXIV = {"1906.08978", "2409.03829"} |
| CORPUS_BIBCODES = {"2018ApJ...873L..14C"} |
|
|
|
|
| def test_parse_references_extracts_year(): |
| refs, _ = parse_references(REF_APJL + "\n\n" + REF_MNRAS, set(), set()) |
| years = {r.year for r in refs} |
| assert 2018 in years |
|
|
|
|
| def test_parse_references_extracts_arxiv(): |
| refs, _ = parse_references(REF_MNRAS, CORPUS_ARXIV, set()) |
| assert refs[0].arxiv == "1906.08978" |
|
|
|
|
| def test_arxiv_match_sets_corpus_match(): |
| refs, _ = parse_references(REF_MNRAS, CORPUS_ARXIV, set()) |
| assert refs[0].corpus_match is True |
|
|
|
|
| def test_no_arxiv_no_bibcode_match_is_display_only(): |
| refs, _ = parse_references(REF_APJL, set(), set()) |
| assert refs[0].corpus_match is False |
|
|
|
|
| def test_bibcode_construction_apjl(): |
| bc = _build_bibcode("2018", "ApJL", "873", "L14", "C") |
| assert bc == "2018ApJ...873L..14C" |
|
|
|
|
| def test_bibcode_construction_mnras(): |
| bc = _build_bibcode("2018", "MNRAS", "489", "3023", "S") |
| assert bc == "2018MNRAS.489.3023S" |
|
|
|
|
| def test_cite_index_built(): |
| _, idx = parse_references(REF_APJL + "\n\n" + REF_ARXIV_ONLY, set(), set()) |
| keys = list(idx.keys()) |
| assert any("carnall" in k for k in keys) |
| assert any("weibel" in k for k in keys) |
|
|
|
|
| def test_multiple_refs_same_author_year_both_indexed(): |
| ref_a = "Smith, J. A. 2020, ApJ, 900, 1" |
| ref_b = "Smith, J. B. 2020, ApJ, 901, 5" |
| _, idx = parse_references(ref_a + "\n\n" + ref_b, set(), set()) |
| keys = list(idx.keys()) |
| assert any("smith" in k for k in keys) |
|
|
|
|
| def test_empty_raw_refs_returns_empty(): |
| refs, idx = parse_references("", set(), set()) |
| assert refs == [] |
| assert idx == {} |
|
|
|
|
| def test_bibcode_match_sets_corpus_match(): |
| refs, _ = parse_references(REF_APJL, set(), CORPUS_BIBCODES) |
| assert refs[0].corpus_match is True |
| assert refs[0].bibcode == "2018ApJ...873L..14C" |
|
|