Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | def test_npm_repository_normalization(self): | ||||
{ | { | ||||
"@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_detect_metadata_package_json(self): | def test_detect_metadata_package_json(self): | ||||
# given | # given | ||||
df = [ | df = [ | ||||
{ | { | ||||
"sha1_git": b"abc", | "sha1_git": b"abc", | ||||
"name": b"index.js", | "name": b"index.js", | ||||
"target": b"abc", | "target": b"abc", | ||||
"length": 897, | "length": 897, | ||||
"status": "visible", | "status": "visible", | ||||
"type": "file", | "type": "file", | ||||
"perms": 33188, | "perms": 33188, | ||||
"dir_id": b"dir_a", | "dir_id": b"dir_a", | ||||
"sha1": b"bcd", | "sha1": b"bcd", | ||||
}, | }, | ||||
{ | { | ||||
"sha1_git": b"aab", | "sha1_git": b"aab", | ||||
"name": b"package.json", | "name": b"package.json", | ||||
"target": b"aab", | "target": b"aab", | ||||
"length": 712, | "length": 712, | ||||
"status": "visible", | "status": "visible", | ||||
"type": "file", | "type": "file", | ||||
"perms": 33188, | "perms": 33188, | ||||
"dir_id": b"dir_a", | "dir_id": b"dir_a", | ||||
"sha1": b"cde", | "sha1": b"cde", | ||||
}, | }, | ||||
] | ] | ||||
ardumont: Hopefully that works with unittest like tests too... | |||||
VickyMerzOwnAuthorUnsubmitted Done Inline ActionsI tried making it work, but using @pytest.mark.parametrize is throwing a lot of errors and warnings on running pytest VickyMerzOwn: I tried making it work, but using `@pytest.mark.parametrize` is throwing a lot of errors and… | |||||
# when | # when | ||||
results = detect_metadata(df) | results = detect_metadata(df) | ||||
expected_results = {"NpmMapping": [b"cde"]} | expected_results = {"NpmMapping": [b"cde"]} | ||||
# then | # then | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) | ||||
def test_detect_metadata_package_uppercase_npm(self): | |||||
# given | |||||
df = [ | |||||
{ | |||||
"sha1git": b"def", | |||||
"name": b"PACKAGE.json", | |||||
"target": b"def", | |||||
"length": 897, | |||||
"status": "visible", | |||||
"type": "file", | |||||
"perms": 33188, | |||||
"dir_id": b"dir_a", | |||||
"sha1": b"xyz", | |||||
}, | |||||
] | |||||
# when | |||||
results = detect_metadata(df) | |||||
expected_results = {"NpmMapping": [b"xyz"]} | |||||
# then | |||||
self.assertEqual(expected_results, results) | |||||
ardumontUnsubmitted Not Done Inline ActionsFor this, we now tend to use pytest.mark.parametrize decorator (as per my previous suggestion above). Can you please give it a try? ardumont: For this, we now tend to use `pytest.mark.parametrize` decorator (as per my previous suggestion… | |||||
ardumontUnsubmitted Not Done Inline Actionsfor some example, please, check [1] [1] https://forge.softwareheritage.org/search/query/0jpXqt8EYpXC/#R ardumont: for some example, please, check [1]
[1] https://forge.softwareheritage. | |||||
def test_detect_metadata_codemeta_json_uppercase(self): | def test_detect_metadata_codemeta_json_uppercase(self): | ||||
# given | # given | ||||
df = [ | df = [ | ||||
{ | { | ||||
"sha1_git": b"abc", | "sha1_git": b"abc", | ||||
"name": b"index.html", | "name": b"index.html", | ||||
"target": b"abc", | "target": b"abc", | ||||
"length": 897, | "length": 897, | ||||
▲ Show 20 Lines • Show All 889 Lines • Show Last 20 Lines |
Hopefully that works with unittest like tests too...