summaryrefslogtreecommitdiffstats
path: root/python/tests/transform_csl.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-03-18 14:48:06 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-03-18 14:48:06 -0700
commit704ea367439f6faf88343b5ee50a438900c96aca (patch)
tree40463ae5d540d768eec77c4522589d6b95edf3f0 /python/tests/transform_csl.py
parentf05b1c823be23b0bc3885199aaca51137e6a22d3 (diff)
downloadfatcat-704ea367439f6faf88343b5ee50a438900c96aca.tar.gz
fatcat-704ea367439f6faf88343b5ee50a438900c96aca.zip
refactor and test citeproc code
Diffstat (limited to 'python/tests/transform_csl.py')
-rw-r--r--python/tests/transform_csl.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/python/tests/transform_csl.py b/python/tests/transform_csl.py
new file mode 100644
index 00000000..43f7a99d
--- /dev/null
+++ b/python/tests/transform_csl.py
@@ -0,0 +1,62 @@
+
+import json
+import pytest
+from fatcat_tools import *
+from fatcat_client import *
+
+from fixtures import api
+from import_crossref import crossref_importer
+
+def test_csl_crossref(crossref_importer):
+ with open('tests/files/crossref-works.single.json', 'r') as f:
+ # not a single line
+ raw = json.loads(f.read())
+ r = crossref_importer.parse_record(raw)
+ # this work has some null contrib names; these should cause errors
+ with pytest.raises(ValueError):
+ release_to_csl(r)
+ with pytest.raises(ValueError):
+ csl = release_to_csl(r)
+ citeproc_csl(csl, 'csl-json')
+ # set with dummy so we can run other tests
+ for c in r.contribs:
+ if not c.raw_name:
+ c.raw_name = "dummy"
+ csl = release_to_csl(r)
+ citeproc_csl(csl, 'csl-json')
+ citeproc_csl(csl, 'bibtex')
+ citeproc_csl(csl, 'harvard1')
+ citeproc_csl(csl, 'harvard1', html=True)
+
+def test_csl_pubmed(crossref_importer):
+ with open('tests/files/example_releases_pubmed19n0972.json', 'r') as f:
+ # multiple single lines
+ for line in f:
+ r = entity_from_json(line, ReleaseEntity)
+ csl = release_to_csl(r)
+ citeproc_csl(csl, 'csl-json')
+ citeproc_csl(csl, 'bibtex')
+ citeproc_csl(csl, 'harvard1')
+ citeproc_csl(csl, 'harvard1', html=True)
+
+def test_csl_pubmed_bibtex(crossref_importer):
+ with open('tests/files/example_releases_pubmed19n0972.json', 'r') as f:
+ r = entity_from_json(f.readline(), ReleaseEntity)
+ csl = release_to_csl(r)
+ print(citeproc_csl(csl, 'bibtex'))
+ # XXX: what's with the '`' in volume?
+ assert citeproc_csl(csl, 'bibtex').strip() == """
+@article{mędrela-kuder_szymura_2018,
+ title={Selected anti-health behaviours among women with osteoporosis},
+ volume={69`},
+ ISSN={0035-7715},
+ DOI={10.32394/rpzh.2018.0046},
+ abstractNote={In the prevention of osteoporosis and its treatment, it is important to prevent bone loss by reducing the occurrence of factors determining human health, which reduce the risk of osteoporosis, such as health behaviors.},
+ number={4},
+ journal={Roczniki Panstwowego Zakladu Higieny},
+ author={Mędrela-Kuder and Szymura},
+ year={2018}}
+ """.strip()
+ assert citeproc_csl(csl, 'harvard1', html=True).strip() == """
+ Mędrela-Kuder &amp; Szymura, 2018. Selected anti-health behaviours among women with osteoporosis. <i>Roczniki Panstwowego Zakladu Higieny</i>, 69`(4).
+ """.strip()