Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/metadata_dictionary/test_npm.py
Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | def test_npm_repository_normalization(): | ||||
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": "foo", | "name": "foo", | ||||
"codeRepository": "git+https://gitlab.com/user/repo.git", | "codeRepository": "git+https://gitlab.com/user/repo.git", | ||||
"type": "SoftwareSourceCode", | "type": "SoftwareSourceCode", | ||||
} | } | ||||
def test_npm_empty_uris(): | |||||
package_json = rb"""{ | |||||
"version": "1.0.0", | |||||
"homepage": "", | |||||
"author": { | |||||
"name": "foo", | |||||
"url": "http://example.org" | |||||
} | |||||
}""" | |||||
result = MAPPINGS["NpmMapping"]().translate(package_json) | |||||
assert result == { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"type": "SoftwareSourceCode", | |||||
"author": [{"name": "foo", "type": "Person", "url": "http://example.org"}], | |||||
"version": "1.0.0", | |||||
} | |||||
package_json = rb"""{ | |||||
"version": "1.0.0", | |||||
"homepage": "http://example.org", | |||||
"author": { | |||||
"name": "foo", | |||||
"url": "" | |||||
} | |||||
}""" | |||||
result = MAPPINGS["NpmMapping"]().translate(package_json) | |||||
assert result == { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"type": "SoftwareSourceCode", | |||||
"author": [{"name": "foo", "type": "Person"}], | |||||
"url": "http://example.org", | |||||
"version": "1.0.0", | |||||
} | |||||
package_json = rb"""{ | |||||
"version": "1.0.0", | |||||
"homepage": "", | |||||
"author": { | |||||
"name": "foo", | |||||
"url": "" | |||||
} | |||||
}""" | |||||
result = MAPPINGS["NpmMapping"]().translate(package_json) | |||||
assert result == { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"type": "SoftwareSourceCode", | |||||
"author": [{"name": "foo", "type": "Person"}], | |||||
"version": "1.0.0", | |||||
} | |||||
@settings(suppress_health_check=[HealthCheck.too_slow]) | @settings(suppress_health_check=[HealthCheck.too_slow]) | ||||
@given(json_document_strategy(keys=list(MAPPINGS["NpmMapping"].mapping))) # type: ignore | @given(json_document_strategy(keys=list(MAPPINGS["NpmMapping"].mapping))) # type: ignore | ||||
def test_npm_adversarial(doc): | def test_npm_adversarial(doc): | ||||
raw = json.dumps(doc).encode() | raw = json.dumps(doc).encode() | ||||
MAPPINGS["NpmMapping"]().translate(raw) | MAPPINGS["NpmMapping"]().translate(raw) | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
Show All 31 Lines |