Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/tests/test_nixguix.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
import json | import json | ||||
import logging | import logging | ||||
import pytest | import pytest | ||||
from json.decoder import JSONDecodeError | from json.decoder import JSONDecodeError | ||||
from typing import Dict, Optional, Tuple | from swh.storage.interface import StorageInterface | ||||
from typing import Any, Dict, Iterable, Optional, Tuple, Union | |||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from swh.model.model import Snapshot | from swh.model.model import Snapshot, TargetType | ||||
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 ( | ||||
NixGuixLoader, | NixGuixLoader, | ||||
retrieve_sources, | retrieve_sources, | ||||
clean_sources, | clean_sources, | ||||
) | ) | ||||
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.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
get_stats, | get_stats, | ||||
check_snapshot, | check_snapshot as check_snapshot_full, | ||||
) | ) | ||||
sources_url = "https://nix-community.github.io/nixpkgs-swh/sources.json" | sources_url = "https://nix-community.github.io/nixpkgs-swh/sources.json" | ||||
def check_snapshot( | |||||
snapshot: Union[Dict[str, Any], Snapshot], | |||||
storage: StorageInterface, | |||||
allowed_empty: Iterable[Tuple[TargetType, bytes]] = [ | |||||
(TargetType.REVISION, b"evaluation") | |||||
], | |||||
): | |||||
return check_snapshot_full(snapshot, storage, allowed_empty) | |||||
def test_retrieve_sources(swh_config, requests_mock_datadir): | def test_retrieve_sources(swh_config, requests_mock_datadir): | ||||
j = retrieve_sources(sources_url) | j = retrieve_sources(sources_url) | ||||
assert "sources" in j.keys() | assert "sources" in j.keys() | ||||
assert len(j["sources"]) == 2 | assert len(j["sources"]) == 2 | ||||
def test_retrieve_non_existing(swh_config, requests_mock_datadir): | def test_retrieve_non_existing(swh_config, requests_mock_datadir): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
▲ Show 20 Lines • Show All 515 Lines • Show Last 20 Lines |