Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/metadata_dictionary/test_codemeta.py
Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | <entry xmlns="http://www.w3.org/2005/Atom" | ||||
<codemeta:name>My Software</codemeta:name> | <codemeta:name>My Software</codemeta:name> | ||||
<codemeta:author> | <codemeta:author> | ||||
<codemeta:name>Author 1</codemeta:name> | <codemeta:name>Author 1</codemeta:name> | ||||
<codemeta:email>foo@example.org</codemeta:email> | <codemeta:email>foo@example.org</codemeta:email> | ||||
</codemeta:author> | </codemeta:author> | ||||
<codemeta:author> | <codemeta:author> | ||||
<codemeta:name>Author 2</codemeta:name> | <codemeta:name>Author 2</codemeta:name> | ||||
</codemeta:author> | </codemeta:author> | ||||
<codemeta:dateCreated>2022-10-26</codemeta:dateCreated> | |||||
<author> | <author> | ||||
<name>Author 3</name> | <name>Author 3</name> | ||||
<email>bar@example.org</email> | <email>bar@example.org</email> | ||||
</author> | </author> | ||||
</entry> | </entry> | ||||
""" | """ | ||||
result = MAPPINGS["SwordCodemetaMapping"]().translate(content) | result = MAPPINGS["SwordCodemetaMapping"]().translate(content) | ||||
assert result == { | assert result == { | ||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", | ||||
"name": "My Software", | "name": "My Software", | ||||
"author": [ | "author": [ | ||||
{"name": "Author 1", "email": "foo@example.org"}, | {"name": "Author 1", "email": "foo@example.org"}, | ||||
{"name": "Author 2"}, | {"name": "Author 2"}, | ||||
{"name": "Author 3", "email": "bar@example.org"}, | {"name": "Author 3", "email": "bar@example.org"}, | ||||
], | ], | ||||
"dateCreated": "2022-10-26", | |||||
} | } | ||||
def test_sword_mixed(): | def test_sword_mixed(): | ||||
content = """<?xml version="1.0"?> | content = """<?xml version="1.0"?> | ||||
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | ||||
xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | ||||
xmlns:schema="http://schema.org/"> | xmlns:schema="http://schema.org/"> | ||||
Show All 28 Lines | assert result == { | ||||
"name": "My Software", | "name": "My Software", | ||||
"version": "1.2.3", | "version": "1.2.3", | ||||
} | } | ||||
def test_sword_schemaorg_in_codemeta_constrained(): | def test_sword_schemaorg_in_codemeta_constrained(): | ||||
"""Resulting property has the compact URI 'schema:url' instead of just | """Resulting property has the compact URI 'schema:url' instead of just | ||||
the term 'url', because term 'url' is defined by the Codemeta schema | the term 'url', because term 'url' is defined by the Codemeta schema | ||||
has having type '@id'.""" | has having type '@id'. | ||||
Ditto for dates (with type http://schema.org/Date).""" | |||||
content = """<?xml version="1.0"?> | content = """<?xml version="1.0"?> | ||||
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | ||||
xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | ||||
xmlns:schema="http://schema.org/"> | xmlns:schema="http://schema.org/"> | ||||
<name>My Software</name> | <name>My Software</name> | ||||
<schema:url>http://example.org/my-software</schema:url> | <schema:url>http://example.org/my-software</schema:url> | ||||
<schema:dateCreated>foo</schema:dateCreated> | |||||
<schema:dateModified>2022-10-26</schema:dateModified> | |||||
</atom:entry> | </atom:entry> | ||||
""" | """ | ||||
result = MAPPINGS["SwordCodemetaMapping"]().translate(content) | result = MAPPINGS["SwordCodemetaMapping"]().translate(content) | ||||
assert result == { | assert result == { | ||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", | ||||
"name": "My Software", | "name": "My Software", | ||||
"schema:url": "http://example.org/my-software", | "schema:url": "http://example.org/my-software", | ||||
"schema:dateCreated": "foo", | |||||
"schema:dateModified": "2022-10-26", | |||||
} | } | ||||
def test_sword_schemaorg_not_in_codemeta(): | def test_sword_schemaorg_not_in_codemeta(): | ||||
content = """<?xml version="1.0"?> | content = """<?xml version="1.0"?> | ||||
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | ||||
xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | xmlns="https://doi.org/10.5063/schema/codemeta-2.0" | ||||
xmlns:schema="http://schema.org/"> | xmlns:schema="http://schema.org/"> | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def test_json_sword(): | ||||
assert result == { | assert result == { | ||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", | ||||
"author": [ | "author": [ | ||||
{"name": "Author 1", "email": "foo@example.org"}, | {"name": "Author 1", "email": "foo@example.org"}, | ||||
{"name": "Author 2"}, | {"name": "Author 2"}, | ||||
], | ], | ||||
"license": {"name": "GNU General Public License v3.0 or later"}, | "license": {"name": "GNU General Public License v3.0 or later"}, | ||||
"name": "The assignment problem", | "name": "The assignment problem", | ||||
"schema:url": "http://example.org/", | "url": "http://example.org/", | ||||
"name": "The assignment problem", | "name": "The assignment problem", | ||||
} | } |