Page MenuHomeSoftware Heritage

D8007.diff
No OneTemporary

D8007.diff

diff --git a/swh/indexer/metadata_dictionary/npm.py b/swh/indexer/metadata_dictionary/npm.py
--- a/swh/indexer/metadata_dictionary/npm.py
+++ b/swh/indexer/metadata_dictionary/npm.py
@@ -160,7 +160,7 @@
>>> NpmMapping().normalize_description(None) is None
True
"""
- if description is None:
+ if not isinstance(description, str):
return None
# XXX: if this function ever need to support more cases, consider
# switching to https://pypi.org/project/ftfy/ instead of adding more hacks
diff --git a/swh/indexer/tests/test_metadata.py b/swh/indexer/tests/test_metadata.py
--- a/swh/indexer/tests/test_metadata.py
+++ b/swh/indexer/tests/test_metadata.py
@@ -253,6 +253,30 @@
# then
assert declared_metadata == result
+ def test_compute_metadata_invalid_description_npm(self):
+ """
+ testing only computation of metadata with hard_mapping_npm
+ """
+ # given
+ content = b"""
+ {
+ "name": "test_metadata",
+ "version": "0.0.2",
+ "description": 1234
+ }
+ """
+ declared_metadata = {
+ "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
+ "type": "SoftwareSourceCode",
+ "name": "test_metadata",
+ "version": "0.0.2",
+ }
+
+ # when
+ result = self.npm_mapping.translate(content)
+ # then
+ assert declared_metadata == result
+
def test_index_content_metadata_npm(self):
"""
testing NPM with package.json

File Metadata

Mime Type
text/plain
Expires
Dec 21 2024, 5:43 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217391

Event Timeline