Commit 3b1f2ea6 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add pytests to validate the Record class on article.

parent 0a991072
# -*- coding: utf-8 -*-
""" helper module
A collection of functions for common tasks.
"""
from invenio_tools import InvenioStore, Marc12
def load_record(host, record_id):
"""Load a record from the store cds.cern.ch or inspirehep.net
"""
store = InvenioStore(host)
xml = store.get_record(record_id)
svc = Marc12()
return svc(xml)[0]
# -*- coding: utf-8 -*-
"""test basic functionalities:
* download a record from a store
* format the author name
"""
from harvest_tools import format_author_fr
from helper import load_record
from invenio_tools import InvenioStore, Record
def test_format_author():
assert format_author_fr("Aaij, Roel") == "R. Aaij"
assert format_author_fr("Le Gac, Renaud") == "R. Le Gac"
assert format_author_fr("Bettler, Marc-Olivier") == "M.-O. Bettler"
def test_get_record():
store = InvenioStore('cds.cern.ch')
xml = store.get_record(1951625)
assert isinstance(xml, str)
assert xml.startswith('<?xml version="1.0" encoding="UTF-8"?>\n'
'<collection xmlns="http://www.loc.gov/MARC21/slim">')
assert xml.endswith('</collection>')
def test_load_record():
rep = load_record('cds.cern.ch', 1951625)
assert isinstance(rep, Record)
# -*- coding: utf-8 -*-
"""ARTICLE
http://cds.cern.ch/record/1951625.
Precision luminosity measurements at LHCb,
J. Instrum. 9 (2014) P12005
arXiv:1410.0149
704 authors
No correction are applied to the record.
Allow to test the brut force decoding with its mistakes.
Note:
* The first author is not in the author list
* LHCb collaboration
* The publication year is a list (duplicate 773y)
* The submitted date is not formatted: 01 Oct 2014
"""
import pytest
from helper import load_record
@pytest.fixture(scope="module")
def record():
return load_record('cds.cern.ch', 1951625)
def test_authors(record):
authors = record.authors_as_list()
assert len(authors) == 703
assert authors[0] == "Adeva, Bernardo"
assert authors[343] == "Le Gac, Renaud"
assert authors[-1] == "Zvyagin, Alexander"
def test_collaboration(record):
assert record.collaboration() == "LHCb Collaboration"
def test_first_author(record):
assert record.first_author() == "Aaij, Roel"
def test_first_institutes(record):
assert record.first_author_institutes() == "NIKHEF, Amsterdam"
def test_host(record):
assert record.host() == "cds.cern.ch"
def test_id(record):
assert record.id() == "1951625"
def test_institutes(record):
institutes = record.institutes()
assert institutes[0] == "AGH-UST, Cracow"
assert institutes[44] == "MIT"
assert institutes[-1] == "Zurich U."
assert record.is_institute_defined() == True
def test_is_article(record):
assert record.is_conference_data() == False
assert record.is_published() == True
assert record.is_thesis() == False
def test_oai(record):
assert record.oai() == "oai:cds.cern.ch:1951625"
assert record.oai_url() == "http://cds.cern.ch/record/1951625"
def test_paper_reference(record):
assert record.paper_editor() == "J. Instrum."
assert record.paper_pages() == "P12005"
assert record.paper_volume() == "9"
assert record.paper_year() == "2014"
def test_paper_url(record):
assert record.paper_url() == "http://arxiv.org/pdf/1410.0149.pdf"
def test_preprint_number(record):
assert record.preprint_number() == "arXiv:1410.0149"
def test_submitted(record):
assert record.submitted() == ["01 Oct 2014"]
def test_report_number(record):
assert record.report_number() == "CERN-PH-EP-2014-221, LHCB-PAPER-2014-047"
def test_title(record):
assert record.title() == "Precision luminosity measurements at LHCb"
def test_year(record):
assert record.year() == "2014"
# -*- coding: utf-8 -*-
"""ARTICLE
http://cds.cern.ch/record/1951625.
Precision luminosity measurements at LHCb,
J. Instrum. 9 (2014) P12005
arXiv:1410.0149
704 authors
The CheckAndFix correction are applied.
Only the changes are checked
Note:
* The first author is not in the author list
* LHCb collaboration
* The publication year is a list (duplicate 773y)
* The submitted date is not formatted: 01 Oct 2014
"""
import pytest
from helper import load_record
from gluon import current
from harvest_tools import family_name_fr, format_author_fr
from invenio_tools import CheckAndFix
CPPM_AUTHORS = [u"S. Akar",
u"E. Aslanides",
u"J. Cogan",
u"W. Kanso",
u"R. Le Gac",
u"O. Leroy",
u"G. Mancinelli",
u"A. Mordà",
u"M. Perrin-Terrin",
u"J. Serrano",
u"A. Tsaregorodtsev"]
@pytest.fixture(scope="module")
def record():
rec = load_record('cds.cern.ch', 1951625)
# apply all corrections for an article
svc = CheckAndFix()
svc.authors(rec)
svc.format_authors(rec, format_author_fr)
svc.format_editor(rec)
svc.my_authors(rec)
svc.submitted(rec)
svc.year(rec)
return rec
def test_authors(record):
authors = record.authors_as_list()
assert len(authors) == 704
assert authors[0] == "R. Aaij"
assert authors[55] == "M.-O. Bettler"
assert authors[344] == "R. Le Gac"
assert authors[-1] == "A. Zvyagin"
def test_find_authors_by_institute(record):
rex = current.app.reg_institute
assert rex == "CPPM"
authors = record.find_authors_by_institute(rex, family_name_fr)
authors = authors.split(", ")
assert authors == CPPM_AUTHORS
def test_first_author(record):
assert record.first_author() == "R. Aaij"
def test_my_authors(record):
assert record.my_authors.split(', ') == CPPM_AUTHORS
def test_paper_editor(record):
assert record.paper_editor() == "J Instrum"
def test_submitted(record):
assert record.submitted() == ["2014-10-01"]
# -*- coding: utf-8 -*-
"""test protection
From time to time some record keys are duplicated.
Protection are add in the record method to correct them
"""
from helper import load_record
def test_protection_paper_year():
record = load_record('cds.cern.ch', 1951625)
assert record["773"]["y"] == ["2014", "2014"]
assert record.paper_year() == "2014"
def test_protection_paper_url():
record = load_record('cds.cern.ch', 2014733)
assert record.paper_url() == "http://arxiv.org/pdf/1505.01654"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment