Changeset View
Changeset View
Standalone View
Standalone View
swh/clearlydefined/tests/test_mapping_utils.py
Show All 28 Lines | from swh.model.model import ( | ||||
DirectoryEntry, | DirectoryEntry, | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
import gzip | import gzip | ||||
import os | import os | ||||
from typing import Tuple | from typing import Tuple | ||||
import pytest | import pytest | ||||
import json | |||||
content_data = [ | content_data = [ | ||||
Content.from_data(b"42\n"), | Content.from_data(b"42\n"), | ||||
Content.from_data(b"4242\n"), | Content.from_data(b"4242\n"), | ||||
] | ] | ||||
directory = Directory( | directory = Directory( | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | expected = ( | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
Origin( | Origin( | ||||
url="http://central.maven.org/maven2/za/co/absa/cobrix/" | url="http://central.maven.org/maven2/za/co/absa/cobrix/" | ||||
"cobol-parser/0.4.0/cobol-parser-0.4.0-sources.jar" | "cobol-parser/0.4.0/cobol-parser-0.4.0-sources.jar" | ||||
), | ), | ||||
json.loads(file_data(os.path.join(datadir, "definitions.json"))), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_definitions_with_gitsha1(swh_storage, datadir): | def test_map_row_for_definitions_with_gitsha1(swh_storage, datadir): | ||||
add_revision_data(swh_storage) | add_revision_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="maven/mavencentral/za.co.absa.cobrix/cobol-parser/revision/0.4.0.json", | id="maven/mavencentral/za.co.absa.cobrix/cobol-parser/revision/0.4.0.json", | ||||
text=file_data(os.path.join(datadir, "definitions_sha1git.json")), | text=file_data(os.path.join(datadir, "definitions_sha1git.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
True, | True, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:rev:4c66129b968ab8122964823d1d77677f50884cf6", | "swh:1:rev:4c66129b968ab8122964823d1d77677f50884cf6", | ||||
MetadataTargetType.REVISION, | MetadataTargetType.REVISION, | ||||
Origin( | Origin( | ||||
url="http://central.maven.org/maven2/za/co/absa/cobrix/" | url="http://central.maven.org/maven2/za/co/absa/cobrix/" | ||||
"cobol-parser/0.4.0/cobol-parser-0.4.0-sources.jar" | "cobol-parser/0.4.0/cobol-parser-0.4.0-sources.jar" | ||||
), | ), | ||||
json.loads( | |||||
file_data(os.path.join(datadir, "definitions_sha1git.json")) | |||||
), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_scancode(swh_storage, datadir): | def test_map_row_for_scancode(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@ngtools/webpack/revision/10.2.1/tool/scancode/3.2.2.json", | id="npm/npmjs/@ngtools/webpack/revision/10.2.1/tool/scancode/3.2.2.json", | ||||
text=file_data(os.path.join(datadir, "scancode.json")), | text=file_data(os.path.join(datadir, "scancode.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
False, | False, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads(file_data(os.path.join(datadir, "scancode_metadata.json"))), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_scancode_true_mapping_status(swh_storage, datadir): | def test_map_row_for_scancode_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@ngtools/webpack/revision/10.2.1/tool/scancode/3.2.2.json", | id="npm/npmjs/@ngtools/webpack/revision/10.2.1/tool/scancode/3.2.2.json", | ||||
text=file_data(os.path.join(datadir, "scancode_true.json")), | text=file_data(os.path.join(datadir, "scancode_true.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
True, | True, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads(file_data(os.path.join(datadir, "scancode_metadata.json"))), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_licensee(swh_storage, datadir): | def test_map_row_for_licensee(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@fluidframework/replay-driver/revision/0.31.0/tool/licensee/\ | id="npm/npmjs/@fluidframework/replay-driver/revision/0.31.0/tool/licensee/\ | ||||
9.13.0.json", | 9.13.0.json", | ||||
text=file_data(os.path.join(datadir, "licensee.json")), | text=file_data(os.path.join(datadir, "licensee.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
False, | False, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads(file_data(os.path.join(datadir, "licensee_metadata.json"))), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_licensee_true_mapping_status(swh_storage, datadir): | def test_map_row_for_licensee_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@fluidframework/replay-driver/revision/0.31.0/tool/licensee/\ | id="npm/npmjs/@fluidframework/replay-driver/revision/0.31.0/tool/licensee/\ | ||||
9.13.0.json", | 9.13.0.json", | ||||
text=file_data(os.path.join(datadir, "licensee_true.json")), | text=file_data(os.path.join(datadir, "licensee_true.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
True, | True, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads(file_data(os.path.join(datadir, "licensee_metadata.json"))), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert map_row(storage=swh_storage, row=row) == expected | assert map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_clearlydefined(swh_storage, datadir): | def test_map_row_for_clearlydefined(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@pixi/mesh-extras/revision/5.3.5/tool/clearlydefined/1.3.4.json", | id="npm/npmjs/@pixi/mesh-extras/revision/5.3.5/tool/clearlydefined/1.3.4.json", | ||||
text=file_data(os.path.join(datadir, "clearlydefined.json")), | text=file_data(os.path.join(datadir, "clearlydefined.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
False, | False, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads( | |||||
file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | |||||
), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
map_row(storage=swh_storage, row=row) == expected | map_row(storage=swh_storage, row=row) == expected | ||||
def test_map_row_for_clearlydefined_true_mapping_status(swh_storage, datadir): | def test_map_row_for_clearlydefined_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
row = make_row( | row = make_row( | ||||
id="npm/npmjs/@pixi/mesh-extras/revision/5.3.5/tool/clearlydefined/1.3.4.json", | id="npm/npmjs/@pixi/mesh-extras/revision/5.3.5/tool/clearlydefined/1.3.4.json", | ||||
text=file_data(os.path.join(datadir, "clearlydefined_true.json")), | text=file_data(os.path.join(datadir, "clearlydefined_true.json")), | ||||
) | ) | ||||
expected = ( | expected = ( | ||||
True, | True, | ||||
[ | [ | ||||
( | ( | ||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa", | ||||
MetadataTargetType.CONTENT, | MetadataTargetType.CONTENT, | ||||
None, | None, | ||||
json.loads( | |||||
file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | |||||
), | |||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
map_row(storage=swh_storage, row=row) == expected | map_row(storage=swh_storage, row=row) == expected | ||||
def test_sha1git_not_in_revision(swh_storage, datadir): | def test_sha1git_not_in_revision(swh_storage, datadir): | ||||
add_revision_data(swh_storage) | add_revision_data(swh_storage) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |