mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
PEP-585 complaint: remove type aliases (#93)
This commit is contained in:
@ -99,7 +99,7 @@ def test_run_filter(args: argparse.Namespace, configuration: Configuration, repo
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
||||
|
||||
Rebuild.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_packages_mock.assert_called_once_with([], {"python-aur"})
|
||||
application_packages_mock.assert_called_once_with([], ["python-aur"])
|
||||
|
||||
|
||||
def test_run_without_filter(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
|
@ -3,7 +3,7 @@ import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, Dict, Type, TypeVar
|
||||
from typing import Any, TypeVar
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
@ -31,12 +31,12 @@ T = TypeVar("T")
|
||||
# helpers
|
||||
# https://stackoverflow.com/a/21611963
|
||||
@pytest.helpers.register
|
||||
def anyvar(cls: Type[T], strict: bool = False) -> T:
|
||||
def anyvar(cls: type[T], strict: bool = False) -> T:
|
||||
"""
|
||||
any value helper for mocker calls check
|
||||
|
||||
Args:
|
||||
cls(Type[T]): type of the variable to check
|
||||
cls(type[T]): type of the variable to check
|
||||
strict(bool, optional): if True then check type of supplied argument (Default value = False)
|
||||
|
||||
Returns:
|
||||
@ -61,7 +61,7 @@ def anyvar(cls: Type[T], strict: bool = False) -> T:
|
||||
|
||||
|
||||
@pytest.helpers.register
|
||||
def get_package_status(package: Package) -> Dict[str, Any]:
|
||||
def get_package_status(package: Package) -> dict[str, Any]:
|
||||
"""
|
||||
helper to extract package status from package
|
||||
|
||||
@ -69,13 +69,13 @@ def get_package_status(package: Package) -> Dict[str, Any]:
|
||||
package(Package): package object
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: simplified package status map (with only status and view)
|
||||
dict[str, Any]: simplified package status map (with only status and view)
|
||||
"""
|
||||
return {"status": BuildStatusEnum.Unknown.value, "package": package.view()}
|
||||
|
||||
|
||||
@pytest.helpers.register
|
||||
def get_package_status_extended(package: Package) -> Dict[str, Any]:
|
||||
def get_package_status_extended(package: Package) -> dict[str, Any]:
|
||||
"""
|
||||
helper to extract package status from package
|
||||
|
||||
@ -83,7 +83,7 @@ def get_package_status_extended(package: Package) -> Dict[str, Any]:
|
||||
package(Package): package object
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: full package status map (with timestamped build status and view)
|
||||
dict[str, Any]: full package status map (with timestamped build status and view)
|
||||
"""
|
||||
return {"status": BuildStatus().view(), "package": package.view()}
|
||||
|
||||
|
@ -125,7 +125,7 @@ def test_packages_depend_on(repository: Repository, package_ahriman: Package, pa
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
||||
return_value=[package_ahriman, package_python_schedule])
|
||||
assert repository.packages_depend_on([package_ahriman], ["python-srcinfo"]) == [package_ahriman]
|
||||
assert repository.packages_depend_on([package_ahriman], {"python-srcinfo"}) == [package_ahriman]
|
||||
|
||||
|
||||
def test_packages_depend_on_empty(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
@ -24,12 +24,12 @@ def github(configuration: Configuration) -> Github:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def github_release() -> Dict[str, Any]:
|
||||
def github_release() -> dict[str, Any]:
|
||||
"""
|
||||
fixture for the github release object
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: github test release object
|
||||
dict[str, Any]: github test release object
|
||||
"""
|
||||
return {
|
||||
"url": "release_url",
|
||||
@ -74,12 +74,12 @@ def s3(configuration: Configuration) -> S3:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def s3_remote_objects() -> List[MagicMock]:
|
||||
def s3_remote_objects() -> list[MagicMock]:
|
||||
"""
|
||||
fixture for boto3 like S3 objects
|
||||
|
||||
Returns:
|
||||
List[MagicMock]: boto3 like S3 objects test instance
|
||||
list[MagicMock]: boto3 like S3 objects test instance
|
||||
"""
|
||||
delete_mock = MagicMock()
|
||||
|
||||
|
@ -3,13 +3,13 @@ import requests
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.upload.github import Github
|
||||
|
||||
|
||||
def test_asset_remove(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_asset_remove(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove asset from the release
|
||||
"""
|
||||
@ -18,7 +18,7 @@ def test_asset_remove(github: Github, github_release: Dict[str, Any], mocker: Mo
|
||||
request_mock.assert_called_once_with("DELETE", "asset_url")
|
||||
|
||||
|
||||
def test_asset_remove_unknown(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_asset_remove_unknown(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail if no asset found
|
||||
"""
|
||||
@ -27,7 +27,7 @@ def test_asset_remove_unknown(github: Github, github_release: Dict[str, Any], mo
|
||||
request_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_asset_upload(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_asset_upload(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload asset to the repository
|
||||
"""
|
||||
@ -41,7 +41,7 @@ def test_asset_upload(github: Github, github_release: Dict[str, Any], mocker: Mo
|
||||
remove_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_asset_upload_with_removal(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_asset_upload_with_removal(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove existing file before upload
|
||||
"""
|
||||
@ -57,7 +57,7 @@ def test_asset_upload_with_removal(github: Github, github_release: Dict[str, Any
|
||||
])
|
||||
|
||||
|
||||
def test_asset_upload_empty_mimetype(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_asset_upload_empty_mimetype(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload asset to the repository with empty mime type if the library cannot guess it
|
||||
"""
|
||||
@ -80,7 +80,7 @@ def test_get_local_files(github: Github, resource_path_root: Path, mocker: Mocke
|
||||
walk_mock.assert_called()
|
||||
|
||||
|
||||
def test_files_remove(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_files_remove(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove files from the remote
|
||||
"""
|
||||
@ -89,7 +89,7 @@ def test_files_remove(github: Github, github_release: Dict[str, Any], mocker: Mo
|
||||
remove_mock.assert_called_once_with(github_release, "b")
|
||||
|
||||
|
||||
def test_files_remove_empty(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_files_remove_empty(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove nothing if nothing changed
|
||||
"""
|
||||
@ -98,7 +98,7 @@ def test_files_remove_empty(github: Github, github_release: Dict[str, Any], mock
|
||||
remove_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_files_upload(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_files_upload(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload files to the remote
|
||||
"""
|
||||
@ -110,7 +110,7 @@ def test_files_upload(github: Github, github_release: Dict[str, Any], mocker: Mo
|
||||
])
|
||||
|
||||
|
||||
def test_files_upload_empty(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_files_upload_empty(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload nothing if nothing changed
|
||||
"""
|
||||
@ -167,7 +167,7 @@ def test_release_get_exception_http_error(github: Github, mocker: MockerFixture)
|
||||
github.release_get()
|
||||
|
||||
|
||||
def test_release_update(github: Github, github_release: Dict[str, Any], mocker: MockerFixture) -> None:
|
||||
def test_release_update(github: Github, github_release: dict[str, Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update release
|
||||
"""
|
||||
|
@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, List, Optional, Tuple
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.core.upload.s3 import S3
|
||||
@ -33,7 +33,7 @@ def test_calculate_etag_small(resource_path_root: Path) -> None:
|
||||
assert S3.calculate_etag(path, _chunk_size) == "79b0f84e0232ed34fd191a85c383ecc5"
|
||||
|
||||
|
||||
def test_files_remove(s3_remote_objects: List[Any]) -> None:
|
||||
def test_files_remove(s3_remote_objects: list[Any]) -> None:
|
||||
"""
|
||||
must remove remote objects
|
||||
"""
|
||||
@ -46,11 +46,11 @@ def test_files_remove(s3_remote_objects: List[Any]) -> None:
|
||||
remote_objects[Path("x86_64/a")].delete.assert_called_once_with()
|
||||
|
||||
|
||||
def test_files_upload(s3: S3, s3_remote_objects: List[Any], mocker: MockerFixture) -> None:
|
||||
def test_files_upload(s3: S3, s3_remote_objects: list[Any], mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload changed files
|
||||
"""
|
||||
def mimetype(path: Path) -> Tuple[Optional[str], None]:
|
||||
def mimetype(path: Path) -> tuple[str | None, None]:
|
||||
return ("text/html", None) if path.name == "b" else (None, None)
|
||||
|
||||
root = Path("path")
|
||||
@ -87,7 +87,7 @@ def test_get_local_files(s3: S3, resource_path_root: Path, mocker: MockerFixture
|
||||
walk_mock.assert_called()
|
||||
|
||||
|
||||
def test_get_remote_objects(s3: S3, s3_remote_objects: List[Any]) -> None:
|
||||
def test_get_remote_objects(s3: S3, s3_remote_objects: list[Any]) -> None:
|
||||
"""
|
||||
must generate list of remote objects by calling boto3 function
|
||||
"""
|
||||
|
@ -5,12 +5,12 @@ import pyalpm # typing: ignore
|
||||
from dataclasses import asdict, fields
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
|
||||
|
||||
def _get_aur_data(resource_path_root: Path) -> Dict[str, Any]:
|
||||
def _get_aur_data(resource_path_root: Path) -> dict[str, Any]:
|
||||
"""
|
||||
load package description from resource file
|
||||
|
||||
@ -18,13 +18,13 @@ def _get_aur_data(resource_path_root: Path) -> Dict[str, Any]:
|
||||
resource_path_root(Path): path to resource root
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: json descriptor
|
||||
dict[str, Any]: json descriptor
|
||||
"""
|
||||
response = (resource_path_root / "models" / "package_ahriman_aur").read_text()
|
||||
return json.loads(response)["results"][0]
|
||||
|
||||
|
||||
def _get_official_data(resource_path_root: Path) -> Dict[str, Any]:
|
||||
def _get_official_data(resource_path_root: Path) -> dict[str, Any]:
|
||||
"""
|
||||
load package description from resource file
|
||||
|
||||
@ -32,7 +32,7 @@ def _get_official_data(resource_path_root: Path) -> Dict[str, Any]:
|
||||
resource_path_root(Path): path to resource root
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: json descriptor
|
||||
dict[str, Any]: json descriptor
|
||||
"""
|
||||
response = (resource_path_root / "models" / "package_akonadi_aur").read_text()
|
||||
return json.loads(response)["results"][0]
|
||||
|
@ -1,6 +1,6 @@
|
||||
from collections.abc import Callable
|
||||
from pytest_mock import MockerFixture
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.package_source import PackageSource
|
||||
|
@ -1,8 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Callable, Tuple
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.core.exceptions import PathError
|
||||
@ -10,7 +10,7 @@ from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def _get_owner(root: Path, same: bool) -> Callable[[Path], Tuple[int, int]]:
|
||||
def _get_owner(root: Path, same: bool) -> Callable[[Path], tuple[int, int]]:
|
||||
"""
|
||||
mocker function for owner definition
|
||||
|
||||
@ -19,7 +19,7 @@ def _get_owner(root: Path, same: bool) -> Callable[[Path], Tuple[int, int]]:
|
||||
same(bool): if True then returns the same as root directory and different otherwise
|
||||
|
||||
Returns:
|
||||
Callable[[Path], Tuple[int, int]]: function which can define ownership
|
||||
Callable[[Path], tuple[int, int]]: function which can define ownership
|
||||
"""
|
||||
root_owner = (42, 42)
|
||||
non_root_owner = (42, 42) if same else (1, 1)
|
||||
|
@ -3,9 +3,10 @@ import pytest
|
||||
from asyncio import BaseEventLoop
|
||||
from aiohttp.web import Application, Resource, UrlMappingMatchInfo
|
||||
from aiohttp.test_utils import TestClient
|
||||
from collections.abc import Awaitable, Callable
|
||||
from marshmallow import Schema
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, Awaitable, Callable, Dict, Optional
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import ahriman.core.auth.helpers
|
||||
@ -21,7 +22,7 @@ from ahriman.web.web import setup_service
|
||||
|
||||
@pytest.helpers.register
|
||||
def request(application: Application, path: str, method: str, json: Any = None, data: Any = None,
|
||||
extra: Optional[Dict[str, Any]] = None, resource: Optional[Resource] = None) -> MagicMock:
|
||||
extra: dict[str, Any] | None = None, resource: Resource | None = None) -> MagicMock:
|
||||
"""
|
||||
request generator helper
|
||||
|
||||
@ -31,8 +32,8 @@ def request(application: Application, path: str, method: str, json: Any = None,
|
||||
method(str): method for the request
|
||||
json(Any, optional): json payload of the request (Default value = None)
|
||||
data(Any, optional): form data payload of the request (Default value = None)
|
||||
extra(Optional[Dict[str, Any]], optional): extra info which will be injected for ``get_extra_info`` command
|
||||
resource(Optional[Resource], optional): optional web resource for the request (Default value = None)
|
||||
extra(dict[str, Any] | None, optional): extra info which will be injected for ``get_extra_info`` command
|
||||
resource(Resource | None, optional): optional web resource for the request (Default value = None)
|
||||
|
||||
Returns:
|
||||
MagicMock: dummy request mock
|
||||
@ -67,7 +68,7 @@ def schema_request(handler: Callable[..., Awaitable[Any]], *, location: str = "j
|
||||
Returns:
|
||||
Schema: request schema as set by the decorators
|
||||
"""
|
||||
schemas: List[Dict[str, Any]] = handler.__schemas__ # type: ignore
|
||||
schemas: list[dict[str, Any]] = handler.__schemas__ # type: ignore
|
||||
return next(schema["schema"] for schema in schemas if schema["put_into"] == location)
|
||||
|
||||
|
||||
@ -83,7 +84,7 @@ def schema_response(handler: Callable[..., Awaitable[Any]], *, code: int = 200)
|
||||
Returns:
|
||||
Schema: response schema as set by the decorators
|
||||
"""
|
||||
schemas: Dict[int, Any] = handler.__apispec__["responses"] # type: ignore
|
||||
schemas: dict[int, Any] = handler.__apispec__["responses"] # type: ignore
|
||||
schema = schemas[code]["schema"]
|
||||
if callable(schema):
|
||||
schema = schema()
|
||||
|
Reference in New Issue
Block a user