Skip to content

Commit d7a62c7

Browse files
author
Ang
committed
fix #34: strengthen tests with real content assertions; add proceedings mock
- test_input_formats: verify DOI appears in output, report.succeeded count - test_integration: verify title/author fields in conference paper output - test_python_api: fix empty-input test to expect ValidationError (code 1) - mock_responses: add MOCK_CROSSREF_PROCEEDINGS_RESPONSE for proceedings-article path - This also validates fix #28 works end-to-end (proceedings DOI resolves correctly) Closes #34
1 parent bcaa9af commit d7a62c7

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

tests/mock_responses.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@
5555
</feed>
5656
"""
5757

58+
# -- Crossref proceedings paper (10.5555/3295222.3295349, "Attention Is All You Need") --
59+
MOCK_CROSSREF_PROCEEDINGS_RESPONSE = {
60+
"status": "ok",
61+
"message-type": "work",
62+
"message": {
63+
"DOI": "10.5555/3295222.3295349",
64+
"type": "proceedings-article",
65+
"title": ["Attention Is All You Need"],
66+
"author": [
67+
{"given": "Ashish", "family": "Vaswani", "sequence": "first"},
68+
{"given": "Noam", "family": "Shazeer", "sequence": "additional"},
69+
{"given": "Niki", "family": "Parmar", "sequence": "additional"},
70+
],
71+
"container-title": ["Advances in Neural Information Processing Systems"],
72+
"published-print": {"date-parts": [[2017]]},
73+
"publisher": "Curran Associates Inc.",
74+
},
75+
}
76+
5877
# -- Crossref title search (used by _resolve_doi_via_crossref_title) ----------
5978
MOCK_CROSSREF_SEARCH_RESPONSE = {
6079
"status": "ok",
@@ -164,6 +183,10 @@ def mock_requests_get(url, *args, **kwargs):
164183
if "api.crossref.org" in url and "10.1038/nature14539" in url:
165184
return MockResponse(json_data=MOCK_CROSSREF_RESPONSE)
166185

186+
# Crossref: proceedings DOI from Attention-Is-All-You-Need fuzzy search result
187+
if "api.crossref.org" in url and "10.5555/3295222.3295349" in url:
188+
return MockResponse(json_data=MOCK_CROSSREF_PROCEEDINGS_RESPONSE)
189+
167190
# Crossref: title search (fuzzy-search path)
168191
if "api.crossref.org" in url and "query" in str(kwargs.get("params", "")):
169192
return MockResponse(json_data=MOCK_CROSSREF_SEARCH_RESPONSE)

tests/test_input_formats.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
class TestInputFormats:
99

1010
def test_plain_doi(self, sample_references, run_onecite_process):
11-
code, out, err, _ = run_onecite_process(sample_references["doi_only"], input_type="txt")
11+
code, out, err, result = run_onecite_process(sample_references["doi_only"], input_type="txt")
1212
assert code == 0, err
1313
assert "@article" in out or "@inproceedings" in out
14+
assert "10.1038/nature14539" in out, "DOI must appear in BibTeX output"
15+
assert result["report"]["succeeded"] >= 1
1416

1517
def test_multiline_txt(self, sample_references, run_onecite_process):
1618
"""Two refs separated by a blank line."""
@@ -20,20 +22,24 @@ def test_multiline_txt(self, sample_references, run_onecite_process):
2022
assert out.count("@") >= 1
2123

2224
def test_bibtex_input(self, sample_references, run_onecite_process):
23-
code, _, err, _ = run_onecite_process(sample_references["bibtex_entry"], input_type="bib")
25+
code, out, err, result = run_onecite_process(sample_references["bibtex_entry"], input_type="bib")
2426
assert code == 0, err
27+
assert result["report"]["total"] >= 1
28+
assert "@" in out, "BibTeX input should produce BibTeX output"
2529

2630
def test_doi_variants(self, run_onecite_process):
27-
"""All common DOI notations should be recognised."""
31+
"""All common DOI notations must resolve to the same paper."""
2832
for doi in (
2933
"10.1038/nature14539",
3034
"doi:10.1038/nature14539",
3135
"DOI: 10.1038/nature14539",
3236
"https://doi.org/10.1038/nature14539",
3337
):
34-
code, out, err, _ = run_onecite_process(doi, input_type="txt")
38+
code, out, err, result = run_onecite_process(doi, input_type="txt")
3539
assert code == 0, f"failed for {doi!r}: {err}"
3640
assert out.strip(), f"empty output for {doi!r}"
41+
assert "10.1038/nature14539" in out, f"{doi!r} did not produce correct DOI in output"
42+
assert result["report"]["succeeded"] == 1, f"{doi!r}: expected 1 succeeded"
3743

3844
def test_arxiv_variants(self, run_onecite_process):
3945
for arxiv in ("1706.03762", "arxiv:1706.03762", "arXiv:1706.03762",

tests/test_integration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ def test_readme_example(self, run_onecite_process):
2424
assert result["report"]["total"] >= 1
2525

2626
def test_doi_to_bibtex(self, run_onecite_process):
27-
code, _, err, result = run_onecite_process(
27+
code, out, err, result = run_onecite_process(
2828
"10.1038/nature14539\n\n1706.03762", output_format="bibtex"
2929
)
3030
assert code == 0, err
3131
self._check(result)
32+
assert "10.1038/nature14539" in out, "first DOI must appear in output"
33+
assert result["report"]["succeeded"] >= 1
3234

3335
def test_bib_to_bibtex(self, run_onecite_process):
3436
"""Round-trip: feed an existing .bib entry, get enriched BibTeX back."""
@@ -48,12 +50,14 @@ def test_bib_to_bibtex(self, run_onecite_process):
4850
self._check(result)
4951

5052
def test_conference_paper(self, run_onecite_process):
51-
code, _, err, result = run_onecite_process(
53+
code, out, err, result = run_onecite_process(
5254
"Attention is all you need\nVaswani et al.\nNIPS 2017",
5355
template="conference_paper",
5456
)
5557
assert code == 0, err
5658
self._check(result)
59+
assert "Attention" in out or "attention" in out, "title must appear in output"
60+
assert "Vaswani" in out or "vaswani" in out.lower(), "author must appear in output"
5761

5862
def test_arxiv(self, run_onecite_process):
5963
code, _, err, result = run_onecite_process("1706.03762\n\narxiv:1512.03385")

0 commit comments

Comments
 (0)