Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/tests/test_pypi.py
Show All 9 Lines | ||||||||
import pytest | import pytest | |||||||
from swh.core.pytest_plugin import requests_mock_datadir_factory | from swh.core.pytest_plugin import requests_mock_datadir_factory | |||||||
from swh.core.tarball import uncompress | from swh.core.tarball import uncompress | |||||||
from swh.loader.package import __version__ | from swh.loader.package import __version__ | |||||||
from swh.loader.package.pypi.loader import ( | from swh.loader.package.pypi.loader import ( | |||||||
PyPILoader, | PyPILoader, | |||||||
PyPIPackageInfo, | ||||||||
author, | author, | |||||||
extract_intrinsic_metadata, | extract_intrinsic_metadata, | |||||||
pypi_api_url, | pypi_api_url, | |||||||
) | ) | |||||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | |||||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | |||||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | |||||||
CoreSWHID, | CoreSWHID, | |||||||
▲ Show 20 Lines • Show All 778 Lines • ▼ Show 20 Lines | def test_pypi_origin_not_found(swh_storage, requests_mock_datadir): | |||||||
url = "https://pypi.org/project/unknown" | url = "https://pypi.org/project/unknown" | |||||||
loader = PyPILoader(swh_storage, url) | loader = PyPILoader(swh_storage, url) | |||||||
assert loader.load() == {"status": "failed"} | assert loader.load() == {"status": "failed"} | |||||||
assert_last_visit_matches( | assert_last_visit_matches( | |||||||
swh_storage, url, status="not_found", type="pypi", snapshot=None | swh_storage, url, status="not_found", type="pypi", snapshot=None | |||||||
) | ) | |||||||
def test_pypi_build_revision_missing_version_in_pkg_info(swh_storage, tmp_path): | ||||||||
"""Simulate revision build when Version field is missing in PKG-INFO file.""" | ||||||||
url = "https://pypi.org/project/GermlineFilter" | ||||||||
# create package info | ||||||||
p_info = PyPIPackageInfo( | ||||||||
url=url, | ||||||||
filename="GermlineFilter-1.2.tar.gz", | ||||||||
directory_extrinsic_metadata=[], | ||||||||
raw_info={}, | ||||||||
comment_text="", | ||||||||
sha256="e4982353c544d94b34f02c5690ab3d3ebc93480d5b62fe6f3317f23c515acc05", | ||||||||
upload_time="2015-02-18T20:39:13", | ||||||||
) | ||||||||
# create PKG-INFO file with missing Version field | ||||||||
package_path = tmp_path / "GermlineFilter-1.2" | ||||||||
pkg_info_path = package_path / "PKG-INFO" | ||||||||
package_path.mkdir() | ||||||||
pkg_info_path.write_text( | ||||||||
"""Metadata-Version: 1.2 | ||||||||
Name: germline_filter | ||||||||
Home-page: | ||||||||
Author: Cristian Caloian (OICR) | ||||||||
Author-email: cristian.caloian@oicr.on.ca | ||||||||
License: UNKNOWN | ||||||||
Description: UNKNOWN | ||||||||
Platform: UNKNOWN""" | ||||||||
) | ||||||||
directory = hash_to_bytes("8b864d66f356afe35033d58f8e03b7c23a66751f") | ||||||||
# attempt to build revision | ||||||||
loader = PyPILoader(swh_storage, url) | ||||||||
revision = loader.build_revision(p_info, str(tmp_path), directory) | ||||||||
# without comment_text and version in PKG-INFO, message should be empty | ||||||||
vlorentzUnsubmitted Not Done Inline Actions
vlorentz: | ||||||||
assert revision.message == b"" |