|
| 1 | +import os |
| 2 | +from functools import lru_cache |
| 3 | + |
| 4 | +import pytest |
| 5 | +from cffconvert import Citation |
| 6 | +from cffconvert.lib.cff_1_2_x.apalike import ApalikeObject |
| 7 | + |
| 8 | +from tests.lib.contracts.apalike import Contract |
| 9 | + |
| 10 | + |
| 11 | +@lru_cache |
| 12 | +def apalike_object(): |
| 13 | + fixture = os.path.join(os.path.dirname(__file__), "CITATION.cff") |
| 14 | + with open(fixture, "rt", encoding="utf-8") as f: |
| 15 | + cffstr = f.read() |
| 16 | + citation = Citation(cffstr) |
| 17 | + return ApalikeObject(citation.cffobj, initialize_empty=True) |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.lib |
| 21 | +@pytest.mark.apalike |
| 22 | +class TestApalikeObject(Contract): |
| 23 | + |
| 24 | + def test_as_string(self): |
| 25 | + actual_apalike = apalike_object().add_all().as_string() |
| 26 | + fixture = os.path.join(os.path.dirname(__file__), "apalike.txt") |
| 27 | + with open(fixture, "rt", encoding="utf-8") as f: |
| 28 | + expected_apalike = f.read() |
| 29 | + assert actual_apalike == expected_apalike |
| 30 | + |
| 31 | + def test_author(self): |
| 32 | + assert apalike_object().add_author().author == "The name." |
| 33 | + |
| 34 | + def test_check_cffobj(self): |
| 35 | + apalike_object().check_cffobj() |
| 36 | + # doesn't need an assert |
| 37 | + |
| 38 | + def test_doi(self): |
| 39 | + assert apalike_object().add_doi().doi is None |
| 40 | + |
| 41 | + def test_title(self): |
| 42 | + assert apalike_object().add_title().title == "The title [Computer software]." |
| 43 | + |
| 44 | + def test_url(self): |
| 45 | + assert apalike_object().add_url().url is None |
| 46 | + |
| 47 | + def test_year(self): |
| 48 | + assert apalike_object().add_year().year is None |
0 commit comments