Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/tests/test_npm.py
Show All 40 Lines | for author, expected_author in [ | ||||
({"name": None, "email": None,}, ""), | ({"name": None, "email": None,}, ""), | ||||
({}, ""), | ({}, ""), | ||||
(None, None), | (None, None), | ||||
({"name": []}, "",), | ({"name": []}, "",), | ||||
( | ( | ||||
{"name": ["Susan McSween", "William H. Bonney", "Doc Scurlock",]}, | {"name": ["Susan McSween", "William H. Bonney", "Doc Scurlock",]}, | ||||
"Susan McSween", | "Susan McSween", | ||||
), | ), | ||||
(None, None), | |||||
]: | ]: | ||||
assert _author_str(author) == expected_author | assert _author_str(author) == expected_author | ||||
def test_extract_npm_package_author(datadir): | def test_extract_npm_package_author(datadir): | ||||
package_metadata_filepath = os.path.join( | package_metadata_filepath = os.path.join( | ||||
datadir, "https_replicate.npmjs.com", "org_visit1" | datadir, "https_replicate.npmjs.com", "org_visit1" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | def test_extract_npm_package_author(datadir): | ||||
) | ) | ||||
assert extract_npm_package_author(package_json) == Person( | assert extract_npm_package_author(package_json) == Person( | ||||
fullname=b"xiaohuoni <448627663@qq.com>", | fullname=b"xiaohuoni <448627663@qq.com>", | ||||
name=b"xiaohuoni", | name=b"xiaohuoni", | ||||
email=b"448627663@qq.com", | email=b"448627663@qq.com", | ||||
) | ) | ||||
package_json_no_authors = json.loads( | |||||
"""{ | |||||
"authors": null, | |||||
"license": "MIT" | |||||
}""" | |||||
) | |||||
assert extract_npm_package_author(package_json_no_authors) == Person( | |||||
fullname=b"", name=None, email=None | |||||
) | |||||
def normalize_hashes(hashes): | def normalize_hashes(hashes): | ||||
if isinstance(hashes, str): | if isinstance(hashes, str): | ||||
return hash_to_bytes(hashes) | return hash_to_bytes(hashes) | ||||
if isinstance(hashes, list): | if isinstance(hashes, list): | ||||
return [hash_to_bytes(x) for x in hashes] | return [hash_to_bytes(x) for x in hashes] | ||||
return {hash_to_bytes(k): hash_to_bytes(v) for k, v in hashes.items()} | return {hash_to_bytes(k): hash_to_bytes(v) for k, v in hashes.items()} | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |