Commit adc62693 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Refactor the tests directory by class.

parent f49d5b68
......@@ -20,10 +20,9 @@ Note:
"""
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
from invenio_tools import CheckAndFix, load_record
CPPM_AUTHORS = [u"S. Akar",
u"E. Aslanides",
......
......@@ -16,11 +16,11 @@ Note:
* The submitted date is 05 Jan 2012
"""
import copy
import pytest
from helper import load_record
from invenio_tools import CheckAndFix
from harvest_tools import format_author_fr
from invenio_tools import CheckAndFix, load_record
@pytest.fixture(scope="module")
......@@ -33,22 +33,39 @@ def record():
return rec
def test_authors(record):
@pytest.fixture(scope="module")
def recordfix(record):
svc = CheckAndFix()
rec = copy.deepcopy(record)
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, recordfix):
assert record.authors() == ""
assert recordfix.authors() == "O. Leroy"
def test_collaboration(record):
assert record.collaboration() == ""
def test_conference_dates(record):
assert record.conference_dates() == "6-11 Dec 2010"
def test_conference_country(record):
assert record.conference_country() == "Italy"
def test_conference_dates(record):
assert record.conference_dates() == "6-11 Dec 2010"
def test_conference_key(record):
assert record.conference_key() == "rome20101206"
......@@ -73,12 +90,14 @@ def test_conference_year(record):
assert record.conference_year() == "2010"
def test_first_author(record):
def test_first_author(record, recordfix):
assert record.first_author() == "Leroy, Olivier"
assert recordfix.first_author() == "O. Leroy"
def test_first_institutes(record):
def test_first_institutes(record, recordfix):
assert record.first_author_institutes() == "Marseille, CPPM"
assert recordfix.first_author_institutes() == "Marseille, CPPM"
def test_host(record):
......@@ -89,12 +108,13 @@ def test_id(record):
assert record.id() == "1411352"
def test_institutes(record):
institutes = record.institutes()
def test_institutes(record, recordfix):
assert record.institutes() == []
assert record.is_institute_defined() == False
assert recordfix.institutes() == ["Marseille, CPPM"]
assert recordfix.is_institute_defined() == True
def test_is_proceeding(record):
assert record.is_conference_data() == True
......@@ -122,8 +142,9 @@ def test_preprint_number(record):
assert record.preprint_number() == ""
def test_submitted(record):
def test_submitted(record, recordfix):
assert record.submitted() == ["05 Jan 2012"]
assert recordfix.submitted() == ["2012-01-05"]
def test_reference_conference_id(record):
......@@ -150,5 +171,6 @@ def test_title(record):
assert record.title() == "Prospects for CP violation in $B^0_s \\to J/\psi\phi$ from first LHCb data"
def test_year(record):
def test_year(record, recordfix):
assert record.year() == "2011"
assert recordfix.year() == "2011"
......@@ -19,11 +19,12 @@ Note:
* Year is not defined
"""
import copy
import pytest
from helper import load_record
from invenio_tools import CheckAndFix
from harvest_tools import format_author_fr
from invenio_tools import CheckAndFix, CheckException, load_record
@pytest.fixture(scope="module")
......@@ -36,20 +37,42 @@ def record():
return rec
def test_authors(record):
@pytest.fixture(scope="module")
def recordfix(record):
svc = CheckAndFix()
rec = copy.deepcopy(record)
svc.authors(rec)
svc.format_authors(rec, format_author_fr)
svc.format_editor(rec)
svc.submitted(rec)
svc.year(rec)
return rec
def test_authors(record, recordfix):
assert record.authors() == ""
assert recordfix.authors() == "F. Hubaut"
def test_collaboration(record):
assert record.collaboration() == "ATLAS"
def test_conference_country(record):
assert record.conference_country() == "Italy"
def test_conference_dates(record):
assert record.conference_dates() == "2-9 Mar 2013"
def test_conference_country(record):
assert record.conference_country() == "Italy"
def test_collaboration_exception(recordfix):
svc = CheckAndFix()
with pytest.raises(CheckException):
svc.collaboration(recordfix)
def test_conference_key(record):
......@@ -105,6 +128,12 @@ def test_is_proceeding(record):
assert record.is_thesis() == False
def test_my_authors_exception(recordfix):
svc = CheckAndFix()
with pytest.raises(CheckException):
svc.my_authors(recordfix)
def test_oai(record):
assert record.oai() == "oai:inspirehep.net:1276938"
assert record.oai_url() == "http://inspirehep.net/record/1276938"
......@@ -125,10 +154,6 @@ def test_preprint_number(record):
assert record.preprint_number() == ""
def test_submitted(record):
assert record.submitted() == []
def test_reference_conference_id(record):
assert record.reference_conference_id() == ""
......@@ -149,9 +174,16 @@ def test_report_number(record):
assert record.report_number() == ""
def test_submitted(record, recordfix):
assert record.submitted() == []
assert recordfix.submitted() == ["2013-03-02"]
def test_title(record):
assert record.title() == "ATLAS studies on Higgs to diboson states"
def test_year(record):
def test_year(record, recordfix):
assert record.year() == ""
assert recordfix.year() == "2013"
......@@ -16,8 +16,7 @@ Note:
import pytest
from helper import load_record
from invenio_tools import CheckAndFix
from invenio_tools import CheckAndFix, load_record
@pytest.fixture(scope="module")
......
......@@ -17,8 +17,7 @@ Note:
import pytest
from helper import load_record
from invenio_tools import CheckAndFix, CheckException
from invenio_tools import CheckAndFix, CheckException, load_record
def test_country_exception():
......
......@@ -19,9 +19,9 @@ Note:
import pytest
from helper import load_record
from harvest_tools import format_author_fr
from invenio_tools import CheckAndFix
from invenio_tools import CheckAndFix, load_record
@pytest.fixture(scope="module")
def record():
......
# -*- coding: utf-8 -*-
"""Test checkandfix
"""CheckAndfix non conformities
Test some of the recovery mechanism of the CheckAndFix class
Test some of the recovery mechanisms implement in the CheckAndFix class.
"""
import pytest
from helper import load_record
from invenio_tools import CheckAndFix, CheckException
from invenio_tools import CheckAndFix, CheckException, load_record
def test_collaboration_exception():
......
# -*- coding: utf-8 -*-
"""test basic functionalities:
* download a record from a store
* format the author name
"""http://cds.cern.ch/record1951625
"""
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"
from invenio_tools import InvenioStore
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 -*-
"""http://cds.cern.ch/record/1951625
"""
from invenio_tools import load_record, Record
def test_call():
rep = load_record('cds.cern.ch', 1951625)
assert isinstance(rep, Record)
......@@ -23,7 +23,7 @@ Note:
import pytest
from helper import load_record
from invenio_tools import load_record
@pytest.fixture(scope="module")
......
......@@ -22,7 +22,7 @@ Note:
import pytest
from helper import load_record
from invenio_tools import load_record
@pytest.fixture(scope="module")
......
# -*- coding: utf-8 -*-
"""test protection
"""Record non conformities
From time to time some record keys are duplicated.
Protection are add in the record method to correct them
"""
from helper import load_record
from invenio_tools import load_record
def test_protection_host():
......
......@@ -20,7 +20,7 @@ Note:
import pytest
from helper import load_record
from invenio_tools import load_record
@pytest.fixture(scope="module")
......
# -*- coding: utf-8 -*-
"""test basic harvester functions
"""
from harvest_tools import format_author_fr
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"
# -*- 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 -*-
"""PROCEEDING
http://cds.cern.ch/record/1411352
Prospects for CP violation in B0s --> J/psiphi from first LHCb data
O. Leroy, Symposium on Prospects in the Physics of Discrete Symmetries,
Rome, Italy, 6 - 11 Dec 2010
J. Phys.: Conf. Ser. 335 (2011) 012042
Corrections are applied to the record.
Note:
* Only the first authors is defined
* The submitted date is 05 Jan 2012
"""
import pytest
from helper import load_record
from harvest_tools import format_author_fr
from invenio_tools import CheckAndFix
@pytest.fixture(scope="module")
def record():
rec = load_record('cds.cern.ch', 1411352)
svc = CheckAndFix()
svc.conference(rec)
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):
assert record.authors() == "O. Leroy"
def test_first_author(record):
assert record.first_author() == "O. Leroy"
def test_first_institutes(record):
assert record.first_author_institutes() == "Marseille, CPPM"
def test_institutes(record):
institutes = record.institutes()
assert record.institutes() == ["Marseille, CPPM"]
assert record.is_institute_defined() == True
def test_submitted(record):
assert record.submitted() == ["2012-01-05"]
def test_year(record):
assert record.year() == "2011"
# -*- coding: utf-8 -*-
"""PROCEEDING
http://inspirehep.net/record/1276938
ATLAS studies on Higgs to diboson states
F Hubaut for the Atlas collaboration
48th Rencontres de Moriond on Electroweak Interactions and Unified Theories
La Thuile, Italy, 2-9 Mar 2013
Corrections are applied to the record.
Note:
* Only first author is defined
* Collaboration is not well formed ATLAS
* Conference year is not defined
* First author affiliation is not defined
* Submitted date is not defined
* Year is not defined
"""
import pytest
from helper import load_record
from harvest_tools import format_author_fr
from invenio_tools import CheckAndFix, CheckException
@pytest.fixture(scope="module")
def record():
rec = load_record('inspirehep.net', 1276938)
svc = CheckAndFix()
svc.conference(rec)
svc.authors(rec)
svc.format_authors(rec, format_author_fr)
svc.format_editor(rec)
svc.submitted(rec)
svc.year(rec)
return rec
def test_my_authors_exception(record):
svc = CheckAndFix()
with pytest.raises(CheckException):
svc.my_authors(record)
def test_collaboration_exception(record):
svc = CheckAndFix()
with pytest.raises(CheckException):
svc.collaboration(record)
def test_authors(record):
assert record.authors() == "F. Hubaut"
def test_submitted(record):
assert record.submitted() == ["2013-03-02"]
def test_year(record):
assert record.year() == "2013"
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