Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/tests/test_nixguix.py
| Show All 27 Lines | |||||
| ) | ) | ||||
| from swh.loader.package.archive.loader import ArchiveLoader | from swh.loader.package.archive.loader import ArchiveLoader | ||||
| from swh.loader.package.nixguix.loader import ( | from swh.loader.package.nixguix.loader import ( | ||||
| NixGuixPackageInfo, | NixGuixPackageInfo, | ||||
| NixGuixLoader, | NixGuixLoader, | ||||
| parse_sources, | parse_sources, | ||||
| retrieve_sources, | retrieve_sources, | ||||
| clean_sources, | clean_sources, | ||||
| make_pattern_unsupported_file_extension, | |||||
| ) | ) | ||||
| from swh.loader.package.utils import download | from swh.loader.package.utils import download | ||||
| from swh.model.hashutil import hash_to_bytes, hash_to_hex | from swh.model.hashutil import hash_to_bytes, hash_to_hex | ||||
| from swh.storage.exc import HashCollision | from swh.storage.exc import HashCollision | ||||
| from swh.storage.algos.origin import origin_get_latest_visit_status | from swh.storage.algos.origin import origin_get_latest_visit_status | ||||
| from swh.storage.interface import PagedResult | from swh.storage.interface import PagedResult | ||||
| ▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | sources = { | ||||
| ], | ], | ||||
| "revision": "my-revision", | "revision": "my-revision", | ||||
| } | } | ||||
| clean = clean_sources(sources) | clean = clean_sources(sources) | ||||
| assert len(clean["sources"]) == len(valid_sources) | assert len(clean["sources"]) == len(valid_sources) | ||||
| def test_make_pattern_unsupported_file_extension(): | |||||
| unsupported_extensions = ["el", "c", "txt"] | |||||
| supported_extensions = ["Z", "7z"] # for test | |||||
| actual_unsupported_pattern = make_pattern_unsupported_file_extension( | |||||
| unsupported_extensions | |||||
| ) | |||||
| for supported_ext in supported_extensions: | |||||
| assert supported_ext not in unsupported_extensions | |||||
| supported_filepath = f"anything.{supported_ext}" | |||||
| actual_match = actual_unsupported_pattern.match(supported_filepath) | |||||
| assert not actual_match | |||||
| for unsupported_ext in unsupported_extensions: | |||||
| unsupported_filepath = f"something.{unsupported_ext}" | |||||
| actual_match = actual_unsupported_pattern.match(unsupported_filepath) | |||||
| assert actual_match | |||||
| def test_clean_sources_unsupported_artifacts(swh_config, requests_mock_datadir): | def test_clean_sources_unsupported_artifacts(swh_config, requests_mock_datadir): | ||||
| unsupported_file_extensions = [ | |||||
| "iso", | |||||
| "whl", | |||||
| "gem", | |||||
| "pom", | |||||
| "msi", | |||||
| "pod", | |||||
| "png", | |||||
| "rock", | |||||
| "ttf", | |||||
| "jar", | |||||
| "c", | |||||
| "el", | |||||
| "rpm", | |||||
| "diff", | |||||
| "patch", | |||||
| ] | |||||
| supported_sources = [ | supported_sources = [ | ||||
| { | { | ||||
| "type": "url", | "type": "url", | ||||
| "urls": [f"https://server.org/my-url.{ext}"], | "urls": [f"https://server.org/my-url.{ext}"], | ||||
| "integrity": "my-integrity", | "integrity": "my-integrity", | ||||
| } | } | ||||
| for ext in [ | for ext in [ | ||||
| "known-unknown-but-ok", # this is fine as well with the current approach | "known-unknown-but-ok", # this is fine as well with the current approach | ||||
| Show All 12 Lines | def test_clean_sources_unsupported_artifacts(swh_config, requests_mock_datadir): | ||||
| ] | ] | ||||
| unsupported_sources = [ | unsupported_sources = [ | ||||
| { | { | ||||
| "type": "url", | "type": "url", | ||||
| "urls": [f"https://server.org/my-url.{ext}"], | "urls": [f"https://server.org/my-url.{ext}"], | ||||
| "integrity": "my-integrity", | "integrity": "my-integrity", | ||||
| } | } | ||||
| for ext in [ | for ext in unsupported_file_extensions | ||||
| "iso", | |||||
| "whl", | |||||
| "gem", | |||||
| "pom", | |||||
| "msi", | |||||
| "pod", | |||||
| "png", | |||||
| "rock", | |||||
| "ttf", | |||||
| "jar", | |||||
| "c", | |||||
| "rpm", | |||||
| "diff", | |||||
| "patch", | |||||
| ] | |||||
| ] | ] | ||||
| sources = { | sources = { | ||||
| "version": 1, | "version": 1, | ||||
| "sources": supported_sources + unsupported_sources, | "sources": supported_sources + unsupported_sources, | ||||
| "revision": "my-revision", | "revision": "my-revision", | ||||
| } | } | ||||
| clean = clean_sources(sources) | clean = clean_sources(sources, unsupported_file_extensions) | ||||
| assert len(clean["sources"]) == len(supported_sources) | assert len(clean["sources"]) == len(supported_sources) | ||||
| def test_loader_one_visit(swh_config, requests_mock_datadir, raw_sources): | def test_loader_one_visit(swh_config, requests_mock_datadir, raw_sources): | ||||
| loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
| res = loader.load() | res = loader.load() | ||||
| assert res["status"] == "eventful" | assert res["status"] == "eventful" | ||||
| ▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines | |||||