def test_is_arxiv_matches_valid_categories(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('BF/0234502') builder.add_uid('math/0311149') expected = [ { 'reference': { 'persistent_identifiers': [{ 'value': 'BF/0234502', 'schema': 'HDL', }], 'arxiv_eprint': 'math/0311149' }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_falls_back_to_isbn(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('1449344852') expected = [ { 'reference': { 'isbn': '9781449344856', }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_handles_arxiv_ids(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('hep-th/0603001') expected = [ { 'reference': { 'arxiv_eprint': 'hep-th/0603001', }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_rejects_invalid_isbns(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('123456789') expected = [ { 'reference': { 'misc': [ '123456789', ] }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_handles_cnums(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('C87-11-11') expected = [ { 'reference': { 'publication_info': { 'cnum': 'C87-11-11', }, }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_handles_dois(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('http://dx.doi.org/10.3972/water973.0145.db') expected = [ { 'reference': { 'dois': [ '10.3972/water973.0145.db', ], }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_add_uid_handles_handles(): schema = load_schema('hep') subschema = schema['properties']['references'] builder = ReferenceBuilder() builder.add_uid('hdl:10443/1646') expected = [ { 'reference': { 'persistent_identifiers': [ { 'schema': 'HDL', 'value': '10443/1646', }, ], }, }, ] result = [builder.obj] assert validate(result, subschema) is None assert expected == result
def test_reference_builder_is_not_adding_doi_when_already_present(): rb = ReferenceBuilder() rb.add_url('https://doi.org/10.1088/1009-0630/7/4/022') rb.add_uid('10.1088/1009-0630/7/4/022') assert rb.obj['reference']['dois'] == ['10.1088/1009-0630/7/4/022']