PEP-673 use Self as return type for classmethods (#94)

* PEP-673 use Self as return type for classmethods

* add dummy test file

* remove python3.10 compat
This commit is contained in:
2023-05-04 03:28:08 +03:00
committed by GitHub
parent 9dc6d56a8d
commit 2ff56965d9
98 changed files with 384 additions and 339 deletions

View File

@ -15,7 +15,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
Versions.run(args, "x86_64", configuration, report=False, unsafe=False)
application_mock.assert_called_once_with("ahriman", ("pacman", "s3", "web"))
application_mock.assert_called_once_with("ahriman")
print_mock.assert_has_calls([MockCall(verbose=False, separator=" "), MockCall(verbose=False, separator=" ")])
@ -23,7 +23,7 @@ def test_package_dependencies() -> None:
"""
must extract package dependencies
"""
packages = Versions.package_dependencies("srcinfo")
packages = dict(Versions.package_dependencies("srcinfo"))
assert packages
assert packages.get("parse") is not None
@ -32,7 +32,7 @@ def test_package_dependencies_missing() -> None:
"""
must extract package dependencies even if some of them are missing
"""
packages = Versions.package_dependencies("ahriman", ("docs", "pacman", "s3", "web"))
packages = dict(Versions.package_dependencies("ahriman"))
assert packages
assert packages.get("pyalpm") is not None
assert packages.get("Sphinx") is None

View File

@ -68,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[attr-defined]
return next(schema["schema"] for schema in schemas if schema["put_into"] == location)
@ -84,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[attr-defined]
schema = schemas[code]["schema"]
if callable(schema):
schema = schema()

View File

@ -1,22 +1,25 @@
import pytest
from aiohttp.test_utils import TestClient
from pytest_mock import MockerFixture
from typing import Any
from ahriman.models.user_access import UserAccess
from ahriman.web.views.api.swagger import SwaggerView
def _client(client: TestClient) -> TestClient:
def _client(client: TestClient, mocker: MockerFixture) -> TestClient:
"""
generate test client with docs
generate test client with docs. Thanks to deprecation, we can't change application state since it was run
Args:
client(TestClient): test client fixture
mocker(MockerFixture): mocker object
Returns:
TestClient: test client fixture with additional properties
"""
client.app["swagger_dict"] = {
swagger_dict = {
"paths": {
"/api/v1/logout": {
"get": {
@ -62,6 +65,14 @@ def _client(client: TestClient) -> TestClient:
},
],
}
source = client.app.__getitem__
def getitem(name: str) -> Any:
if name == "swagger_dict":
return swagger_dict
return source(name)
mocker.patch("aiohttp.web.Application.__getitem__", side_effect=getitem)
return client
@ -75,11 +86,11 @@ async def test_get_permission() -> None:
assert await SwaggerView.get_permission(request) == UserAccess.Unauthorized
async def test_get(client: TestClient) -> None:
async def test_get(client: TestClient, mocker: MockerFixture) -> None:
"""
must generate api-docs correctly
"""
client = _client(client)
client = _client(client, mocker)
response = await client.get("/api-docs/swagger.json")
assert response.ok