Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
limbra
limbra
Commits
66288cd2
Commit
66288cd2
authored
Jun 20, 2017
by
LE GAC Renaud
Browse files
Update invenio_tools to add the factory function build_record.
parent
9b4a0fdb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
160 deletions
+57
-160
modules/invenio_tools/__init__.py
modules/invenio_tools/__init__.py
+14
-14
modules/invenio_tools/factory.py
modules/invenio_tools/factory.py
+39
-0
tests/basis/test_02_record_factory.py
tests/basis/test_02_record_factory.py
+4
-3
tests/invenio_tools/Record/test_acl_cds1951625.py
tests/invenio_tools/Record/test_acl_cds1951625.py
+0
-143
No files found.
modules/invenio_tools/__init__.py
View file @
66288cd2
...
...
@@ -26,6 +26,7 @@ from .exception import (CdsException,
RecordException
,
XmlException
)
from
.factory
import
build_record
from
.inveniostore
import
InvenioStore
from
.iterrecord
import
IterRecord
,
REG_INT
from
.marc12
import
Marc12
...
...
@@ -40,24 +41,23 @@ def load_record(host, record_id):
"""Helper function to load a single record from an invenio store.
Args:
host (str): host of the store.
Possible values are ``cds.cern.ch`` or ``inspirehep.net``.
record_id (int): the record identifier in the store
host (str):
host of the store. Possible values are ``cds.cern.ch``
or ``inspirehep.net``.
record_id (int):
the record identifier in the store
Returns:
Record or None: the decoded record when it exist, ``None`` otherwise.
Record:
either RecordPubli, RecordInst, RecordConf of RecordThesis.
Raises:
CdsException: when the server return an HTTP error.
Marc12Exception: when a record is not well formed XML.
CdsException:
* the server return an HTTP error.
* no JSON object could be decoded.
"""
store
=
InvenioStore
(
host
)
xml
=
store
.
get_record
(
record_id
)
svc
=
Marc12
()
records
=
svc
(
xml
)
if
len
(
records
)
>
0
:
return
records
[
0
]
return
None
recjson
=
store
.
get_record
(
record_id
)
return
build_record
(
recjson
)
modules/invenio_tools/factory.py
0 → 100644
View file @
66288cd2
# -*- coding: utf-8 -*-
""" invenio_tools.factory
"""
from
base
import
is_conference
,
is_institute
,
is_thesis
from
recordconf
import
RecordConf
from
recordinst
import
RecordInst
from
recordpubli
import
RecordPubli
from
recordthesis
import
RecordThesis
def
build_record
(
rec_json
):
"""Transform a JSON object into a record
Args:
rec_json (dict):
record data in a JSON format.
Return
Record:
either RecordConf, RecordInst, RecodPubli or RecordThesis
Raises:
"""
if
is_conference
(
rec_json
):
upcast_record
=
RecordConf
(
rec_json
)
# self._add_conference_data(upcast_record)
elif
is_institute
(
rec_json
):
upcast_record
=
RecordInst
(
rec_json
)
elif
is_thesis
(
rec_json
):
upcast_record
=
RecordThesis
(
rec_json
)
else
:
upcast_record
=
RecordPubli
(
rec_json
)
return
upcast_record
tests/basis/test_02_
R
ecord.py
→
tests/basis/test_02_
r
ecord
_factory
.py
View file @
66288cd2
# -*- coding: utf-8 -*-
"""test_
instantiate_Record
"""test_
02_record_factory
* Test
function
s to introspect the type of record.
* Test
function
s to upcast the Record from the JSON object.
* Test
tool
s to introspect the type of record.
* Test
tool
s to upcast the Record from the JSON object.
"""
from
invenio_tools.base
import
is_conference
,
is_institute
,
is_thesis
...
...
@@ -93,6 +93,7 @@ def test_talk_cds():
record
=
build_record
(
recjson
)
assert
isinstance
(
record
,
RecordConf
)
def
test_thesis_cds
():
store
=
InvenioStore
(
"cds.cern.ch"
)
...
...
tests/invenio_tools/Record/test_acl_cds1951625.py
deleted
100644 → 0
View file @
9b4a0fdb
"""ARTICLE
http://cds.cern.ch/record/1951625.
(same as http://inspirehep.net/record/1319638)
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
invenio_tools
import
load_record
,
RecordPubli
@
pytest
.
fixture
(
scope
=
"module"
)
def
record
():
return
load_record
(
'cds.cern.ch'
,
1951625
)
def
test_affiliations
(
record
):
assert
record
.
is_affiliations
()
==
True
assert
record
.
is_affiliation_for_all
()
==
True
institutes
=
record
.
institutes
()
assert
institutes
[
0
]
==
"AGH-UST, Cracow"
assert
institutes
[
44
]
==
"MIT"
assert
institutes
[
-
1
]
==
"Zurich U."
def
test_authors
(
record
):
assert
record
.
is_authors
()
==
True
authors
=
record
.
authors_as_list
()
assert
len
(
authors
)
==
704
assert
authors
[
0
]
==
"Aaij, Roel"
assert
authors
[
1
]
==
"Adeva, Bernardo"
assert
authors
[
344
]
==
"Le Gac, Renaud"
assert
authors
[
-
1
]
==
"Zvyagin, Alexander"
def
test_collaboration
(
record
):
assert
record
.
collaboration
()
==
"LHCb Collaboration"
def
test_find_affiliation
(
record
):
affiliation
=
record
.
find_affiliation
(
r
"Marseille, CPPM|CPPM, Marseille"
)
assert
affiliation
==
"Marseille, CPPM"
def
test_find_authors
(
record
):
assert
record
.
find_authors
(
"Leo"
)
==
"Beaucourt, Leo, Kravchuk, Leonid, Leo, Sabato"
def
test_find_authors_by_affiliation
(
record
):
pattern
=
"CPPM, Marseille|Marseille, CPPM"
authors
=
record
.
find_authors_by_affiliation
(
pattern
,
sep
=
"|"
)
assert
authors
==
"Akar, Simon|Aslanides, Elie|Cogan, Julien|"
\
"Kanso, Walaa|Le Gac, Renaud|Leroy, Olivier|"
\
"Mancinelli, Giampiero|Mordà, Alessandro|"
\
"Perrin-Terrin, Mathieu|Serrano, Justine|"
\
"Tsaregorodtsev, Andrei"
def
test_first_author
(
record
):
assert
record
.
first_author
()
==
"Aaij, Roel"
def
test_first_author_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
len
(
institutes
)
==
90
assert
institutes
[
0
]
==
"AGH-UST, Cracow"
assert
institutes
[
-
1
]
==
"Zurich U."
def
test_is_article
(
record
):
assert
isinstance
(
record
,
RecordPubli
)
assert
record
.
is_published
()
==
True
def
test_oai
(
record
):
assert
record
.
oai
()
==
"oai:cds.cern.ch:1951625, oai:inspirehep.net:1319638"
assert
record
.
oai_url
()
==
"http://cds.cern.ch/record/1951625, http://inspirehep.net/record/1319638"
def
test_paper_reference
(
record
):
assert
record
.
paper_editor
()
==
"JINST"
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, CERN-PH-EP-2014-221, LHCB-PAPER-2014-047, LHCB-PAPER-2014-047"
def
test_title
(
record
):
assert
record
.
title
()
==
"Precision luminosity measurements at LHCb"
def
test_year
(
record
):
assert
record
.
year
()
==
"2014"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment