Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
shows the entire diff in the results | shows the entire diff in the results | ||||
""" | """ | ||||
self.maxDiff = None | self.maxDiff = None | ||||
self.npm_mapping = MAPPINGS["NpmMapping"]() | self.npm_mapping = MAPPINGS["NpmMapping"]() | ||||
self.codemeta_mapping = MAPPINGS["CodemetaMapping"]() | self.codemeta_mapping = MAPPINGS["CodemetaMapping"]() | ||||
self.maven_mapping = MAPPINGS["MavenMapping"]() | self.maven_mapping = MAPPINGS["MavenMapping"]() | ||||
self.pkginfo_mapping = MAPPINGS["PythonPkginfoMapping"]() | self.pkginfo_mapping = MAPPINGS["PythonPkginfoMapping"]() | ||||
self.gemspec_mapping = MAPPINGS["GemspecMapping"]() | self.gemspec_mapping = MAPPINGS["GemspecMapping"]() | ||||
self.cff_mapping = MAPPINGS["CffMapping"]() | |||||
def test_compute_metadata_none(self): | def test_compute_metadata_none(self): | ||||
""" | """ | ||||
testing content empty content is empty | testing content empty content is empty | ||||
should return None | should return None | ||||
""" | """ | ||||
# given | # given | ||||
content = b"" | content = b"" | ||||
# None if no metadata was found or an error occurred | # None if no metadata was found or an error occurred | ||||
declared_metadata = None | declared_metadata = None | ||||
# when | # when | ||||
result = self.npm_mapping.translate(content) | result = self.npm_mapping.translate(content) | ||||
# then | # then | ||||
self.assertEqual(declared_metadata, result) | self.assertEqual(declared_metadata, result) | ||||
def test_compute_metadata_cff(self): | |||||
""" | |||||
testing CITATION.cff tranlsation | |||||
vlorentz: typo | |||||
""" | |||||
# given | |||||
content = """# YAML 1.2 | |||||
--- | |||||
abstract: "Command line program to convert from Citation File \ | |||||
Format to various other formats such as BibTeX, EndNote, RIS, \ | |||||
schema.org, CodeMeta, and .zenodo.json." | |||||
authors: | |||||
- | |||||
affiliation: "Netherlands eScience Center" | |||||
family-names: Klaver | |||||
given-names: Tom | |||||
- | |||||
affiliation: "Humboldt-Universität zu Berlin" | |||||
family-names: Druskat | |||||
given-names: Stephan | |||||
orcid: https://orcid.org/0000-0003-4925-7248 | |||||
cff-version: "1.0.3" | |||||
date-released: 2019-11-12 | |||||
doi: 10.5281/zenodo.1162057 | |||||
keywords: | |||||
- "citation" | |||||
- "bibliography" | |||||
- "cff" | |||||
- "CITATION.cff" | |||||
license: Apache-2.0 | |||||
message: "If you use this software, please cite it using these metadata." | |||||
repository-code: "https://github.com/citation-file-format/cff-converter-python" | |||||
title: cffconvert | |||||
version: "1.4.0-alpha0" | |||||
""".encode( | |||||
"utf-8" | |||||
) | |||||
vlorentzUnsubmitted Not Done Inline Actionsuse b""" to start the string so you don't need to .encode() it vlorentz: use `b"""` to start the string so you don't need to `.encode()` it | |||||
KShivenduAuthorUnsubmitted Not Done Inline ActionsI did that the first time but it throws an error: bytes can only contain ASCII literal characters. KShivendu: I did that the first time but it throws an error: `bytes can only contain ASCII literal… | |||||
expected = { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"type": "SoftwareSourceCode", | |||||
"author": [ | |||||
{ | |||||
"@type": "Person", | |||||
"affiliation": { | |||||
"@type": "Organization", | |||||
"name": "Netherlands eScience Center", | |||||
}, | |||||
"familyName": "Klaver", | |||||
"givenName": "Tom", | |||||
}, | |||||
{ | |||||
"@id": "https://orcid.org/0000-0003-4925-7248", | |||||
"@type": "Person", | |||||
"affiliation": { | |||||
"@type": "Organization", | |||||
"name": "Humboldt-Universit\u00e4t zu Berlin", | |||||
vlorentzUnsubmitted Done Inline Actionsyou can write the literal ä here vlorentz: you can write the literal `ä` here | |||||
}, | |||||
"familyName": "Druskat", | |||||
"givenName": "Stephan", | |||||
}, | |||||
], | |||||
"codeRepository": ( | |||||
"https://github.com/" "citation-file-format/cff-converter-python" | |||||
vlorentzUnsubmitted Done Inline Actionsdrop the " " (Black can't do it when it folds two lines, unfortunately) vlorentz: drop the `" "` (Black can't do it when it folds two lines, unfortunately) | |||||
), | |||||
"datePublished": "2019-11-12", | |||||
"description": """Command line program to convert from \ | |||||
Citation File Format to various other formats such as BibTeX, EndNote, \ | |||||
RIS, schema.org, CodeMeta, and .zenodo.json.""", | |||||
"identifier": "https://doi.org/10.5281/zenodo.1162057", | |||||
"keywords": ["citation", "bibliography", "cff", "CITATION.cff"], | |||||
"license": "https://spdx.org/licenses/Apache-2.0", | |||||
"version": "1.4.0-alpha0", | |||||
} | |||||
# when | |||||
result = self.cff_mapping.translate(content) | |||||
# then | |||||
self.assertEqual(expected, result) | |||||
def test_compute_metadata_npm(self): | def test_compute_metadata_npm(self): | ||||
""" | """ | ||||
testing only computation of metadata with hard_mapping_npm | testing only computation of metadata with hard_mapping_npm | ||||
""" | """ | ||||
# given | # given | ||||
content = b""" | content = b""" | ||||
{ | { | ||||
"name": "test_metadata", | "name": "test_metadata", | ||||
▲ Show 20 Lines • Show All 1,146 Lines • Show Last 20 Lines |
typo