mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-24 19:29:57 +00:00
100% coverage
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
|
||||
|
||||
@ -36,3 +38,59 @@ def test_build_status_from_json_view(build_status_failed: BuildStatus) -> None:
|
||||
must construct same object from json
|
||||
"""
|
||||
assert BuildStatus.from_json(build_status_failed.view()) == build_status_failed
|
||||
|
||||
|
||||
def test_build_status_pretty_print(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must return string in pretty print function
|
||||
"""
|
||||
assert build_status_failed.pretty_print()
|
||||
assert isinstance(build_status_failed.pretty_print(), str)
|
||||
|
||||
|
||||
def test_build_status_eq(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be equal
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
assert other == build_status_failed
|
||||
|
||||
|
||||
def test_build_status_eq_self(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be equal itself
|
||||
"""
|
||||
assert build_status_failed == build_status_failed
|
||||
|
||||
|
||||
def test_build_status_ne_by_status(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal by status
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
other.status = BuildStatusEnum.Success
|
||||
assert build_status_failed != other
|
||||
|
||||
|
||||
def test_build_status_ne_by_timestamp(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal by timestamp
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
other.timestamp = datetime.datetime.utcnow().timestamp()
|
||||
assert build_status_failed != other
|
||||
|
||||
|
||||
def test_build_status_ne_other(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal to random object
|
||||
"""
|
||||
assert build_status_failed != object()
|
||||
|
||||
|
||||
def test_build_status_repr(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must return string in __repr__ function
|
||||
"""
|
||||
assert build_status_failed.__repr__()
|
||||
assert isinstance(build_status_failed.__repr__(), str)
|
||||
|
@ -124,6 +124,17 @@ def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_pa
|
||||
assert package_ahriman == package
|
||||
|
||||
|
||||
def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load
|
||||
"""
|
||||
mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.from_build(Path("path"), package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_from_json_view_1(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must construct same object from json
|
||||
@ -190,6 +201,17 @@ def test_load_failure(package_ahriman: Package, pyalpm_handle: MagicMock, mocker
|
||||
Package.load(Path("path"), pyalpm_handle, package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_dependencies_failed(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load
|
||||
"""
|
||||
mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.dependencies(Path("path"))
|
||||
|
||||
|
||||
def test_dependencies_with_version(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load correct list of dependencies with version
|
||||
@ -227,12 +249,25 @@ def test_actual_version_vcs(package_tpacpi_bat_git: Package, repository_paths: R
|
||||
assert package_tpacpi_bat_git.actual_version(repository_paths) == "3.1.r13.g4959b52-1"
|
||||
|
||||
|
||||
def test_actual_version_srcinfo_failed(package_tpacpi_bat_git: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return same version in case if exception occurred
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package._check_output", side_effect=Exception())
|
||||
mocker.patch("ahriman.core.build_tools.task.Task.fetch")
|
||||
|
||||
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version
|
||||
|
||||
|
||||
def test_actual_version_vcs_failed(package_tpacpi_bat_git: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return same version in case if exception occurred
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package._check_output", side_effect=Exception())
|
||||
mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
mocker.patch("ahriman.models.package.Package._check_output")
|
||||
mocker.patch("ahriman.core.build_tools.task.Task.fetch")
|
||||
|
||||
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version
|
||||
@ -253,3 +288,11 @@ def test_is_outdated_true(package_ahriman: Package, repository_paths: Repository
|
||||
other.version = other.version.replace("-1", "-2")
|
||||
|
||||
assert package_ahriman.is_outdated(other, repository_paths)
|
||||
|
||||
|
||||
def test_build_status_pretty_print(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return string in pretty print function
|
||||
"""
|
||||
assert package_ahriman.pretty_print()
|
||||
assert isinstance(package_ahriman.pretty_print(), str)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from dataclasses import asdict
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
@ -19,6 +20,22 @@ def test_filepath_empty(package_description_ahriman: PackageDescription) -> None
|
||||
assert package_description_ahriman.filepath is None
|
||||
|
||||
|
||||
def test_from_json(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must construct description from json object
|
||||
"""
|
||||
assert PackageDescription.from_json(asdict(package_description_ahriman)) == package_description_ahriman
|
||||
|
||||
|
||||
def test_from_json_with_unknown_fields(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must construct description from json object containing unknown fields
|
||||
"""
|
||||
dump = asdict(package_description_ahriman)
|
||||
dump.update(unknown_field="value")
|
||||
assert PackageDescription.from_json(dump) == package_description_ahriman
|
||||
|
||||
|
||||
def test_from_package(package_description_ahriman: PackageDescription,
|
||||
pyalpm_package_description_ahriman: MagicMock) -> None:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user