Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 689 Lines • ▼ Show 20 Lines | |||||
""") # noqa | """) # noqa | ||||
result = MAPPINGS["PythonPkginfoMapping"].translate(raw_content) | result = MAPPINGS["PythonPkginfoMapping"].translate(raw_content) | ||||
self.assertEqual(result, { | self.assertEqual(result, { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'name': 'foo', | 'name': 'foo', | ||||
'license': 'MIT', | 'license': 'MIT', | ||||
}) | }) | ||||
douardda: When writing tests for this kind of feature, please also add limit cases. How about invalid… | |||||
Done Inline Actionsvlorentz: T1475 | |||||
def test_gemspec_base(self): | |||||
raw_content = b""" | |||||
Gem::Specification.new do |s| | |||||
s.name = 'example' | |||||
s.version = '0.1.0' | |||||
s.licenses = ['MIT'] | |||||
s.summary = "This is an example!" | |||||
s.description = "Much longer explanation of the example!" | |||||
s.authors = ["Ruby Coder"] | |||||
s.email = 'rubycoder@example.com' | |||||
s.files = ["lib/example.rb"] | |||||
s.homepage = 'https://rubygems.org/gems/example' | |||||
s.metadata = { "source_code_uri" => "https://github.com/example/example" } | |||||
end""" | |||||
result = MAPPINGS['GemspecMapping'].translate(raw_content) | |||||
self.assertCountEqual(result.pop('description'), [ | |||||
"This is an example!", | |||||
"Much longer explanation of the example!" | |||||
]) | |||||
self.assertEqual(result, { | |||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | |||||
'type': 'SoftwareSourceCode', | |||||
'author': ['Ruby Coder'], | |||||
'name': 'example', | |||||
'license': 'https://spdx.org/licenses/MIT', | |||||
'codeRepository': 'https://rubygems.org/gems/example', | |||||
'email': 'rubycoder@example.com', | |||||
'version': '0.1.0', | |||||
}) | |||||
def test_gemspec_two_author_fields(self): | |||||
raw_content = b""" | |||||
Gem::Specification.new do |s| | |||||
s.authors = ["Ruby Coder1"] | |||||
s.author = "Ruby Coder2" | |||||
end""" | |||||
result = MAPPINGS['GemspecMapping'].translate(raw_content) | |||||
self.assertCountEqual(result.pop('author'), [ | |||||
'Ruby Coder1', 'Ruby Coder2']) | |||||
self.assertEqual(result, { | |||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | |||||
'type': 'SoftwareSourceCode', | |||||
}) | |||||
def test_revision_metadata_indexer(self): | def test_revision_metadata_indexer(self): | ||||
metadata_indexer = RevisionMetadataTestIndexer() | metadata_indexer = RevisionMetadataTestIndexer() | ||||
fill_obj_storage(metadata_indexer.objstorage) | fill_obj_storage(metadata_indexer.objstorage) | ||||
fill_storage(metadata_indexer.storage) | fill_storage(metadata_indexer.storage) | ||||
tool = metadata_indexer.idx_storage.indexer_configuration_get( | tool = metadata_indexer.idx_storage.indexer_configuration_get( | ||||
{'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | {'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | ||||
assert tool is not None | assert tool is not None | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |
When writing tests for this kind of feature, please also add limit cases. How about invalid spec files? what if the description (or any other field) is a (literal) multi line string/list/dict?
One test for the most basic and "friendly" data is not enough.