def test_languages_from_041__a_handles_multiple_languages_in_one_a(): schema = load_schema('hep') subschema = schema['properties']['languages'] snippet = ('<datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">Russian / English</subfield>' '</datafield>') # record/116959 expected = [ 'ru', 'en', ] result = hep.do(create_record(snippet)) assert validate(result['languages'], subschema) is None assert expected == result['languages'] expected = [ { 'a': 'russian' }, { 'a': 'english' }, ] result = hep2marc.do(result) assert expected == result['041']
def test_external_system_numbers_from_035__a_d_h_m_9(): schema = load_schema('hep') subschema = schema['properties']['external_system_identifiers'] snippet = ( '<datafield tag="035" ind1=" " ind2=" ">' ' <subfield code="9">http://cds.cern.ch/oai2d</subfield>' ' <subfield code="a">oai:cds.cern.ch:325030</subfield>' ' <subfield code="d">2015-06-05T13:24:42Z</subfield>' ' <subfield code="h">2015-11-09T16:22:48Z</subfield>' ' <subfield code="m">marcxml</subfield>' '</datafield>' ) # record/1403324 expected = [ { 'value': 'oai:cds.cern.ch:325030', 'schema': 'http://cds.cern.ch/oai2d', } ] result = hep.do(create_record(snippet)) assert validate(result['external_system_identifiers'], subschema) is None assert expected == result['external_system_identifiers'] expected = [ { '9': 'http://cds.cern.ch/oai2d', 'a': 'oai:cds.cern.ch:325030', }, ] result = hep2marc.do(result) assert expected == result['035']
def test_report_numbers_from_037__z_9(): schema = load_schema('hep') subschema = schema['properties']['report_numbers'] snippet = ( '<datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="9">SLAC</subfield>' ' <subfield code="a">SLAC-PUB-16140</subfield>' '</datafield>' ) # record/1326454 expected = [ { 'source': 'SLAC', 'value': 'SLAC-PUB-16140', }, ] result = hep.do(create_record(snippet)) assert validate(result['report_numbers'], subschema) is None assert expected == result['report_numbers'] expected = [ { '9': 'SLAC', 'a': 'SLAC-PUB-16140', }, ] result = hep2marc.do(result) assert expected == result['037']
def test_isbns_from_020__a_b_normalizes_print(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ( '<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">9781786341105</subfield>' ' <subfield code="b">Print</subfield>' '</datafield>' ) # record/1509456 expected = [ { 'value': '9781786341105', 'medium': 'print', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '9781786341105', 'b': 'print', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_dois_from_0247_a_2_double_9_ignores_curator_source(): schema = load_schema('hep') subschema = schema['properties']['dois'] snippet = ( '<datafield tag="024" ind1="7" ind2=" ">' ' <subfield code="2">DOI</subfield>' ' <subfield code="9">bibcheck</subfield>' ' <subfield code="9">CURATOR</subfield>' ' <subfield code="a">10.1590/S1806-11172008005000006</subfield>' '</datafield>' ) # record/1117362 expected = [ { 'source': 'bibcheck', 'value': '10.1590/S1806-11172008005000006', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['dois'], subschema) is None assert expected == result['dois'] expected = [ { 'a': '10.1590/S1806-11172008005000006', '9': 'bibcheck', '2': 'DOI', }, ] result = hep2marc.do(result) assert expected == result['0247']
def test_urls_from_8564_u_w_y_ignores_w(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="w">12-316</subfield>' ' <subfield code="y">FERMILABPUB</subfield>' ' <subfield code="u">http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316</subfield>' '</datafield>') # record/1120360 expected = [ { 'description': 'FERMILABPUB', 'value': 'http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316', 'y': 'FERMILABPUB', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_title_translations_from_242__a(stable_langdetect): schema = load_schema('hep') subschema = schema['properties']['title_translations'] snippet = ( '<datafield tag="242" ind1=" " ind2=" ">' ' <subfield code="a">The redshift of extragalactic nebulae</subfield>' '</datafield>' ) # record/8352 expected = [ { 'language': 'en', 'title': 'The redshift of extragalactic nebulae', }, ] result = hep.do(create_record(snippet)) assert validate(result['title_translations'], subschema) is None assert expected == result['title_translations'] expected = [ { 'a': 'The redshift of extragalactic nebulae', }, ] result = hep2marc.do(result) assert expected == result['242']
def test_titles_from_245__a_9(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ( '<datafield tag="245" ind1=" " ind2=" ">' ' <subfield code="a">Exact Form of Boundary Operators Dual to ' 'Interacting Bulk Scalar Fields in the AdS/CFT Correspondence</subfield>' ' <subfield code="9">arXiv</subfield>' '</datafield>') # record/001511698 expected = [ { 'title': 'Exact Form of Boundary Operators Dual to Interacting ' 'Bulk Scalar Fields in the AdS/CFT Correspondence', 'source': 'arXiv', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Exact Form of Boundary Operators Dual to Interacting ' 'Bulk Scalar Fields in the AdS/CFT Correspondence', '9': 'arXiv', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_titles_from_246__a_9(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ('<datafield tag="246" ind1=" " ind2=" ">' ' <subfield code="a">Superintegrable relativistic systems in' ' spacetime-dependent background fields</subfield>' ' <subfield code="9">arXiv</subfield>' '</datafield>') # record/1511471 expected = [ { 'source': 'arXiv', 'title': 'Superintegrable relativistic systems in ' 'spacetime-dependent background fields', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Superintegrable relativistic systems in spacetime-dependent background fields', '9': 'arXiv', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_title_translations_from_242__a(): schema = load_schema('hep') subschema = schema['properties']['title_translations'] snippet = ( '<datafield tag="242" ind1=" " ind2=" ">' ' <subfield code="a">The redshift of extragalactic nebulae</subfield>' '</datafield>') # record/8352 expected = [ { 'language': 'en', 'title': 'The redshift of extragalactic nebulae', }, ] result = hep.do(create_record(snippet)) assert validate(result['title_translations'], subschema) is None assert expected == result['title_translations'] expected = [ { 'a': 'The redshift of extragalactic nebulae', }, ] result = hep2marc.do(result) assert expected == result['242']
def test_title_translations_from_242__a_b(): schema = load_schema('hep') subschema = schema['properties']['title_translations'] snippet = ( '<datafield tag="242" ind1=" " ind2=" ">' ' <subfield code="a">Generalized Hamilton-Jacobi Formalism</subfield>' ' <subfield code="b">Field Theories with Upper-Order Derivatives</subfield>' '</datafield>') # record/1501064 expected = [ { 'language': 'en', 'title': 'Generalized Hamilton-Jacobi Formalism', 'subtitle': 'Field Theories with Upper-Order Derivatives', }, ] result = hep.do(create_record(snippet)) assert validate(result['title_translations'], subschema) is None assert expected == result['title_translations'] expected = [ { 'a': 'Generalized Hamilton-Jacobi Formalism', 'b': 'Field Theories with Upper-Order Derivatives', }, ] result = hep2marc.do(result) assert expected == result['242']
def test_titles_from_245__a_b(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ( '<datafield tag="245" ind1=" " ind2=" ">' ' <subfield code="a">Proceedings, New Observables in Quarkonium Production</subfield>' ' <subfield code="b">Trento, Italy</subfield>' '</datafield>') # record/1510141 expected = [ { 'title': 'Proceedings, New Observables in Quarkonium Production', 'subtitle': 'Trento, Italy', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Proceedings, New Observables in Quarkonium Production', 'b': 'Trento, Italy', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_isbns_from_020__a_b_normalizes_print(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ('<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">9781786341105</subfield>' ' <subfield code="b">Print</subfield>' '</datafield>') # record/1509456 expected = [ { 'value': '978-1-78634-110-5', 'medium': 'print', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '978-1-78634-110-5', 'b': 'print', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_languages_from_double_041__a(): schema = load_schema('hep') subschema = schema['properties']['languages'] snippet = ('<record>' ' <datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">French</subfield>' ' </datafield>' ' <datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">German</subfield>' ' </datafield>' '</record>') # record/1231408 expected = [ 'fr', 'de', ] result = hep.do(create_record(snippet)) assert validate(result['languages'], subschema) is None assert expected == result['languages'] expected = [ { 'a': 'french' }, { 'a': 'german' }, ] result = hep2marc.do(result) assert expected == result['041']
def test_inspire_categories_from_65017a_2_9_converts_automatically_added(): schema = load_schema('elements/inspire_field') snippet = ( '<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="2">INSPIRE</subfield>' ' <subfield code="a">Instrumentation</subfield>' ' <subfield code="9">automatically added based on DCC, PPF, DK</subfield>' '</datafield>') # record/669400 expected = [ { 'source': 'curator', 'term': 'Instrumentation', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result, schema) is None assert expected == result['inspire_categories'] expected = [ { '9': 'curator', 'a': 'Instrumentation', }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_abstracts_from_520__a_9(): schema = load_schema('hep') subschema = schema['properties']['abstracts'] snippet = ( '<datafield tag="520" ind1=" " ind2=" ">' ' <subfield code="9">Springer</subfield>' ' <subfield code="a">We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.</subfield>' '</datafield>' ) # record/1346798 expected = [ { 'source': 'Springer', 'value': 'We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.', }, ] result = hep.do(create_record(snippet)) assert validate(result['abstracts'], subschema) is None assert expected == result['abstracts'] expected = [ { '9': 'Springer', 'a': 'We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.', }, ] result = hep2marc.do(result) assert expected == result['520']
def test_urls_from_8564_u_y(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="u">http://www-lib.kek.jp/ar/ar.html</subfield>' ' <subfield code="y">KEK</subfield>' '</datafield>') # record/1405358 expected = [ { 'description': 'KEK', 'value': 'http://www-lib.kek.jp/ar/ar.html', }, ] result = hep.do(create_record(snippet)) assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://www-lib.kek.jp/ar/ar.html', 'y': 'KEK', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_abstracts_from_520__double_a_ignores_second_a(): schema = load_schema('hep') subschema = schema['properties']['abstracts'] snippet = ( '<datafield tag="520" ind1=" " ind2=" ">' ' <subfield code="a">$D$ $K$ scattering and the $D_s$ spectrum from lattice QCD 520__</subfield>' ' <subfield code="a">We present results from Lattice QCD calculations of the low-lying charmed-strange meson spectrum using two types of Clover-Wilson lattices. In addition to quark-antiquark interpolating fields we also consider meson-meson interpolators corresponding to D-meson kaon scattering states. To calculate the all-to-all propagation necessary for the backtracking loops we use the (stochastic) distillation technique. For the charm quark we use the Fermilab method. Results for the $J^P=0^+$ $D_{s0}^*(2317)$ charmed-strange meson are presented.</subfield>' '</datafield>' ) # record/1297699 expected = [ {'value': '$D$ $K$ scattering and the $D_s$ spectrum from lattice QCD 520__'}, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['abstracts'], subschema) is None assert expected == result['abstracts'] expected = [ { 'a': '$D$ $K$ scattering and the $D_s$ spectrum from lattice QCD 520__', }, ] result = hep2marc.do(result) assert expected == result['520']
def test_acquisition_source_from_541__double_a_b_c_e(): schema = load_schema('elements/acquisition_source') snippet = ('<datafield tag="541" ind1=" " ind2=" ">' ' <subfield code="a">inspire:uid:52524</subfield>' ' <subfield code="a">orcid:0000-0002-1048-661X</subfield>' ' <subfield code="b">[email protected]</subfield>' ' <subfield code="c">submission</subfield>' ' <subfield code="e">504296</subfield>' '</datafield>') # record/1416571/export/xme expected = { 'source': 'orcid:0000-0002-1048-661X', 'email': '*****@*****.**', 'method': 'submission', 'submission_number': '504296', } result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['acquisition_source'], schema) is None assert expected == result['acquisition_source'] expected = { 'a': 'orcid:0000-0002-1048-661X', 'b': '*****@*****.**', 'c': 'submission', 'e': '504296', } result = hep2marc.do(result) assert expected == result['541']
def test_copyright_from_542__d_e_g(): schema = load_schema('hep') subschema = schema['properties']['copyright'] snippet = ( '<datafield tag="542" ind1=" " ind2=" ">' ' <subfield code="d">American Physical Society</subfield>' ' <subfield code="g">2017</subfield>' ' <subfield code="e">Article</subfield>' '</datafield>' ) # record/1511489 expected = [ {'holder': 'American Physical Society'}, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['copyright'], subschema) is None assert expected == result['copyright'] expected = [ {'d': 'American Physical Society'}, ] result = hep2marc.do(result) assert expected == result['542']
def test_titles_from_245__a_9(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ( '<datafield tag="245" ind1=" " ind2=" ">' ' <subfield code="a">Exact Form of Boundary Operators Dual to ' 'Interacting Bulk Scalar Fields in the AdS/CFT Correspondence</subfield>' ' <subfield code="9">arXiv</subfield>' '</datafield>' ) # record/001511698 expected = [ { 'title': 'Exact Form of Boundary Operators Dual to Interacting ' 'Bulk Scalar Fields in the AdS/CFT Correspondence', 'source': 'arXiv', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Exact Form of Boundary Operators Dual to Interacting ' 'Bulk Scalar Fields in the AdS/CFT Correspondence', '9': 'arXiv', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_public_notes_from_500__a_9(): schema = load_schema('hep') subschema = schema['properties']['public_notes'] snippet = ( '<datafield tag="500" ind1=" " ind2=" ">' ' <subfield code="9">arXiv</subfield>' ' <subfield code="a">5 pages</subfield>' '</datafield>' ) # record/1450044 expected = [ { 'source': 'arXiv', 'value': '5 pages', }, ] result = hep.do(create_record(snippet)) assert validate(result['public_notes'], subschema) is None assert expected == result['public_notes'] expected = [ { '9': 'arXiv', 'a': '5 pages', }, ] result = hep2marc.do(result) assert expected == result['500']
def test_isbns_from_020__a_b_normalizes_ebook(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ( '<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">9783319259017</subfield>' ' <subfield code="b">eBook</subfield>' '</datafield>' ) # record/1430829 expected = [ { 'value': '9783319259017', 'medium': 'online', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '9783319259017', 'b': 'online', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_hidden_notes_from_595__a_9(): schema = load_schema('hep') subschema = schema['properties']['hidden_notes'] snippet = ( '<datafield tag="595" ind1=" " ind2=" ">' ' <subfield code="9">SPIRES-HIDDEN</subfield>' ' <subfield code="a">Title changed from ALLCAPS</subfield>' '</datafield>' ) # record/109310 expected = [ { 'source': 'SPIRES-HIDDEN', 'value': 'Title changed from ALLCAPS', }, ] result = hep.do(create_record(snippet)) assert validate(result['hidden_notes'], subschema) is None assert expected == result['hidden_notes'] expected = [ { '9': 'SPIRES-HIDDEN', 'a': 'Title changed from ALLCAPS', }, ] result = hep2marc.do(result) assert expected == result['595']
def test_texkeys_from_035__a_9(): schema = load_schema('hep') subschema = schema['properties']['texkeys'] snippet = ( '<datafield tag="035" ind1=" " ind2=" ">' ' <subfield code="9">INSPIRETeX</subfield>' ' <subfield code="a">Hagedorn:1963hdh</subfield>' '</datafield>' ) # record/1403324 expected = [ 'Hagedorn:1963hdh', ] result = hep.do(create_record(snippet)) assert validate(result['texkeys'], subschema) is None assert expected == result['texkeys'] expected = [ { '9': 'INSPIRETeX', 'a': 'Hagedorn:1963hdh', } ] result = hep2marc.do(result) assert expected == result['035']
def test_collaboration_from_710__g(): schema = load_schema('hep') subschema = schema['properties']['collaboration'] snippet = ('<datafield tag="710" ind1=" " ind2=" ">' ' <subfield code="g">Pierre Auger</subfield>' '</datafield>') # record/1510404 expected = [ { 'value': 'Pierre Auger' }, ] result = hep.do(create_record(snippet)) assert validate(result['collaboration'], subschema) is None assert expected == result['collaboration'] expected = [ { 'g': 'Pierre Auger' }, ] result = hep2marc.do(result) assert expected == result['710']
def test_report_numbers_from_two_037__a(): schema = load_schema('hep') subschema = schema['properties']['report_numbers'] snippet = ( '<record>' ' <datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="a">UTPT-89-27</subfield>' ' </datafield>' ' <datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="a">CALT-68-1585</subfield>' ' </datafield>' '</record>' ) # record/26564 expected = [ { 'value': 'UTPT-89-27', }, { 'value': 'CALT-68-1585', }, ] result = hep.do(create_record(snippet)) assert validate(result['report_numbers'], subschema) is None assert expected == result['report_numbers'] expected = [ {'a': 'UTPT-89-27'}, {'a': 'CALT-68-1585'}, ] result = hep2marc.do(result) assert expected == result['037']
def test_collaboration_from_710__g_0(): schema = load_schema('hep') subschema = schema['properties']['collaboration'] snippet = ('<datafield tag="710" ind1=" " ind2=" ">' ' <subfield code="g">ANTARES</subfield>' ' <subfield code="0">1110619</subfield>' '</datafield>') # record/1422032/export/xme expected = [ { 'record': { '$ref': 'http://localhost:5000/api/experiments/1110619', }, 'value': 'ANTARES', }, ] result = hep.do(create_record(snippet)) assert validate(result['collaboration'], subschema) is None assert expected == result['collaboration'] expected = [ { 'g': 'ANTARES' }, ] result = hep2marc.do(result) assert expected == result['710']
def test_languages_from_041__a_handles_multiple_languages_in_one_a(): schema = load_schema('hep') subschema = schema['properties']['languages'] snippet = ( '<datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">Russian / English</subfield>' '</datafield>' ) # record/116959 expected = [ 'ru', 'en', ] result = hep.do(create_record(snippet)) assert validate(result['languages'], subschema) is None assert expected == result['languages'] expected = [ {'a': 'russian'}, {'a': 'english'}, ] result = hep2marc.do(result) assert expected == result['041']
def test_keywords_from_695__a_2(): schema = load_schema('hep') subschema = schema['properties']['keywords'] snippet = ( '<datafield tag="695" ind1=" " ind2=" ">' ' <subfield code="a">REVIEW</subfield>' ' <subfield code="2">INSPIRE</subfield>' '</datafield>' ) # record/200123 expected = [ { 'keyword': 'REVIEW', 'classification_scheme': 'INSPIRE', }, ] result = hep.do(create_record(snippet)) assert validate(result['keywords'], subschema) is None assert expected == result['keywords'] expected = [ { 'a': 'REVIEW', '2': 'INSPIRE', }, ] result = hep2marc.do(result) assert expected == result['695']
def test_inspire_categories_from_65017a_2_9_discards_conference(): schema = load_schema('elements/inspire_field') snippet = ('<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="2">INSPIRE</subfield>' ' <subfield code="9">conference</subfield>' ' <subfield code="a">Accelerators</subfield>' '</datafield>') # record/1479228 expected = [ { 'source': 'undefined', 'term': 'Accelerators', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result, schema) is None assert expected == result['inspire_categories'] expected = [ { '9': 'undefined', 'a': 'Accelerators', }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_energy_ranges_from_695__2_e(): schema = load_schema('hep') subschema = schema['properties']['energy_ranges'] snippet = ( '<datafield tag="695" ind1=" " ind2=" ">' ' <subfield code="2">INSPIRE</subfield>' ' <subfield code="e">7</subfield>' '</datafield>' ) # record/1124337 expected = [7] result = hep.do(create_record(snippet)) assert validate(result['energy_ranges'], subschema) is None assert expected == result['energy_ranges'] expected = [ { '2': 'INSPIRE', 'e': 7, }, ] result = hep2marc.do(result) assert expected == result['695']
def test_inspire_categories_from_65017a_2_9_converts_submitter(): schema = load_schema('elements/inspire_field') snippet = ('<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="a">Math and Math Physics</subfield>' ' <subfield code="9">submitter</subfield>' ' <subfield code="2">INSPIRE</subfield>' '</datafield>') # record/1511089 expected = [ { 'source': 'user', 'term': 'Math and Math Physics', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result, schema) is None assert expected == result['inspire_categories'] expected = [ { '9': 'user', 'a': 'Math and Math Physics' }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_keywords_from_653__a_9(): schema = load_schema('hep') subschema = schema['properties']['keywords'] snippet = ( '<datafield tag="653" ind1=" " ind2=" ">' ' <subfield code="9">author</subfield>' ' <subfield code="a">Data</subfield>' '</datafield>' ) # record/1260876 expected = [ { 'source': 'author', 'keyword': 'Data', }, ] result = hep.do(create_record(snippet)) assert validate(result['keywords'], subschema) is None assert expected == result['keywords'] expected = [ { '9': 'author', 'a': 'Data', }, ] result = hep2marc.do(result) assert expected == result['653']
def test_urls_from_8564_s_u_ignores_s(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="s">443981</subfield>' ' <subfield code="u">http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf</subfield>' '</datafield>') # record/1511347 expected = [ { 'value': 'http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf' }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf' }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_inspire_categories_from_65017a_2_9_discards_conference(): schema = load_schema('hep') subschema = schema['properties']['inspire_categories'] snippet = ( '<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="2">INSPIRE</subfield>' ' <subfield code="9">conference</subfield>' ' <subfield code="a">Accelerators</subfield>' '</datafield>' ) # record/1479228 expected = [ { 'source': 'undefined', 'term': 'Accelerators', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['inspire_categories'], subschema) is None assert expected == result['inspire_categories'] expected = [ { '2': 'INSPIRE', '9': 'undefined', 'a': 'Accelerators', }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_urls_from_8564_u_double_y_selects_the_first_y(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="u">http://link.springer.com/journal/10909/176/5/page/1</subfield>' ' <subfield code="y">Part II</subfield>' ' <subfield code="y">Springer</subfield>' '</datafield>') # record/1312672 expected = [ { 'description': 'Part II', 'value': 'http://link.springer.com/journal/10909/176/5/page/1', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://link.springer.com/journal/10909/176/5/page/1', 'y': 'Part II', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_acquisition_source_from_541__a_c(): schema = load_schema('hep') subschema = schema['properties']['acquisition_source'] snippet = ( '<datafield tag="541" ind1=" " ind2=" ">' ' <subfield code="a">IOP</subfield>' ' <subfield code="c">batchupload</subfield>' '</datafield>' ) # record/1487640/export/xme expected = { 'source': 'IOP', 'method': 'batchuploader', } result = hep.do(create_record(snippet)) assert validate(result['acquisition_source'], subschema) is None assert expected == result['acquisition_source'] expected = { 'a': 'IOP', 'c': 'batchupload', } result = hep2marc.do(result) assert expected == result['541']
def test_titles_from_245__a_b(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ( '<datafield tag="245" ind1=" " ind2=" ">' ' <subfield code="a">Proceedings, New Observables in Quarkonium Production</subfield>' ' <subfield code="b">Trento, Italy</subfield>' '</datafield>' ) # record/1510141 expected = [ { 'title': 'Proceedings, New Observables in Quarkonium Production', 'subtitle': 'Trento, Italy', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Proceedings, New Observables in Quarkonium Production', 'b': 'Trento, Italy', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_inspire_categories_from_65017a_2_9_converts_automatically_added(): schema = load_schema('hep') subschema = schema['properties']['inspire_categories'] snippet = ( '<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="2">INSPIRE</subfield>' ' <subfield code="a">Instrumentation</subfield>' ' <subfield code="9">automatically added based on DCC, PPF, DK</subfield>' '</datafield>' ) # record/669400 expected = [ { 'source': 'curator', 'term': 'Instrumentation', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['inspire_categories'], subschema) is None assert expected == result['inspire_categories'] expected = [ { '2': 'INSPIRE', '9': 'curator', 'a': 'Instrumentation', }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_title_translations_from_242__a_b(stable_langdetect): schema = load_schema('hep') subschema = schema['properties']['title_translations'] snippet = ( '<datafield tag="242" ind1=" " ind2=" ">' ' <subfield code="a">Generalized Hamilton-Jacobi Formalism</subfield>' ' <subfield code="b">Field Theories with Upper-Order Derivatives</subfield>' '</datafield>' ) # record/1501064 expected = [ { 'language': 'en', 'title': 'Generalized Hamilton-Jacobi Formalism', 'subtitle': 'Field Theories with Upper-Order Derivatives', }, ] result = hep.do(create_record(snippet)) assert validate(result['title_translations'], subschema) is None assert expected == result['title_translations'] expected = [ { 'a': 'Generalized Hamilton-Jacobi Formalism', 'b': 'Field Theories with Upper-Order Derivatives', }, ] result = hep2marc.do(result) assert expected == result['242']
def test_inspire_categories_from_65017a_2_9_converts_submitter(): schema = load_schema('hep') subschema = schema['properties']['inspire_categories'] snippet = ( '<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="a">Math and Math Physics</subfield>' ' <subfield code="9">submitter</subfield>' ' <subfield code="2">INSPIRE</subfield>' '</datafield>' ) # record/1511089 expected = [ { 'source': 'user', 'term': 'Math and Math Physics', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['inspire_categories'], subschema) is None assert expected == result['inspire_categories'] expected = [ { '2': 'INSPIRE', '9': 'user', 'a': 'Math and Math Physics' }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_titles_from_246__a_9(): schema = load_schema('hep') subschema = schema['properties']['titles'] snippet = ( '<datafield tag="246" ind1=" " ind2=" ">' ' <subfield code="a">Superintegrable relativistic systems in' ' spacetime-dependent background fields</subfield>' ' <subfield code="9">arXiv</subfield>' '</datafield>' ) # record/1511471 expected = [ { 'source': 'arXiv', 'title': 'Superintegrable relativistic systems in ' 'spacetime-dependent background fields', }, ] result = hep.do(create_record(snippet)) assert validate(result['titles'], subschema) is None assert expected == result['titles'] expected = [ { 'a': 'Superintegrable relativistic systems in spacetime-dependent background fields', '9': 'arXiv', }, ] result = hep2marc.do(result) assert expected == result['245']
def test_urls_from_8564_u_y(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="u">http://www-lib.kek.jp/ar/ar.html</subfield>' ' <subfield code="y">KEK</subfield>' '</datafield>' ) # record/1405358 expected = [ { 'description': 'KEK', 'value': 'http://www-lib.kek.jp/ar/ar.html', }, ] result = hep.do(create_record(snippet)) assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://www-lib.kek.jp/ar/ar.html', 'y': 'KEK', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_isbns_from_020__a_b_normalizes_electronic(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ( '<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">9783319006260</subfield>' ' <subfield code="b">electronic version</subfield>' '</datafield>' ) # record/1292006 expected = [ { 'value': '9783319006260', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '9783319006260', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_urls_from_8564_s_u_ignores_s(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="s">443981</subfield>' ' <subfield code="u">http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf</subfield>' '</datafield>' ) # record/1511347 expected = [ {'value': 'http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf'}, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ {'u': 'http://inspirehep.net/record/1511347/files/HIG-16-034-pas.pdf'}, ] result = hep2marc.do(result) assert expected == result['8564']
def test_isbns_from_020__a_b_normalizes_hardcover(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ( '<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">978-981-4571-66-1</subfield>' ' <subfield code="b">hardcover</subfield>' '</datafield>' ) # record/1351311 expected = [ { 'value': '9789814571661', 'medium': 'hardcover', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '9789814571661', 'b': 'hardcover', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_urls_from_8564_u_w_y_ignores_w(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="w">12-316</subfield>' ' <subfield code="y">FERMILABPUB</subfield>' ' <subfield code="u">http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316</subfield>' '</datafield>' ) # record/1120360 expected = [ { 'description': 'FERMILABPUB', 'value': 'http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://lss.fnal.gov/cgi-bin/find_paper.pl?pub-12-316', 'y': 'FERMILABPUB', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_dois_from_0247_a_2(): schema = load_schema('hep') subschema = schema['properties']['dois'] snippet = ( '<datafield tag="024" ind1="7" ind2=" ">' ' <subfield code="2">DOI</subfield>' ' <subfield code="a">10.1088/0264-9381/31/24/245004</subfield>' '</datafield>' ) # record/1302395 expected = [ {'value': '10.1088/0264-9381/31/24/245004'}, ] result = hep.do(create_record(snippet)) assert validate(result['dois'], subschema) is None assert expected == result['dois'] expected = [ { 'a': '10.1088/0264-9381/31/24/245004', '2': 'DOI', }, ] result = hep2marc.do(result) assert expected == result['0247']
def test_urls_from_8564_u_double_y_selects_the_first_y(): schema = load_schema('hep') subschema = schema['properties']['urls'] snippet = ( '<datafield tag="856" ind1="4" ind2=" ">' ' <subfield code="u">http://link.springer.com/journal/10909/176/5/page/1</subfield>' ' <subfield code="y">Part II</subfield>' ' <subfield code="y">Springer</subfield>' '</datafield>' ) # record/1312672 expected = [ { 'description': 'Part II', 'value': 'http://link.springer.com/journal/10909/176/5/page/1', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['urls'], subschema) is None assert expected == result['urls'] expected = [ { 'u': 'http://link.springer.com/journal/10909/176/5/page/1', 'y': 'Part II', }, ] result = hep2marc.do(result) assert expected == result['8564']
def test_external_system_identifiers_from_035__z_9_handles_cernkey(): schema = load_schema('hep') subschema = schema['properties']['external_system_identifiers'] snippet = ( '<datafield tag="035" ind1=" " ind2=" ">' ' <subfield code="9">CERNKEY</subfield>' ' <subfield code="z">0263439</subfield>' '</datafield>' ) # record/451647 expected = [ { 'schema': 'CERNKEY', 'value': '0263439', }, ] result = hep.do(create_record(snippet)) assert validate(result['external_system_identifiers'], subschema) is None assert expected == result['external_system_identifiers'] expected = [ { '9': 'CERNKEY', 'z': '0263439', }, ] result = hep2marc.do(result) assert expected == result['035']
def test_acquisition_source_from_541__double_a_b_c_e(): schema = load_schema('hep') subschema = schema['properties']['acquisition_source'] snippet = ( '<datafield tag="541" ind1=" " ind2=" ">' ' <subfield code="a">inspire:uid:52524</subfield>' ' <subfield code="a">orcid:0000-0002-1048-661X</subfield>' ' <subfield code="b">[email protected]</subfield>' ' <subfield code="c">submission</subfield>' ' <subfield code="e">504296</subfield>' '</datafield>' ) # record/1416571/export/xme expected = { 'email': '*****@*****.**', 'internal_uid': 52524, 'method': 'submitter', 'orcid': '0000-0002-1048-661X', 'submission_number': '504296', } result = hep.do(create_record(snippet)) # no roundtrip assert validate(result['acquisition_source'], subschema) is None assert expected == result['acquisition_source'] expected = { 'a': 'orcid:0000-0002-1048-661X', 'b': '*****@*****.**', 'c': 'submission', 'e': '504296', } result = hep2marc.do(result) assert expected == result['541']
def test_arxiv_eprints_from_037__a_c_9(): schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] snippet = ( '<datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="9">arXiv</subfield>' ' <subfield code="a">arXiv:1505.01843</subfield>' ' <subfield code="c">hep-ph</subfield>' '</datafield>' ) # record/1368891 expected = [ { 'categories': [ 'hep-ph', ], 'value': '1505.01843', }, ] result = hep.do(create_record(snippet)) assert validate(result['arxiv_eprints'], subschema) is None assert expected == result['arxiv_eprints'] expected = [ { '9': 'arXiv', 'a': 'arXiv:1505.01843', 'c': 'hep-ph', }, ] result = hep2marc.do(result) assert expected == result['037']
def test_external_system_numbers_from_970__a(): schema = load_schema('hep') subschema = schema['properties']['external_system_numbers'] snippet = ('<datafield tag="970" ind1=" " ind2=" ">' ' <subfield code="a">SPIRES-10325093</subfield>' '</datafield>') # record/1297176 expected = [ { 'institute': 'SPIRES', 'obsolete': True, 'value': 'SPIRES-10325093', }, ] result = hep.do(create_record(snippet)) assert validate(result['external_system_numbers'], subschema) is None assert expected == result['external_system_numbers'] expected = [ { 'a': 'SPIRES-10325093' }, ] result = hep2marc.do(result) assert expected == result['970']
def test_report_numbers_hidden_from_037__z(): schema = load_schema('hep') subschema = schema['properties']['report_numbers'] snippet = ( '<datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="z">FERMILAB-PUB-17-011-CMS</subfield>' '</datafield>' ) # record/1508174 expected = [ { 'hidden': True, 'value': 'FERMILAB-PUB-17-011-CMS', }, ] result = hep.do(create_record(snippet)) assert validate(result['report_numbers'], subschema) is None assert expected == result['report_numbers'] expected = [ {'z': 'FERMILAB-PUB-17-011-CMS'} ] result = hep2marc.do(result) assert expected == result['037']
def test_collections_from_980__a(): schema = load_schema('hep') subschema = schema['properties']['collections'] snippet = ('<datafield tag="980" ind1=" " ind2=" ">' ' <subfield code="a">HEP</subfield>' '</datafield>') # record/1508886 expected = [ { 'primary': 'HEP' }, ] result = hep.do(create_record(snippet)) assert validate(result['collections'], subschema) is None assert expected == result['collections'] expected = [ { 'a': 'HEP' }, ] result = hep2marc.do(result) assert expected == result['980']
def test_isbns_from_020__a_b_normalizes_online(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ( '<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">978-94-024-0999-4</subfield>' ' <subfield code="b">Online</subfield>' '</datafield>' ) # record/1504286 expected = [ { 'value': '9789402409994', 'medium': 'online', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '9789402409994', 'b': 'online', }, ] result = hep2marc.do(result) assert expected == result['020']
def test_inspire_categories_from_65017a_2(): schema = load_schema('elements/inspire_field') snippet = ('<datafield tag="650" ind1="1" ind2="7">' ' <subfield code="2">Inspire</subfield>' ' <subfield code="a">Experiment-HEP</subfield>' '</datafield>') # record/1426196 expected = [ { 'source': 'undefined', 'term': 'Experiment-HEP', }, ] result = hep.do(create_record(snippet)) # no roundtrip assert validate(result, schema) is None assert expected == result['inspire_categories'] expected = [ { '9': 'undefined', 'a': 'Experiment-HEP', }, ] result = hep2marc.do(result) assert expected == result['65017']
def test_languages_from_double_041__a(): schema = load_schema('hep') subschema = schema['properties']['languages'] snippet = ( '<record>' ' <datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">French</subfield>' ' </datafield>' ' <datafield tag="041" ind1=" " ind2=" ">' ' <subfield code="a">German</subfield>' ' </datafield>' '</record>' ) # record/1231408 expected = [ 'fr', 'de', ] result = hep.do(create_record(snippet)) assert validate(result['languages'], subschema) is None assert expected == result['languages'] expected = [ {'a': 'french'}, {'a': 'german'}, ] result = hep2marc.do(result) assert expected == result['041']
def test_isbns_from_020__a_b_normalizes_online(): schema = load_schema('hep') subschema = schema['properties']['isbns'] snippet = ('<datafield tag="020" ind1=" " ind2=" ">' ' <subfield code="a">978-94-024-0999-4</subfield>' ' <subfield code="b">Online</subfield>' '</datafield>') # record/1504286 expected = [ { 'value': '978-94-024-0999-4', 'medium': 'online', }, ] result = hep.do(create_record(snippet)) assert validate(result['isbns'], subschema) is None assert expected == result['isbns'] expected = [ { 'a': '978-94-024-0999-4', 'b': 'online', }, ] result = hep2marc.do(result) assert expected == result['020']