strict test checks

This commit is contained in:
Evgenii Alekseev 2022-03-03 22:35:10 +03:00
parent 9529525cb5
commit 9964a96296
62 changed files with 326 additions and 269 deletions

View File

@ -1 +1 @@
skips: ['B101', 'B404']
skips: ['B101', 'B105', 'B404']

View File

@ -3,4 +3,4 @@ test = pytest
[tool:pytest]
addopts = --cov=ahriman --cov-report term-missing:skip-covered --pspec
asyncio_mode = auto
asyncio_mode = legacy

View File

@ -23,7 +23,7 @@ import argparse
import logging
from multiprocessing import Pool
from typing import Set, Type
from typing import List, Type
from ahriman.application.lock import Lock
from ahriman.core.configuration import Configuration
@ -42,7 +42,7 @@ class Handler:
ALLOW_MULTI_ARCHITECTURE_RUN = True
@classmethod
def architectures_extract(cls: Type[Handler], args: argparse.Namespace) -> Set[str]:
def architectures_extract(cls: Type[Handler], args: argparse.Namespace) -> List[str]:
"""
get known architectures
:param args: command line args
@ -53,7 +53,7 @@ class Handler:
# for those cases architecture must be set explicitly
raise MissingArchitecture(args.command)
if args.architecture: # architecture is specified explicitly
return set(args.architecture)
return sorted(set(args.architecture))
config = Configuration()
config.load(args.configuration)
@ -63,7 +63,7 @@ class Handler:
if not architectures: # well we did not find anything
raise MissingArchitecture(args.command)
return architectures
return sorted(architectures)
@classmethod
def call(cls: Type[Handler], args: argparse.Namespace, architecture: str) -> bool:

View File

@ -144,7 +144,7 @@ class Setup(Handler):
:param packager: packager identifier (e.g. name, email)
:param paths: repository paths instance
"""
(paths.root / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n")
(paths.root / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n", encoding="utf8")
@staticmethod
def configuration_create_sudo(prefix: str, architecture: str) -> None:

View File

@ -12,8 +12,8 @@ def test_finalize(application: Application, mocker: MockerFixture) -> None:
sync_mock = mocker.patch("ahriman.application.application.Application.sync")
application._finalize([])
report_mock.assert_called_once()
sync_mock.assert_called_once()
report_mock.assert_called_once_with([], [])
sync_mock.assert_called_once_with([], [])
def test_known_packages(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:

View File

@ -33,7 +33,8 @@ def test_add_archive(application_packages: Packages, package_ahriman: Package, m
"""
copy_mock = mocker.patch("shutil.copy")
application_packages._add_archive(package_ahriman.base)
copy_mock.assert_called_once()
copy_mock.assert_called_once_with(
Path(package_ahriman.base), application_packages.repository.paths.packages / package_ahriman.base)
def test_add_aur(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -45,8 +46,12 @@ def test_add_aur(application_packages: Packages, package_ahriman: Package, mocke
dependencies_mock = mocker.patch("ahriman.application.application.packages.Packages._process_dependencies")
application_packages._add_aur(package_ahriman.base, set(), False)
load_mock.assert_called_once()
dependencies_mock.assert_called_once()
load_mock.assert_called_once_with(
application_packages.repository.paths.manual_for(package_ahriman.base),
package_ahriman.git_url,
application_packages.repository.paths.patches_for(package_ahriman.base))
dependencies_mock.assert_called_once_with(
application_packages.repository.paths.manual_for(package_ahriman.base), set(), False)
def test_add_directory(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -56,10 +61,11 @@ def test_add_directory(application_packages: Packages, package_ahriman: Package,
iterdir_mock = mocker.patch("pathlib.Path.iterdir",
return_value=[package.filepath for package in package_ahriman.packages.values()])
copy_mock = mocker.patch("shutil.copy")
filename = package_ahriman.packages[package_ahriman.base].filepath
application_packages._add_directory(package_ahriman.base)
iterdir_mock.assert_called_once()
copy_mock.assert_called_once()
iterdir_mock.assert_called_once_with()
copy_mock.assert_called_once_with(filename, application_packages.repository.paths.packages / filename.name)
def test_add_local(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -72,13 +78,14 @@ def test_add_local(application_packages: Packages, package_ahriman: Package, moc
dependencies_mock = mocker.patch("ahriman.application.application.packages.Packages._process_dependencies")
application_packages._add_local(package_ahriman.base, set(), False)
init_mock.assert_called_once()
init_mock.assert_called_once_with(application_packages.repository.paths.cache_for(package_ahriman.base))
copytree_mock.assert_has_calls([
mock.call(Path(package_ahriman.base), application_packages.repository.paths.cache_for(package_ahriman.base)),
mock.call(application_packages.repository.paths.cache_for(package_ahriman.base),
application_packages.repository.paths.manual_for(package_ahriman.base)),
])
dependencies_mock.assert_called_once()
dependencies_mock.assert_called_once_with(
application_packages.repository.paths.manual_for(package_ahriman.base), set(), False)
def test_add_remote(application_packages: Packages, package_description_ahriman: PackageDescription,
@ -95,7 +102,7 @@ def test_add_remote(application_packages: Packages, package_description_ahriman:
application_packages._add_remote(url)
open_mock.assert_called_once_with("wb")
request_mock.assert_called_once_with(url, stream=True)
response_mock.raise_for_status.assert_called_once()
response_mock.raise_for_status.assert_called_once_with()
def test_process_dependencies(application_packages: Packages, mocker: MockerFixture) -> None:
@ -146,7 +153,7 @@ def test_add_add_archive(application_packages: Packages, package_ahriman: Packag
add_mock = mocker.patch("ahriman.application.application.packages.Packages._add_archive")
application_packages.add([package_ahriman.base], PackageSource.Archive, False)
add_mock.assert_called_once()
add_mock.assert_called_once_with(package_ahriman.base, set(), False)
def test_add_add_aur(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -157,7 +164,7 @@ def test_add_add_aur(application_packages: Packages, package_ahriman: Package, m
add_mock = mocker.patch("ahriman.application.application.packages.Packages._add_aur")
application_packages.add([package_ahriman.base], PackageSource.AUR, True)
add_mock.assert_called_once()
add_mock.assert_called_once_with(package_ahriman.base, set(), True)
def test_add_add_directory(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -168,7 +175,7 @@ def test_add_add_directory(application_packages: Packages, package_ahriman: Pack
add_mock = mocker.patch("ahriman.application.application.packages.Packages._add_directory")
application_packages.add([package_ahriman.base], PackageSource.Directory, False)
add_mock.assert_called_once()
add_mock.assert_called_once_with(package_ahriman.base, set(), False)
def test_add_add_local(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -179,7 +186,7 @@ def test_add_add_local(application_packages: Packages, package_ahriman: Package,
add_mock = mocker.patch("ahriman.application.application.packages.Packages._add_local")
application_packages.add([package_ahriman.base], PackageSource.Local, False)
add_mock.assert_called_once()
add_mock.assert_called_once_with(package_ahriman.base, set(), False)
def test_add_add_remote(application_packages: Packages, package_description_ahriman: PackageDescription,
@ -192,7 +199,7 @@ def test_add_add_remote(application_packages: Packages, package_description_ahri
url = f"https://host/{package_description_ahriman.filename}"
application_packages.add([url], PackageSource.Remote, False)
add_mock.assert_called_once()
add_mock.assert_called_once_with(url, set(), False)
def test_remove(application_packages: Packages, mocker: MockerFixture) -> None:
@ -203,5 +210,5 @@ def test_remove(application_packages: Packages, mocker: MockerFixture) -> None:
finalize_mock = mocker.patch("ahriman.application.application.packages.Packages._finalize")
application_packages.remove([])
executor_mock.assert_called_once()
finalize_mock.assert_called_once()
executor_mock.assert_called_once_with([])
finalize_mock.assert_called_once_with([])

View File

@ -22,7 +22,7 @@ def test_clean_build(application_repository: Repository, mocker: MockerFixture)
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_build")
application_repository.clean(True, False, False, False, False, False)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_clean_cache(application_repository: Repository, mocker: MockerFixture) -> None:
@ -31,7 +31,7 @@ def test_clean_cache(application_repository: Repository, mocker: MockerFixture)
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
application_repository.clean(False, True, False, False, False, False)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_clean_chroot(application_repository: Repository, mocker: MockerFixture) -> None:
@ -40,7 +40,7 @@ def test_clean_chroot(application_repository: Repository, mocker: MockerFixture)
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_chroot")
application_repository.clean(False, False, True, False, False, False)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_clean_manual(application_repository: Repository, mocker: MockerFixture) -> None:
@ -49,7 +49,7 @@ def test_clean_manual(application_repository: Repository, mocker: MockerFixture)
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_manual")
application_repository.clean(False, False, False, True, False, False)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_clean_packages(application_repository: Repository, mocker: MockerFixture) -> None:
@ -58,7 +58,7 @@ def test_clean_packages(application_repository: Repository, mocker: MockerFixtur
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_packages")
application_repository.clean(False, False, False, False, True, False)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_clean_patches(application_repository: Repository, mocker: MockerFixture) -> None:
@ -67,7 +67,7 @@ def test_clean_patches(application_repository: Repository, mocker: MockerFixture
"""
clear_mock = mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_patches")
application_repository.clean(False, False, False, False, False, True)
clear_mock.assert_called_once()
clear_mock.assert_called_once_with()
def test_report(application_repository: Repository, mocker: MockerFixture) -> None:
@ -75,8 +75,8 @@ def test_report(application_repository: Repository, mocker: MockerFixture) -> No
must generate report
"""
executor_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_report")
application_repository.report([], [])
executor_mock.assert_called_once()
application_repository.report(["a"], [])
executor_mock.assert_called_once_with(["a"], [])
def test_sign(application_repository: Repository, package_ahriman: Package, package_python_schedule: Package,
@ -93,12 +93,12 @@ def test_sign(application_repository: Repository, package_ahriman: Package, pack
application_repository.sign([])
copy_mock.assert_has_calls([
mock.call(pytest.helpers.anyvar(str), pytest.helpers.anyvar(str)),
mock.call(pytest.helpers.anyvar(str), pytest.helpers.anyvar(str))
mock.call(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int)),
mock.call(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
])
update_mock.assert_called_once_with([])
sign_repository_mock.assert_called_once()
finalize_mock.assert_called_once()
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
finalize_mock.assert_called_once_with([])
def test_sign_skip(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -125,11 +125,14 @@ def test_sign_specific(application_repository: Repository, package_ahriman: Pack
sign_repository_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process_sign_repository")
finalize_mock = mocker.patch("ahriman.application.application.repository.Repository._finalize")
filename = package_ahriman.packages[package_ahriman.base].filepath
application_repository.sign([package_ahriman.base])
copy_mock.assert_called_once()
copy_mock.assert_called_once_with(
application_repository.repository.paths.repository / filename.name,
application_repository.repository.paths.packages / filename.name)
update_mock.assert_called_once_with([])
sign_repository_mock.assert_called_once()
finalize_mock.assert_called_once()
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
finalize_mock.assert_called_once_with([])
def test_sync(application_repository: Repository, mocker: MockerFixture) -> None:
@ -137,8 +140,8 @@ def test_sync(application_repository: Repository, mocker: MockerFixture) -> None
must sync to remote
"""
executor_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_sync")
application_repository.sync([], [])
executor_mock.assert_called_once()
application_repository.sync(["a"], [])
executor_mock.assert_called_once_with(["a"], [])
def test_unknown_no_aur(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -193,7 +196,7 @@ def test_update(application_repository: Repository, package_ahriman: Package, mo
finalize_mock = mocker.patch("ahriman.application.application.repository.Repository._finalize")
application_repository.update([package_ahriman])
build_mock.assert_called_once()
build_mock.assert_called_once_with([package_ahriman])
update_mock.assert_called_once_with(paths)
finalize_mock.assert_called_once_with([package_ahriman])
@ -210,8 +213,8 @@ def test_updates_all(application_repository: Repository, package_ahriman: Packag
application_repository.updates([], no_aur=False, no_local=False, no_manual=False, no_vcs=False, log_fn=print)
updates_aur_mock.assert_called_once_with([], False)
updates_local_mock.assert_called_once()
updates_manual_mock.assert_called_once()
updates_local_mock.assert_called_once_with()
updates_manual_mock.assert_called_once_with()
def test_updates_disabled(application_repository: Repository, mocker: MockerFixture) -> None:
@ -240,8 +243,8 @@ def test_updates_no_aur(application_repository: Repository, mocker: MockerFixtur
application_repository.updates([], no_aur=True, no_local=False, no_manual=False, no_vcs=False, log_fn=print)
updates_aur_mock.assert_not_called()
updates_local_mock.assert_called_once()
updates_manual_mock.assert_called_once()
updates_local_mock.assert_called_once_with()
updates_manual_mock.assert_called_once_with()
def test_updates_no_local(application_repository: Repository, mocker: MockerFixture) -> None:
@ -256,7 +259,7 @@ def test_updates_no_local(application_repository: Repository, mocker: MockerFixt
application_repository.updates([], no_aur=False, no_local=True, no_manual=False, no_vcs=False, log_fn=print)
updates_aur_mock.assert_called_once_with([], False)
updates_local_mock.assert_not_called()
updates_manual_mock.assert_called_once()
updates_manual_mock.assert_called_once_with()
def test_updates_no_manual(application_repository: Repository, mocker: MockerFixture) -> None:
@ -270,7 +273,7 @@ def test_updates_no_manual(application_repository: Repository, mocker: MockerFix
application_repository.updates([], no_aur=False, no_local=False, no_manual=True, no_vcs=False, log_fn=print)
updates_aur_mock.assert_called_once_with([], False)
updates_local_mock.assert_called_once()
updates_local_mock.assert_called_once_with()
updates_manual_mock.assert_not_called()
@ -285,8 +288,8 @@ def test_updates_no_vcs(application_repository: Repository, mocker: MockerFixtur
application_repository.updates([], no_aur=False, no_local=False, no_manual=False, no_vcs=True, log_fn=print)
updates_aur_mock.assert_called_once_with([], True)
updates_local_mock.assert_called_once()
updates_manual_mock.assert_called_once()
updates_local_mock.assert_called_once_with()
updates_manual_mock.assert_called_once_with()
def test_updates_with_filter(application_repository: Repository, mocker: MockerFixture) -> None:
@ -301,5 +304,5 @@ def test_updates_with_filter(application_repository: Repository, mocker: MockerF
application_repository.updates(["filter"], no_aur=False, no_local=False, no_manual=False, no_vcs=False,
log_fn=print)
updates_aur_mock.assert_called_once_with(["filter"], False)
updates_local_mock.assert_called_once()
updates_manual_mock.assert_called_once()
updates_local_mock.assert_called_once_with()
updates_manual_mock.assert_called_once_with()

View File

@ -17,7 +17,7 @@ def test_architectures_extract(args: argparse.Namespace, configuration: Configur
known_architectures_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures")
Handler.architectures_extract(args)
known_architectures_mock.assert_called_once()
known_architectures_mock.assert_called_once_with(configuration.getpath("repository", "root"))
def test_architectures_extract_empty(args: argparse.Namespace, configuration: Configuration,
@ -48,7 +48,7 @@ def test_architectures_extract_specified(args: argparse.Namespace) -> None:
must return architecture list if it has been specified
"""
architectures = args.architecture = ["i686", "x86_64"]
assert Handler.architectures_extract(args) == set(architectures)
assert Handler.architectures_extract(args) == sorted(set(architectures))
def test_call(args: argparse.Namespace, mocker: MockerFixture) -> None:
@ -63,8 +63,8 @@ def test_call(args: argparse.Namespace, mocker: MockerFixture) -> None:
exit_mock = mocker.patch("ahriman.application.lock.Lock.__exit__")
assert Handler.call(args, "x86_64")
enter_mock.assert_called_once()
exit_mock.assert_called_once()
enter_mock.assert_called_once_with()
exit_mock.assert_called_once_with(None, None, None)
def test_call_exception(args: argparse.Namespace, mocker: MockerFixture) -> None:
@ -83,7 +83,7 @@ def test_execute(args: argparse.Namespace, mocker: MockerFixture) -> None:
starmap_mock = mocker.patch("multiprocessing.pool.Pool.starmap")
Handler.execute(args)
starmap_mock.assert_called_once()
starmap_mock.assert_called_once_with(Handler.call, [(args, architecture) for architecture in args.architecture])
def test_execute_multiple_not_supported(args: argparse.Namespace, mocker: MockerFixture) -> None:

View File

@ -1,9 +1,11 @@
import argparse
import pytest
from pytest_mock import MockerFixture
from ahriman.application.handlers import Add
from ahriman.core.configuration import Configuration
from ahriman.models.package import Package
from ahriman.models.package_source import PackageSource
@ -29,10 +31,11 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.add")
Add.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(args.package, args.source, args.without_dependencies)
def test_run_with_updates(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
def test_run_with_updates(args: argparse.Namespace, configuration: Configuration,
package_ahriman: Package, mocker: MockerFixture) -> None:
"""
must run command with updates after
"""
@ -41,8 +44,8 @@ def test_run_with_updates(args: argparse.Namespace, configuration: Configuration
mocker.patch("ahriman.application.application.Application.add")
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
application_mock = mocker.patch("ahriman.application.application.Application.update")
updates_mock = mocker.patch("ahriman.application.application.Application.updates")
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
Add.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
updates_mock.assert_called_once()
updates_mock.assert_called_once_with(args.package, True, True, False, True, pytest.helpers.anyvar(int))
application_mock.assert_called_once_with([package_ahriman])

View File

@ -30,4 +30,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.clean")
Clean.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(False, False, False, False, False, False)

View File

@ -16,7 +16,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
return_value=configuration.dump())
Dump.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with()
print_mock.assert_called()

View File

@ -15,8 +15,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
init_mock = mocker.patch("ahriman.core.alpm.repo.Repo.init")
Init.run(args, "x86_64", configuration, True)
tree_create_mock.assert_called_once()
init_mock.assert_called_once()
tree_create_mock.assert_called_once_with()
init_mock.assert_called_once_with()
def test_disallow_auto_architecture_run() -> None:

View File

@ -26,7 +26,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.core.sign.gpg.GPG.key_import")
KeyImport.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(args.key_server, args.key)
def test_disallow_auto_architecture_run() -> None:

View File

@ -1,4 +1,5 @@
import argparse
import pytest
from pathlib import Path
from pytest_mock import MockerFixture
@ -32,7 +33,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_create")
Patch.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, args.track)
def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -45,7 +46,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list")
Patch.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package)
def test_run_remove(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -58,7 +59,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, mock
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_remove")
Patch.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package)
def test_patch_set_list(application: Application, mocker: MockerFixture) -> None:

View File

@ -18,18 +18,20 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
return args
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
def test_run(args: argparse.Namespace, package_ahriman: Package,
configuration: Configuration, mocker: MockerFixture) -> None:
"""
must run command
"""
args = _default_args(args)
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depends_on")
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depends_on",
return_value=[package_ahriman])
application_mock = mocker.patch("ahriman.application.application.Application.update")
Rebuild.run(args, "x86_64", configuration, True)
application_packages_mock.assert_called_once()
application_mock.assert_called_once()
application_packages_mock.assert_called_once_with(None)
application_mock.assert_called_once_with([package_ahriman])
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration,

View File

@ -25,4 +25,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.remove")
Remove.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with([])

View File

@ -18,18 +18,20 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
return args
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
def test_run(args: argparse.Namespace, package_ahriman: Package,
configuration: Configuration, mocker: MockerFixture) -> None:
"""
must run command
"""
args = _default_args(args)
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
application_mock = mocker.patch("ahriman.application.application.Application.unknown")
application_mock = mocker.patch("ahriman.application.application.Application.unknown",
return_value=[package_ahriman])
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
RemoveUnknown.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
remove_mock.assert_called_once()
application_mock.assert_called_once_with()
remove_mock.assert_called_once_with([package_ahriman])
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
@ -46,7 +48,7 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, pac
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
RemoveUnknown.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with()
remove_mock.assert_not_called()
print_mock.assert_called_once_with(False)
@ -66,6 +68,6 @@ def test_run_dry_run_verbose(args: argparse.Namespace, configuration: Configurat
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
RemoveUnknown.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with()
remove_mock.assert_not_called()
print_mock.assert_called_once_with(True)

View File

@ -25,4 +25,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.report")
Report.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(args.target, [])

View File

@ -33,7 +33,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, aur_package
Search.run(args, "x86_64", configuration, True)
search_mock.assert_called_once_with("ahriman")
print_mock.assert_called_once()
print_mock.assert_called_once_with(False)
def test_run_sort(args: argparse.Namespace, configuration: Configuration, aur_package_ahriman: AURPackage,

View File

@ -1,4 +1,5 @@
import argparse
import pytest
from pathlib import Path
from pytest_mock import MockerFixture
@ -38,13 +39,15 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
paths = RepositoryPaths(configuration.getpath("repository", "root"), "x86_64")
Setup.run(args, "x86_64", configuration, True)
ahriman_configuration_mock.assert_called_once()
devtools_configuration_mock.assert_called_once()
makepkg_configuration_mock.assert_called_once()
sudo_configuration_mock.assert_called_once()
executable_mock.assert_called_once()
ahriman_configuration_mock.assert_called_once_with(args, "x86_64", args.repository, configuration.include)
devtools_configuration_mock.assert_called_once_with(args.build_command, "x86_64", args.from_configuration,
args.no_multilib, args.repository, paths)
makepkg_configuration_mock.assert_called_once_with(args.packager, paths)
sudo_configuration_mock.assert_called_once_with(args.build_command, "x86_64")
executable_mock.assert_called_once_with(args.build_command, "x86_64")
def test_build_command(args: argparse.Namespace) -> None:
@ -75,7 +78,7 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C
mock.call(Configuration.section_name("sign", "x86_64"), "key", args.sign_key),
mock.call(Configuration.section_name("web", "x86_64"), "port", str(args.web_port)),
])
write_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_configuration_create_devtools(args: argparse.Namespace, repository_paths: RepositoryPaths,
@ -95,7 +98,7 @@ def test_configuration_create_devtools(args: argparse.Namespace, repository_path
mock.call("multilib"),
mock.call(args.repository)
])
write_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, repository_paths: RepositoryPaths,
@ -110,7 +113,7 @@ def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, rep
Setup.configuration_create_devtools(args.build_command, "x86_64", args.from_configuration,
True, args.repository, repository_paths)
write_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths,
@ -122,7 +125,7 @@ def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths
write_text_mock = mocker.patch("pathlib.Path.write_text")
Setup.configuration_create_makepkg(args.packager, repository_paths)
write_text_mock.assert_called_once()
write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8")
def test_configuration_create_sudo(args: argparse.Namespace, mocker: MockerFixture) -> None:
@ -135,7 +138,7 @@ def test_configuration_create_sudo(args: argparse.Namespace, mocker: MockerFixtu
Setup.configuration_create_sudo(args.build_command, "x86_64")
chmod_text_mock.assert_called_once_with(0o400)
write_text_mock.assert_called_once()
write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8")
def test_executable_create(args: argparse.Namespace, mocker: MockerFixture) -> None:
@ -147,8 +150,8 @@ def test_executable_create(args: argparse.Namespace, mocker: MockerFixture) -> N
unlink_text_mock = mocker.patch("pathlib.Path.unlink")
Setup.executable_create(args.build_command, "x86_64")
symlink_text_mock.assert_called_once()
unlink_text_mock.assert_called_once()
symlink_text_mock.assert_called_once_with(Setup.ARCHBUILD_COMMAND_PATH)
unlink_text_mock.assert_called_once_with(missing_ok=True)
def test_disallow_auto_architecture_run() -> None:

View File

@ -25,4 +25,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.sign")
Sign.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with([])

View File

@ -36,8 +36,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, package_ahr
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
Status.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
packages_mock.assert_called_once()
application_mock.assert_called_once_with()
packages_mock.assert_called_once_with(None)
print_mock.assert_has_calls([mock.call(False) for _ in range(3)])
@ -98,7 +98,7 @@ def test_imply_with_report(args: argparse.Namespace, configuration: Configuratio
load_mock = mocker.patch("ahriman.core.status.client.Client.load")
Status.run(args, "x86_64", configuration, True)
load_mock.assert_called_once()
load_mock.assert_called_once_with(configuration)
def test_disallow_auto_architecture_run() -> None:

View File

@ -30,7 +30,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
update_self_mock = mocker.patch("ahriman.core.status.client.Client.update_self")
StatusUpdate.run(args, "x86_64", configuration, True)
update_self_mock.assert_called_once()
update_self_mock.assert_called_once_with(args.status)
def test_run_packages(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
@ -44,7 +44,7 @@ def test_run_packages(args: argparse.Namespace, configuration: Configuration, pa
update_mock = mocker.patch("ahriman.core.status.client.Client.update")
StatusUpdate.run(args, "x86_64", configuration, True)
update_mock.assert_called_once()
update_mock.assert_called_once_with(package_ahriman.base, args.status)
def test_run_remove(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
@ -59,7 +59,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, pack
update_mock = mocker.patch("ahriman.core.status.client.Client.remove")
StatusUpdate.run(args, "x86_64", configuration, True)
update_mock.assert_called_once()
update_mock.assert_called_once_with(package_ahriman.base)
def test_imply_with_report(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -71,7 +71,7 @@ def test_imply_with_report(args: argparse.Namespace, configuration: Configuratio
load_mock = mocker.patch("ahriman.core.status.client.Client.load")
StatusUpdate.run(args, "x86_64", configuration, True)
load_mock.assert_called_once()
load_mock.assert_called_once_with(configuration)
def test_disallow_auto_architecture_run() -> None:

View File

@ -25,4 +25,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
application_mock = mocker.patch("ahriman.application.application.Application.sync")
Sync.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
application_mock.assert_called_once_with(args.target, [])

View File

@ -1,10 +1,12 @@
import argparse
import pytest
from pytest_mock import MockerFixture
from ahriman.application.application import Application
from ahriman.application.handlers import Update
from ahriman.core.configuration import Configuration
from ahriman.models.package import Package
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
@ -22,18 +24,20 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
return args
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
def test_run(args: argparse.Namespace, package_ahriman: Package,
configuration: Configuration, mocker: MockerFixture) -> None:
"""
must run command
"""
args = _default_args(args)
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
application_mock = mocker.patch("ahriman.application.application.Application.update")
updates_mock = mocker.patch("ahriman.application.application.Application.updates")
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
Update.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
updates_mock.assert_called_once()
application_mock.assert_called_once_with([package_ahriman])
updates_mock.assert_called_once_with(args.package, args.no_aur, args.no_local, args.no_manual, args.no_vcs,
pytest.helpers.anyvar(int))
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -46,7 +50,8 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, moc
updates_mock = mocker.patch("ahriman.application.application.Application.updates")
Update.run(args, "x86_64", configuration, True)
updates_mock.assert_called_once()
updates_mock.assert_called_once_with(args.package, args.no_aur, args.no_local, args.no_manual, args.no_vcs,
pytest.helpers.anyvar(int))
def test_log_fn(application: Application, mocker: MockerFixture) -> None:
@ -55,4 +60,4 @@ def test_log_fn(application: Application, mocker: MockerFixture) -> None:
"""
logger_mock = mocker.patch("logging.Logger.info")
Update.log_fn(application, False)("hello")
logger_mock.assert_called_once()
logger_mock.assert_called_once_with("hello")

View File

@ -42,12 +42,13 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
reload_mock = mocker.patch("ahriman.core.status.client.Client.reload_auth")
User.run(args, "x86_64", configuration, True)
get_auth_configuration_mock.assert_called_once()
create_configuration_mock.assert_called_once()
create_user_mock.assert_called_once()
get_salt_mock.assert_called_once()
write_configuration_mock.assert_called_once()
reload_mock.assert_called_once()
get_auth_configuration_mock.assert_called_once_with(configuration.include)
create_configuration_mock.assert_called_once_with(
pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), args.as_service)
create_user_mock.assert_called_once_with(args)
get_salt_mock.assert_called_once_with(configuration)
write_configuration_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.secure)
reload_mock.assert_called_once_with()
def test_run_remove(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -63,10 +64,10 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, mock
reload_mock = mocker.patch("ahriman.core.status.client.Client.reload_auth")
User.run(args, "x86_64", configuration, True)
get_auth_configuration_mock.assert_called_once()
get_auth_configuration_mock.assert_called_once_with(configuration.include)
create_configuration_mock.assert_not_called()
write_configuration_mock.assert_called_once()
reload_mock.assert_called_once()
write_configuration_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.secure)
reload_mock.assert_called_once_with()
def test_run_no_reload(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
@ -94,8 +95,8 @@ def test_configuration_create(configuration: Configuration, user: MUser, mocker:
User.configuration_create(configuration, user, "salt", False)
set_mock.assert_has_calls([
mock.call("auth", "salt", pytest.helpers.anyvar(str)),
mock.call(section, user.username, pytest.helpers.anyvar(str))
mock.call("auth", "salt", pytest.helpers.anyvar(int)),
mock.call(section, user.username, pytest.helpers.anyvar(int))
])
@ -139,7 +140,7 @@ def test_configuration_get_exists(mocker: MockerFixture) -> None:
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
assert User.configuration_get(Path("path"))
read_mock.assert_called_once()
read_mock.assert_called_once_with(Path("path") / "auth.ini")
def test_configuration_get_not_exists(mocker: MockerFixture) -> None:
@ -151,7 +152,7 @@ def test_configuration_get_not_exists(mocker: MockerFixture) -> None:
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
assert User.configuration_get(Path("path"))
read_mock.assert_called_once()
read_mock.assert_called_once_with(Path("path") / "auth.ini")
def test_configuration_write(configuration: Configuration, mocker: MockerFixture) -> None:
@ -163,8 +164,8 @@ def test_configuration_write(configuration: Configuration, mocker: MockerFixture
chmod_mock = mocker.patch("pathlib.Path.chmod")
User.configuration_write(configuration, secure=True)
write_mock.assert_called_once()
chmod_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
chmod_mock.assert_called_once_with(0o600)
def test_configuration_write_insecure(configuration: Configuration, mocker: MockerFixture) -> None:
@ -256,7 +257,7 @@ def test_user_create_getpass(args: argparse.Namespace, mocker: MockerFixture) ->
getpass_mock = mocker.patch("getpass.getpass", return_value="password")
generated = User.user_create(args)
getpass_mock.assert_called_once()
getpass_mock.assert_called_once_with()
assert generated.password == "password"

View File

@ -1,4 +1,5 @@
import argparse
import pytest
from pytest_mock import MockerFixture
@ -27,8 +28,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
run_mock = mocker.patch("ahriman.web.web.run_server")
Web.run(args, "x86_64", configuration, True)
setup_mock.assert_called_once()
run_mock.assert_called_once()
setup_mock.assert_called_once_with("x86_64", configuration, pytest.helpers.anyvar(int))
run_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_disallow_auto_architecture_run() -> None:

View File

@ -473,4 +473,4 @@ def test_run(args: argparse.Namespace, mocker: MockerFixture) -> None:
exit_mock = mocker.patch("sys.exit")
ahriman.run()
exit_mock.assert_called_once()
exit_mock.assert_called_once_with(1)

View File

@ -24,10 +24,10 @@ def test_enter(lock: Lock, mocker: MockerFixture) -> None:
with lock:
pass
check_user_mock.assert_called_once()
clear_mock.assert_called_once()
create_mock.assert_called_once()
check_version_mock.assert_called_once()
check_user_mock.assert_called_once_with()
clear_mock.assert_called_once_with()
create_mock.assert_called_once_with()
check_version_mock.assert_called_once_with()
update_status_mock.assert_has_calls([
mock.call(BuildStatusEnum.Building),
mock.call(BuildStatusEnum.Success)
@ -66,14 +66,14 @@ def test_check_version(lock: Lock, mocker: MockerFixture) -> None:
def test_check_version_mismatch(lock: Lock, mocker: MockerFixture) -> None:
"""
must check version correctly
must check mismatched version correctly
"""
mocker.patch("ahriman.core.status.client.Client.get_internal",
return_value=InternalStatus(version="version"))
logging_mock = mocker.patch("logging.Logger.warning")
lock.check_version()
logging_mock.assert_called_once()
logging_mock.assert_called_once() # we do not check logging arguments
def test_check_user(lock: Lock, mocker: MockerFixture) -> None:

View File

@ -20,7 +20,7 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
repo.add(Path("path"))
check_output_mock.assert_called_once()
check_output_mock.assert_called_once() # it will be checked later
assert check_output_mock.call_args[0][0] == "repo-add"
@ -31,7 +31,7 @@ def test_repo_init(repo: Repo, mocker: MockerFixture) -> None:
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
repo.init()
check_output_mock.assert_called_once()
check_output_mock.assert_called_once() # it will be checked later
assert check_output_mock.call_args[0][0] == "repo-add"
@ -43,7 +43,7 @@ def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None:
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
repo.remove("package", Path("package.pkg.tar.xz"))
check_output_mock.assert_called_once()
check_output_mock.assert_called_once() # it will be checked later
assert check_output_mock.call_args[0][0] == "repo-remove"

View File

@ -39,7 +39,7 @@ async def test_authorized_userid_library(mocker: MockerFixture) -> None:
mocker.patch.object(helpers, "_has_aiohttp_security", True)
authorized_userid_mock = mocker.patch("aiohttp_security.authorized_userid")
await helpers.authorized_userid()
authorized_userid_mock.assert_called_once()
authorized_userid_mock.assert_called_once_with()
async def test_check_authorized_dummy(mocker: MockerFixture) -> None:
@ -59,7 +59,7 @@ async def test_check_authorized_library(mocker: MockerFixture) -> None:
mocker.patch.object(helpers, "_has_aiohttp_security", True)
check_authorized_mock = mocker.patch("aiohttp_security.check_authorized")
await helpers.check_authorized()
check_authorized_mock.assert_called_once()
check_authorized_mock.assert_called_once_with()
async def test_forget_dummy(mocker: MockerFixture) -> None:
@ -79,7 +79,7 @@ async def test_forget_library(mocker: MockerFixture) -> None:
mocker.patch.object(helpers, "_has_aiohttp_security", True)
forget_mock = mocker.patch("aiohttp_security.forget")
await helpers.forget()
forget_mock.assert_called_once()
forget_mock.assert_called_once_with()
async def test_remember_dummy(mocker: MockerFixture) -> None:
@ -99,4 +99,4 @@ async def test_remember_library(mocker: MockerFixture) -> None:
mocker.patch.object(helpers, "_has_aiohttp_security", True)
remember_mock = mocker.patch("aiohttp_security.remember")
await helpers.remember()
remember_mock.assert_called_once()
remember_mock.assert_called_once_with()

View File

@ -71,7 +71,7 @@ async def test_get_oauth_username(oauth: OAuth, mocker: MockerFixture) -> None:
email = await oauth.get_oauth_username("code")
access_token_mock.assert_called_once_with("code", redirect_uri=oauth.redirect_uri)
user_info_mock.assert_called_once()
user_info_mock.assert_called_once_with()
assert email == "email"

View File

@ -31,7 +31,7 @@ def test_diff(mocker: MockerFixture) -> None:
local = Path("local")
Sources.diff(local, Path("patch"))
write_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
check_output_mock.assert_called_once_with("git", "diff",
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
@ -157,7 +157,7 @@ def test_patch_apply(mocker: MockerFixture) -> None:
local = Path("local")
Sources.patch_apply(local, Path("patches"))
glob_mock.assert_called_once()
glob_mock.assert_called_once_with("*.patch")
check_output_mock.assert_has_calls([
mock.call("git", "apply", "--ignore-space-change", "--ignore-whitespace", "01.patch",
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),

View File

@ -21,4 +21,4 @@ def test_init_with_cache(task_ahriman: Task, mocker: MockerFixture) -> None:
copytree_mock = mocker.patch("shutil.copytree")
task_ahriman.init(None)
copytree_mock.assert_called_once()
copytree_mock.assert_called_once() # we do not check full command here, sorry

View File

@ -1,3 +1,5 @@
import pytest
from pytest_mock import MockerFixture
from ahriman.core.configuration import Configuration
@ -15,8 +17,8 @@ def test_send(configuration: Configuration, mocker: MockerFixture) -> None:
report._send("a text", {"attachment.html": "an attachment"})
smtp_mock.return_value.starttls.assert_not_called()
smtp_mock.return_value.login.assert_not_called()
smtp_mock.return_value.sendmail.assert_called_once()
smtp_mock.return_value.quit.assert_called_once()
smtp_mock.return_value.sendmail.assert_called_once_with(report.sender, report.receivers, pytest.helpers.anyvar(int))
smtp_mock.return_value.quit.assert_called_once_with()
def test_send_auth(configuration: Configuration, mocker: MockerFixture) -> None:
@ -29,7 +31,7 @@ def test_send_auth(configuration: Configuration, mocker: MockerFixture) -> None:
report = Email("x86_64", configuration, "email")
report._send("a text", {"attachment.html": "an attachment"})
smtp_mock.return_value.login.assert_called_once()
smtp_mock.return_value.login.assert_called_once_with(report.user, report.password)
def test_send_auth_no_password(configuration: Configuration, mocker: MockerFixture) -> None:
@ -67,8 +69,8 @@ def test_send_ssl_tls(configuration: Configuration, mocker: MockerFixture) -> No
report._send("a text", {"attachment.html": "an attachment"})
smtp_mock.return_value.starttls.assert_not_called()
smtp_mock.return_value.login.assert_not_called()
smtp_mock.return_value.sendmail.assert_called_once()
smtp_mock.return_value.quit.assert_called_once()
smtp_mock.return_value.sendmail.assert_called_once_with(report.sender, report.receivers, pytest.helpers.anyvar(int))
smtp_mock.return_value.quit.assert_called_once_with()
def test_send_starttls(configuration: Configuration, mocker: MockerFixture) -> None:
@ -80,7 +82,7 @@ def test_send_starttls(configuration: Configuration, mocker: MockerFixture) -> N
report = Email("x86_64", configuration, "email")
report._send("a text", {"attachment.html": "an attachment"})
smtp_mock.return_value.starttls.assert_called_once()
smtp_mock.return_value.starttls.assert_called_once_with()
def test_generate(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -91,7 +93,7 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
report = Email("x86_64", configuration, "email")
report.generate([package_ahriman], [])
send_mock.assert_called_once()
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
def test_generate_with_built(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -102,7 +104,7 @@ def test_generate_with_built(configuration: Configuration, package_ahriman: Pack
report = Email("x86_64", configuration, "email")
report.generate([package_ahriman], [package_ahriman])
send_mock.assert_called_once()
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
def test_generate_with_built_and_full_path(
@ -117,7 +119,7 @@ def test_generate_with_built_and_full_path(
report = Email("x86_64", configuration, "email")
report.full_template_path = report.template_path
report.generate([package_ahriman], [package_ahriman])
send_mock.assert_called_once()
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
def test_generate_no_empty(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -142,4 +144,4 @@ def test_generate_no_empty_with_built(configuration: Configuration, package_ahri
report = Email("x86_64", configuration, "email")
report.generate([package_ahriman], [package_ahriman])
send_mock.assert_called_once()
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})

View File

@ -1,3 +1,5 @@
import pytest
from pytest_mock import MockerFixture
from ahriman.core.configuration import Configuration
@ -13,4 +15,4 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
report = HTML("x86_64", configuration, "html")
report.generate([package_ahriman], [])
write_mock.assert_called_once()
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))

View File

@ -24,7 +24,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
mocker.patch("ahriman.models.report_settings.ReportSettings.from_option", return_value=ReportSettings.Disabled)
report_mock = mocker.patch("ahriman.core.report.report.Report.generate")
Report.load("x86_64", configuration, "disabled").run([], [])
report_mock.assert_called_once()
report_mock.assert_called_once_with([], [])
def test_report_email(configuration: Configuration, mocker: MockerFixture) -> None:
@ -33,7 +33,7 @@ def test_report_email(configuration: Configuration, mocker: MockerFixture) -> No
"""
report_mock = mocker.patch("ahriman.core.report.email.Email.generate")
Report.load("x86_64", configuration, "email").run([], [])
report_mock.assert_called_once()
report_mock.assert_called_once_with([], [])
def test_report_html(configuration: Configuration, mocker: MockerFixture) -> None:
@ -42,4 +42,4 @@ def test_report_html(configuration: Configuration, mocker: MockerFixture) -> Non
"""
report_mock = mocker.patch("ahriman.core.report.html.HTML.generate")
Report.load("x86_64", configuration, "html").run([], [])
report_mock.assert_called_once()
report_mock.assert_called_once_with([], [])

View File

@ -39,14 +39,14 @@ def test_process_build(executor: Executor, package_ahriman: Package, mocker: Moc
executor.process_build([package_ahriman])
# must move files (once)
move_mock.assert_called_once()
move_mock.assert_called_once_with(Path(package_ahriman.base), executor.paths.packages / package_ahriman.base)
# must update status
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
# must clear directory
from ahriman.core.repository.cleaner import Cleaner
Cleaner.clear_build.assert_called_once()
Cleaner.clear_build.assert_called_once_with()
# must return build packages after all
built_packages_mock.assert_called_once()
built_packages_mock.assert_called_once_with()
def test_process_build_failure(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -60,7 +60,7 @@ def test_process_build_failure(executor: Executor, package_ahriman: Package, moc
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
executor.process_build([package_ahriman])
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_process_remove_base(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -74,10 +74,11 @@ def test_process_remove_base(executor: Executor, package_ahriman: Package, mocke
executor.process_remove([package_ahriman.base])
# must remove via alpm wrapper
repo_remove_mock.assert_called_once()
repo_remove_mock.assert_called_once_with(
package_ahriman.base, package_ahriman.packages[package_ahriman.base].filepath)
# must update status and remove package files
tree_clear_mock.assert_called_once_with(package_ahriman.base)
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_process_remove_base_multiple(executor: Executor, package_python_schedule: Package,
@ -96,7 +97,7 @@ def test_process_remove_base_multiple(executor: Executor, package_python_schedul
for package, props in package_python_schedule.packages.items()
], any_order=True)
# must update status
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_python_schedule.base)
def test_process_remove_base_single(executor: Executor, package_python_schedule: Package,
@ -110,7 +111,8 @@ def test_process_remove_base_single(executor: Executor, package_python_schedule:
executor.process_remove(["python2-schedule"])
# must remove via alpm wrapper
repo_remove_mock.assert_called_once()
repo_remove_mock.assert_called_once_with(
"python2-schedule", package_python_schedule.packages["python2-schedule"].filepath)
# must not update status
status_client_mock.assert_not_called()
@ -154,7 +156,7 @@ def test_process_report(executor: Executor, package_ahriman: Package, mocker: Mo
report_mock = mocker.patch("ahriman.core.report.report.Report.run")
executor.process_report(["dummy"], [])
report_mock.assert_called_once()
report_mock.assert_called_once_with([package_ahriman], [])
def test_process_report_auto(executor: Executor) -> None:
@ -163,18 +165,18 @@ def test_process_report_auto(executor: Executor) -> None:
"""
configuration_mock = executor.configuration = MagicMock()
executor.process_report(None, [])
configuration_mock.getlist.assert_called_once()
configuration_mock.getlist.assert_called_once_with("report", "target")
def test_process_upload(executor: Executor, mocker: MockerFixture) -> None:
"""
must process sync in auto mode if no targets supplied
must process sync
"""
mocker.patch("ahriman.core.upload.upload.Upload.load", return_value=Upload("x86_64", executor.configuration))
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.run")
executor.process_sync(["dummy"], [])
upload_mock.assert_called_once()
upload_mock.assert_called_once_with(executor.paths.repository, [])
def test_process_upload_auto(executor: Executor) -> None:
@ -183,7 +185,7 @@ def test_process_upload_auto(executor: Executor) -> None:
"""
configuration_mock = executor.configuration = MagicMock()
executor.process_sync(None, [])
configuration_mock.getlist.assert_called_once()
configuration_mock.getlist.assert_called_once_with("upload", "target")
def test_process_update(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -197,20 +199,21 @@ def test_process_update(executor: Executor, package_ahriman: Package, mocker: Mo
sign_package_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process_sign_package", side_effect=lambda fn, _: [fn])
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_success")
remove_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_remove")
filepath = next(package.filepath for package in package_ahriman.packages.values())
# must return complete
assert executor.process_update([package.filepath for package in package_ahriman.packages.values()])
assert executor.process_update([filepath])
# must move files (once)
move_mock.assert_called_once()
move_mock.assert_called_once_with(executor.paths.packages / filepath, executor.paths.repository / filepath)
# must sign package
sign_package_mock.assert_called_once()
sign_package_mock.assert_called_once_with(executor.paths.packages / filepath, package_ahriman.base)
# must add package
repo_add_mock.assert_called_once()
repo_add_mock.assert_called_once_with(executor.paths.repository / filepath)
# must update status
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman)
# must clear directory
from ahriman.core.repository.cleaner import Cleaner
Cleaner.clear_packages.assert_called_once()
Cleaner.clear_packages.assert_called_once_with()
# clear removed packages
remove_mock.assert_called_once_with([])
@ -256,7 +259,7 @@ def test_process_update_failed(executor: Executor, package_ahriman: Package, moc
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
executor.process_update([package.filepath for package in package_ahriman.packages.values()])
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_process_update_removed_package(executor: Executor, package_python_schedule: Package,

View File

@ -14,7 +14,7 @@ def test_create_tree_on_load(configuration: Configuration, mocker: MockerFixture
tree_create_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
Properties("x86_64", configuration, True)
tree_create_mock.assert_called_once()
tree_create_mock.assert_called_once_with()
def test_create_tree_on_load_unsafe(configuration: Configuration, mocker: MockerFixture) -> None:
@ -48,4 +48,4 @@ def test_create_full_report_client(configuration: Configuration, mocker: MockerF
load_mock = mocker.patch("ahriman.core.status.client.Client.load")
Properties("x86_64", configuration, False)
load_mock.assert_called_once()
load_mock.assert_called_once_with(configuration)

View File

@ -1,3 +1,5 @@
import pytest
from pathlib import Path
from pytest_mock import MockerFixture
@ -71,7 +73,8 @@ def test_packages(repository: Repository, mocker: MockerFixture) -> None:
"""
load_mock = mocker.patch("ahriman.core.repository.repository.Repository.load_archives")
repository.packages()
load_mock.assert_called_once() # it uses filter object so we cannot verity argument list =/
# it uses filter object, so we cannot verify argument list =/
load_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_packages_built(repository: Repository, mocker: MockerFixture) -> None:

View File

@ -4,6 +4,7 @@ from pytest_mock import MockerFixture
from ahriman.core.repository.update_handler import UpdateHandler
from ahriman.models.package import Package
from ahriman.models.package_source import PackageSource
def test_packages(update_handler: UpdateHandler) -> None:
@ -25,13 +26,13 @@ def test_updates_aur(update_handler: UpdateHandler, package_ahriman: Package,
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_pending")
assert update_handler.updates_aur([], False) == [package_ahriman]
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_updates_aur_success(update_handler: UpdateHandler, package_ahriman: Package,
mocker: MockerFixture) -> None:
"""
must provide updates with status updates
must provide updates with status updates with success
"""
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
mocker.patch("ahriman.models.package.Package.is_outdated", return_value=False)
@ -52,7 +53,7 @@ def test_updates_aur_failed(update_handler: UpdateHandler, package_ahriman: Pack
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
update_handler.updates_aur([], False)
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Package, package_python_schedule: Package,
@ -66,7 +67,8 @@ def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Pack
package_load_mock = mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
assert update_handler.updates_aur([package_ahriman.base], False) == [package_ahriman]
package_load_mock.assert_called_once()
package_load_mock.assert_called_once_with(package_ahriman.base, PackageSource.AUR,
update_handler.pacman, update_handler.aur_url)
def test_updates_aur_ignore(update_handler: UpdateHandler, package_ahriman: Package,
@ -108,8 +110,9 @@ def test_updates_local(update_handler: UpdateHandler, package_ahriman: Package,
assert update_handler.updates_local() == [package_ahriman]
fetch_mock.assert_called_once_with(package_ahriman.base, remote=None)
package_load_mock.assert_called_once()
status_client_mock.assert_called_once()
package_load_mock.assert_called_once_with(
package_ahriman.base, PackageSource.Local, update_handler.pacman, update_handler.aur_url)
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_updates_local_unknown(update_handler: UpdateHandler, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -124,7 +127,7 @@ def test_updates_local_unknown(update_handler: UpdateHandler, package_ahriman: P
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_unknown")
assert update_handler.updates_local() == [package_ahriman]
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman)
def test_updates_local_with_failures(update_handler: UpdateHandler, package_ahriman: Package,
@ -165,7 +168,7 @@ def test_updates_manual_clear(update_handler: UpdateHandler, mocker: MockerFixtu
update_handler.updates_manual()
from ahriman.core.repository.cleaner import Cleaner
Cleaner.clear_manual.assert_called_once()
Cleaner.clear_manual.assert_called_once_with()
def test_updates_manual_status_known(update_handler: UpdateHandler, package_ahriman: Package,
@ -179,7 +182,7 @@ def test_updates_manual_status_known(update_handler: UpdateHandler, package_ahri
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_pending")
update_handler.updates_manual()
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman.base)
def test_updates_manual_status_unknown(update_handler: UpdateHandler, package_ahriman: Package,
@ -193,7 +196,7 @@ def test_updates_manual_status_unknown(update_handler: UpdateHandler, package_ah
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_unknown")
update_handler.updates_manual()
status_client_mock.assert_called_once()
status_client_mock.assert_called_once_with(package_ahriman)
def test_updates_manual_with_failures(update_handler: UpdateHandler, package_ahriman: Package,

View File

@ -70,7 +70,8 @@ def test_key_download(gpg: GPG, mocker: MockerFixture) -> None:
"""
requests_mock = mocker.patch("requests.get")
gpg.key_download("pgp.mit.edu", "0xE989490C")
requests_mock.assert_called_once()
requests_mock.assert_called_once_with(
"http://pgp.mit.edu/pks/lookup", params={"op": "get", "options": "mr", "search": "0xE989490C"})
def test_key_download_failure(gpg: GPG, mocker: MockerFixture) -> None:
@ -116,19 +117,19 @@ def test_process_sign_package_1(gpg_with_key: GPG, mocker: MockerFixture) -> Non
gpg_with_key.targets = {SignSettings.Packages}
assert gpg_with_key.process_sign_package(Path("a"), "a") == result
process_mock.assert_called_once()
process_mock.assert_called_once_with(Path("a"), "key")
def test_process_sign_package_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign package
must sign package if there are multiple targets
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg_with_key.targets = {SignSettings.Packages, SignSettings.Repository}
assert gpg_with_key.process_sign_package(Path("a"), "a") == result
process_mock.assert_called_once()
process_mock.assert_called_once_with(Path("a"), "key")
def test_process_sign_package_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
@ -180,19 +181,19 @@ def test_process_sign_repository_1(gpg_with_key: GPG, mocker: MockerFixture) ->
gpg_with_key.targets = {SignSettings.Repository}
assert gpg_with_key.process_sign_repository(Path("a")) == result
process_mock.assert_called_once()
process_mock.assert_called_once_with(Path("a"), "key")
def test_process_sign_repository_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign repository
must sign repository if there are multiple targets
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg_with_key.targets = {SignSettings.Packages, SignSettings.Repository}
assert gpg_with_key.process_sign_repository(Path("a")) == result
process_mock.assert_called_once()
process_mock.assert_called_once_with(Path("a"), "key")
def test_process_sign_repository_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:

View File

@ -105,7 +105,7 @@ def test_cache_save(watcher: Watcher, package_ahriman: Package, mocker: MockerFi
watcher.known = {package_ahriman.base: (package_ahriman, BuildStatus())}
watcher._cache_save()
json_mock.assert_called_once()
json_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
def test_cache_save_failed(watcher: Watcher, mocker: MockerFixture) -> None:
@ -163,7 +163,7 @@ def test_load(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture)
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_load")
watcher.load()
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
package, status = watcher.known[package_ahriman.base]
assert package == package_ahriman
assert status.status == BuildStatusEnum.Unknown
@ -191,7 +191,7 @@ def test_remove(watcher: Watcher, package_ahriman: Package, mocker: MockerFixtur
watcher.remove(package_ahriman.base)
assert not watcher.known
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
def test_remove_unknown(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -201,7 +201,7 @@ def test_remove_unknown(watcher: Watcher, package_ahriman: Package, mocker: Mock
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_save")
watcher.remove(package_ahriman.base)
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
def test_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -211,7 +211,7 @@ def test_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixtur
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_save")
watcher.update(package_ahriman.base, BuildStatusEnum.Unknown, package_ahriman)
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
package, status = watcher.known[package_ahriman.base]
assert package == package_ahriman
assert status.status == BuildStatusEnum.Unknown
@ -225,7 +225,7 @@ def test_update_ping(watcher: Watcher, package_ahriman: Package, mocker: MockerF
watcher.known = {package_ahriman.base: (package_ahriman, BuildStatus())}
watcher.update(package_ahriman.base, BuildStatusEnum.Success, None)
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
package, status = watcher.known[package_ahriman.base]
assert package == package_ahriman
assert status.status == BuildStatusEnum.Success
@ -239,7 +239,7 @@ def test_update_unknown(watcher: Watcher, package_ahriman: Package, mocker: Mock
with pytest.raises(UnknownPackage):
watcher.update(package_ahriman.base, BuildStatusEnum.Unknown, None)
cache_mock.assert_called_once()
cache_mock.assert_called_once_with()
def test_update_self(watcher: Watcher) -> None:

View File

@ -130,7 +130,7 @@ def test_get_all(web_client: WebClient, package_ahriman: Package, mocker: Mocker
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
result = web_client.get(None)
requests_mock.assert_called_once()
requests_mock.assert_called_once_with(web_client._package_url())
assert len(result) == len(response)
assert (package_ahriman, BuildStatusEnum.Unknown) in [(package, status.status) for package, status in result]
@ -163,7 +163,7 @@ def test_get_single(web_client: WebClient, package_ahriman: Package, mocker: Moc
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
result = web_client.get(package_ahriman.base)
requests_mock.assert_called_once()
requests_mock.assert_called_once_with(web_client._package_url(package_ahriman.base))
assert len(result) == len(response)
assert (package_ahriman, BuildStatusEnum.Unknown) in [(package, status.status) for package, status in result]
@ -179,7 +179,7 @@ def test_get_internal(web_client: WebClient, mocker: MockerFixture) -> None:
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
result = web_client.get_internal()
requests_mock.assert_called_once()
requests_mock.assert_called_once_with(web_client._status_url)
assert result.architecture == "x86_64"
@ -210,7 +210,7 @@ def test_get_self(web_client: WebClient, mocker: MockerFixture) -> None:
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
result = web_client.get_self()
requests_mock.assert_called_once()
requests_mock.assert_called_once_with(web_client._ahriman_url)
assert result.status == BuildStatusEnum.Unknown

View File

@ -22,8 +22,8 @@ def test_from_path(mocker: MockerFixture) -> None:
configuration = Configuration.from_path(path, "x86_64", True)
assert configuration.path == path
read_mock.assert_called_once_with(path)
load_includes_mock.assert_called_once()
load_logging_mock.assert_called_once()
load_includes_mock.assert_called_once_with()
load_logging_mock.assert_called_once_with(True)
def test_dump(configuration: Configuration) -> None:
@ -251,8 +251,8 @@ def test_reload(configuration: Configuration, mocker: MockerFixture) -> None:
merge_mock = mocker.patch("ahriman.core.configuration.Configuration.merge_sections")
configuration.reload()
load_mock.assert_called_once()
merge_mock.assert_called_once()
load_mock.assert_called_once_with(configuration.path)
merge_mock.assert_called_once_with(configuration.architecture)
def test_reload_clear(configuration: Configuration, mocker: MockerFixture) -> None:

View File

@ -70,7 +70,7 @@ def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
start_mock = mocker.patch("multiprocessing.Process.start")
spawner.spawn_process("add", "ahriman", now="", maybe="?")
start_mock.assert_called_once()
start_mock.assert_called_once_with()
spawner.args_parser.parse_args.assert_called_once_with([
"--architecture", spawner.architecture, "--configuration", str(spawner.configuration.path),
"add", "ahriman", "--now", "--maybe", "?"
@ -104,8 +104,8 @@ def test_run_pop(spawner: Spawn) -> None:
spawner.run()
first.terminate.assert_called_once()
first.join.assert_called_once()
second.terminate.assert_called_once()
second.join.assert_called_once()
first.terminate.assert_called_once_with()
first.join.assert_called_once_with()
second.terminate.assert_called_once_with()
second.join.assert_called_once_with()
assert not spawner.active

View File

@ -1,3 +1,5 @@
import pytest
from pytest_mock import MockerFixture
from ahriman.core.tree import Leaf, Tree
@ -47,10 +49,11 @@ def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
leaf = Leaf.load(package_ahriman, repository_paths)
assert leaf.package == package_ahriman
assert leaf.dependencies == {"ahriman-dependency"}
tempdir_mock.assert_called_once()
load_mock.assert_called_once()
dependencies_mock.assert_called_once()
rmtree_mock.assert_called_once()
tempdir_mock.assert_called_once_with()
load_mock.assert_called_once_with(
pytest.helpers.anyvar(int), package_ahriman.git_url, repository_paths.patches_for(package_ahriman.base))
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
rmtree_mock.assert_called_once_with(pytest.helpers.anyvar(int), ignore_errors=True)
def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> None:

View File

@ -21,7 +21,7 @@ def test_check_output(mocker: MockerFixture) -> None:
logger_mock.assert_not_called()
assert check_output("echo", "hello", exception=None, logger=logging.getLogger("")) == "hello"
logger_mock.assert_called_once()
logger_mock.assert_called_once_with("hello")
def test_check_output_failure(mocker: MockerFixture) -> None:
@ -49,7 +49,7 @@ def test_check_output_failure_log(mocker: MockerFixture) -> None:
with pytest.raises(subprocess.CalledProcessError):
check_output("echo", "hello", exception=None, logger=logging.getLogger(""))
logger_mock.assert_called_once()
logger_mock.assert_called_once_with()
def test_check_user(mocker: MockerFixture) -> None:

View File

@ -180,20 +180,20 @@ def test_release_sync(github: Github, mocker: MockerFixture) -> None:
"""
must run sync command
"""
release_get_mock = mocker.patch("ahriman.core.upload.github.Github.release_get")
get_hashes_mock = mocker.patch("ahriman.core.upload.github.Github.get_hashes")
get_local_files_mock = mocker.patch("ahriman.core.upload.github.Github.get_local_files")
release_get_mock = mocker.patch("ahriman.core.upload.github.Github.release_get", return_value={})
get_hashes_mock = mocker.patch("ahriman.core.upload.github.Github.get_hashes", return_value={})
get_local_files_mock = mocker.patch("ahriman.core.upload.github.Github.get_local_files", return_value={})
files_upload_mock = mocker.patch("ahriman.core.upload.github.Github.files_upload")
files_remove_mock = mocker.patch("ahriman.core.upload.github.Github.files_remove")
release_update_mock = mocker.patch("ahriman.core.upload.github.Github.release_update")
github.sync(Path("local"), [])
release_get_mock.assert_called_once()
get_hashes_mock.assert_called_once()
get_local_files_mock.assert_called_once()
files_upload_mock.assert_called_once()
files_remove_mock.assert_called_once()
release_update_mock.assert_called_once()
release_get_mock.assert_called_once_with()
get_hashes_mock.assert_called_once_with("")
get_local_files_mock.assert_called_once_with(Path("local"))
files_upload_mock.assert_called_once_with({}, {}, {})
files_remove_mock.assert_called_once_with({}, {}, {})
release_update_mock.assert_called_once_with({}, pytest.helpers.anyvar(int))
def test_release_sync_create_release(github: Github, mocker: MockerFixture) -> None:
@ -209,4 +209,4 @@ def test_release_sync_create_release(github: Github, mocker: MockerFixture) -> N
release_create_mock = mocker.patch("ahriman.core.upload.github.Github.release_create")
github.sync(Path("local"), [])
release_create_mock.assert_called_once()
release_create_mock.assert_called_once_with()

View File

@ -51,7 +51,7 @@ def test_request(github: Github, mocker: MockerFixture) -> None:
github._request("GET", "url", arg="arg")
request_mock.assert_called_once_with("GET", "url", auth=github.auth, arg="arg")
response_mock.raise_for_status.assert_called_once()
response_mock.raise_for_status.assert_called_once_with()
def test_request_exception(github: Github, mocker: MockerFixture) -> None:

View File

@ -10,4 +10,4 @@ def test_sync(rsync: Rsync, mocker: MockerFixture) -> None:
"""
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
rsync.sync(Path("path"), [])
check_output_mock.assert_called_once()
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, exception=None, logger=rsync.logger)

View File

@ -1,3 +1,5 @@
import pytest
from pathlib import Path
from pytest_mock import MockerFixture
from typing import Any, List, Optional, Tuple
@ -44,7 +46,7 @@ def test_files_remove(s3_remote_objects: List[Any]) -> None:
remote_objects = {Path(item.key): item for item in s3_remote_objects}
S3.files_remove(local_files, remote_objects)
remote_objects[Path("x86_64/a")].delete.assert_called_once()
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:
@ -104,13 +106,13 @@ def test_sync(s3: S3, mocker: MockerFixture) -> None:
"""
must run sync command
"""
local_files_mock = mocker.patch("ahriman.core.upload.s3.S3.get_local_files")
remote_objects_mock = mocker.patch("ahriman.core.upload.s3.S3.get_remote_objects")
local_files_mock = mocker.patch("ahriman.core.upload.s3.S3.get_local_files", return_value=["a"])
remote_objects_mock = mocker.patch("ahriman.core.upload.s3.S3.get_remote_objects", return_value=["b"])
remove_files_mock = mocker.patch("ahriman.core.upload.s3.S3.files_remove")
upload_files_mock = mocker.patch("ahriman.core.upload.s3.S3.files_upload")
s3.sync(Path("root"), [])
local_files_mock.assert_called_once()
remote_objects_mock.assert_called_once()
remove_files_mock.assert_called_once()
upload_files_mock.assert_called_once()
remote_objects_mock.assert_called_once_with()
local_files_mock.assert_called_once_with(Path("root"))
upload_files_mock.assert_called_once_with(Path("root"), ["a"], ["b"])
remove_files_mock.assert_called_once_with(["a"], ["b"])

View File

@ -25,7 +25,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
mocker.patch("ahriman.models.upload_settings.UploadSettings.from_option", return_value=UploadSettings.Disabled)
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.sync")
Upload.load("x86_64", configuration, "disabled").run(Path("path"), [])
upload_mock.assert_called_once()
upload_mock.assert_called_once_with(Path("path"), [])
def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> None:
@ -34,7 +34,7 @@ def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> No
"""
upload_mock = mocker.patch("ahriman.core.upload.rsync.Rsync.sync")
Upload.load("x86_64", configuration, "rsync").run(Path("path"), [])
upload_mock.assert_called_once()
upload_mock.assert_called_once_with(Path("path"), [])
def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
@ -43,7 +43,7 @@ def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
"""
upload_mock = mocker.patch("ahriman.core.upload.s3.S3.sync")
Upload.load("x86_64", configuration, "customs3").run(Path("path"), [])
upload_mock.assert_called_once()
upload_mock.assert_called_once_with(Path("path"), [])
def test_upload_github(configuration: Configuration, mocker: MockerFixture) -> None:
@ -52,4 +52,4 @@ def test_upload_github(configuration: Configuration, mocker: MockerFixture) -> N
"""
upload_mock = mocker.patch("ahriman.core.upload.github.Github.sync")
Upload.load("x86_64", configuration, "github").run(Path("path"), [])
upload_mock.assert_called_once()
upload_mock.assert_called_once_with(Path("path"), [])

View File

@ -172,7 +172,7 @@ def test_load_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, m
"""
load_mock = mocker.patch("ahriman.models.package.Package.from_archive")
Package.load("path", PackageSource.Archive, pyalpm_handle, package_ahriman.aur_url)
load_mock.assert_called_once()
load_mock.assert_called_once_with(Path("path"), pyalpm_handle, package_ahriman.aur_url)
def test_load_from_aur(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
@ -181,7 +181,7 @@ def test_load_from_aur(package_ahriman: Package, pyalpm_handle: MagicMock, mocke
"""
load_mock = mocker.patch("ahriman.models.package.Package.from_aur")
Package.load("path", PackageSource.AUR, pyalpm_handle, package_ahriman.aur_url)
load_mock.assert_called_once()
load_mock.assert_called_once_with("path", package_ahriman.aur_url)
def test_load_from_build(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
@ -190,7 +190,7 @@ def test_load_from_build(package_ahriman: Package, pyalpm_handle: MagicMock, moc
"""
load_mock = mocker.patch("ahriman.models.package.Package.from_build")
Package.load("path", PackageSource.Local, pyalpm_handle, package_ahriman.aur_url)
load_mock.assert_called_once()
load_mock.assert_called_once_with(Path("path"), package_ahriman.aur_url)
def test_load_failure(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:

View File

@ -11,7 +11,7 @@ def test_known_architectures(repository_paths: RepositoryPaths, mocker: MockerFi
"""
iterdir_mock = mocker.patch("pathlib.Path.iterdir")
repository_paths.known_architectures(repository_paths.root)
iterdir_mock.assert_called_once()
iterdir_mock.assert_called_once_with()
def test_cache_for(repository_paths: RepositoryPaths, package_ahriman: Package) -> None:

View File

@ -14,7 +14,7 @@ from ahriman.web.middlewares.auth_handler import auth_handler, AuthorizationPoli
def _identity(username: str) -> str:
"""
generate identity from user
:param user: user fixture object
:param username: name of the user
:return: user identity string
"""
return f"{username} {UserIdentity.expire_when(60)}"
@ -119,7 +119,7 @@ def test_setup_auth(application_with_auth: web.Application, auth: Auth, mocker:
"""
must setup authorization
"""
aiohttp_security_setup_mock = mocker.patch("aiohttp_security.setup")
setup_mock = mocker.patch("aiohttp_security.setup")
application = setup_auth(application_with_auth, auth)
assert application.get("validator") is not None
aiohttp_security_setup_mock.assert_called_once()
setup_mock.assert_called_once_with(application_with_auth, pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))

View File

@ -71,7 +71,7 @@ async def test_exception_handler_server_error(mocker: MockerFixture) -> None:
handler = exception_handler(logging.getLogger())
response = await handler(request, request_handler)
assert _extract_body(response) == {"error": HTTPInternalServerError().reason}
logging_mock.assert_called_once()
logging_mock.assert_called_once() # we do not check logging arguments
async def test_exception_handler_unknown_error(mocker: MockerFixture) -> None:
@ -85,4 +85,4 @@ async def test_exception_handler_unknown_error(mocker: MockerFixture) -> None:
handler = exception_handler(logging.getLogger())
response = await handler(request, request_handler)
assert _extract_body(response) == {"error": "An error"}
logging_mock.assert_called_once()
logging_mock.assert_called_once() # we do not check logging arguments

View File

@ -5,7 +5,16 @@ from pytest_mock import MockerFixture
from ahriman.core.exceptions import InitializeException
from ahriman.core.status.watcher import Watcher
from ahriman.web.web import on_startup, run_server
from ahriman.web.web import on_shutdown, on_startup, run_server
async def test_on_shutdown(application: web.Application, mocker: MockerFixture) -> None:
"""
must write information to log
"""
logging_mock = mocker.patch("logging.Logger.warning")
await on_shutdown(application)
logging_mock.assert_called_once_with(pytest.helpers.anyvar(str, True))
async def test_on_startup(application: web.Application, watcher: Watcher, mocker: MockerFixture) -> None:
@ -16,7 +25,7 @@ async def test_on_startup(application: web.Application, watcher: Watcher, mocker
load_mock = mocker.patch("ahriman.core.status.watcher.Watcher.load")
await on_startup(application)
load_mock.assert_called_once()
load_mock.assert_called_once_with()
async def test_on_startup_exception(application: web.Application, watcher: Watcher, mocker: MockerFixture) -> None:

View File

@ -26,7 +26,7 @@ async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None
response = await client_with_auth.post("/service-api/v1/reload-auth")
assert response.ok
reload_mock.assert_called_once()
reload_mock.assert_called_once_with()
load_mock.assert_called_once_with(client_with_auth.app["configuration"])
@ -38,4 +38,4 @@ async def test_post_no_auth(client: TestClient, mocker: MockerFixture) -> None:
response = await client.post("/service-api/v1/reload-auth")
assert response.status == 500
reload_mock.assert_called_once()
reload_mock.assert_called_once_with()

View File

@ -45,4 +45,4 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
load_mock = mocker.patch("ahriman.core.status.watcher.Watcher.load")
response = await client.post("/status-api/v1/packages")
assert response.status == 204
load_mock.assert_called_once()
load_mock.assert_called_once_with()

View File

@ -36,7 +36,7 @@ async def test_get_redirect_to_oauth(client_with_auth: TestClient) -> None:
get_response = await client_with_auth.get("/user-api/v1/login")
assert get_response.ok
oauth.get_oauth_url.assert_called_once()
oauth.get_oauth_url.assert_called_once_with()
async def test_get_redirect_to_oauth_empty_code(client_with_auth: TestClient) -> None:
@ -48,7 +48,7 @@ async def test_get_redirect_to_oauth_empty_code(client_with_auth: TestClient) ->
get_response = await client_with_auth.get("/user-api/v1/login", params={"code": ""})
assert get_response.ok
oauth.get_oauth_url.assert_called_once()
oauth.get_oauth_url.assert_called_once_with()
async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
@ -58,7 +58,7 @@ async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
oauth = client_with_auth.app["validator"] = MagicMock(spec=OAuth)
oauth.get_oauth_username.return_value = "user"
oauth.known_username.return_value = True
oauth.enabled = False # lol\
oauth.enabled = False # lol
oauth.max_age = 60
remember_mock = mocker.patch("aiohttp_security.remember")
@ -67,7 +67,8 @@ async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
assert get_response.ok
oauth.get_oauth_username.assert_called_once_with("code")
oauth.known_username.assert_called_once_with("user")
remember_mock.assert_called_once()
remember_mock.assert_called_once_with(
pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
async def test_get_unauthorized(client_with_auth: TestClient, mocker: MockerFixture) -> None:

View File

@ -26,7 +26,7 @@ async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None
post_response = await client_with_auth.post("/user-api/v1/logout")
assert post_response.ok
forget_mock.assert_called_once()
forget_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
async def test_post_unauthorized(client_with_auth: TestClient, mocker: MockerFixture) -> None: