mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
Local packages support improvements (#104)
* handle git author correctly * make remote source required argument
This commit is contained in:
@ -86,7 +86,9 @@ def test_add_local(application_packages: ApplicationPackages, package_ahriman: P
|
||||
application_packages._add_local(package_ahriman.base, "packager")
|
||||
is_dir_mock.assert_called_once_with()
|
||||
copytree_mock.assert_called_once_with(
|
||||
Path(package_ahriman.base), application_packages.repository.paths.cache_for(package_ahriman.base))
|
||||
Path(package_ahriman.base),
|
||||
application_packages.repository.paths.cache_for(package_ahriman.base),
|
||||
dirs_exist_ok=True)
|
||||
init_mock.assert_called_once_with(application_packages.repository.paths.cache_for(package_ahriman.base))
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
|
||||
|
@ -7,6 +7,7 @@ from typing import Any, TypeVar
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.alpm.remote import AUR
|
||||
from ahriman.core.auth import Auth
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
@ -314,7 +315,13 @@ def package_python_schedule(
|
||||
return Package(
|
||||
base="python-schedule",
|
||||
version="1.0.0-2",
|
||||
remote=RemoteSource.from_source(PackageSource.AUR, "python-schedule", "aur"),
|
||||
remote=RemoteSource(
|
||||
source=PackageSource.AUR,
|
||||
git_url=AUR.remote_git_url("python-schedule", "aur"),
|
||||
web_url=AUR.remote_web_url("python-schedule"),
|
||||
path=".",
|
||||
branch="master",
|
||||
),
|
||||
packages=packages)
|
||||
|
||||
|
||||
@ -451,7 +458,13 @@ def remote_source() -> RemoteSource:
|
||||
Returns:
|
||||
RemoteSource: remote source test instance
|
||||
"""
|
||||
return RemoteSource.from_source(PackageSource.AUR, "ahriman", "aur")
|
||||
return RemoteSource(
|
||||
source=PackageSource.AUR,
|
||||
git_url=AUR.remote_git_url("ahriman", "aur"),
|
||||
web_url=AUR.remote_web_url("ahriman"),
|
||||
path=".",
|
||||
branch="master",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -8,6 +8,7 @@ from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@ -23,7 +24,7 @@ def test_init_with_local_cache(configuration: Configuration, mocker: MockerFixtu
|
||||
with TemporaryDirectory(ignore_cleanup_errors=True) as pacman_root:
|
||||
mocker.patch.object(RepositoryPaths, "pacman", Path(pacman_root))
|
||||
# during the creation pyalpm.Handle will create also version file which we would like to remove later
|
||||
pacman = Pacman("x86_64", configuration, refresh_database=1)
|
||||
pacman = Pacman("x86_64", configuration, refresh_database=PacmanSynchronization.Enabled)
|
||||
assert pacman.handle
|
||||
sync_mock.assert_called_once_with(pytest.helpers.anyvar(int), force=False)
|
||||
|
||||
@ -40,7 +41,7 @@ def test_init_with_local_cache_forced(configuration: Configuration, mocker: Mock
|
||||
with TemporaryDirectory(ignore_cleanup_errors=True) as pacman_root:
|
||||
mocker.patch.object(RepositoryPaths, "pacman", Path(pacman_root))
|
||||
# during the creation pyalpm.Handle will create also version file which we would like to remove later
|
||||
pacman = Pacman("x86_64", configuration, refresh_database=2)
|
||||
pacman = Pacman("x86_64", configuration, refresh_database=PacmanSynchronization.Force)
|
||||
assert pacman.handle
|
||||
sync_mock.assert_called_once_with(pytest.helpers.anyvar(int), force=True)
|
||||
|
||||
@ -54,7 +55,7 @@ def test_database_copy(pacman: Pacman, repository_paths: RepositoryPaths, mocker
|
||||
dst_path = Path("/var/lib/pacman/sync/core.db")
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
# root database exists, local database does not
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: True if p.is_relative_to(path) else False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: p.is_relative_to(path))
|
||||
copy_mock = mocker.patch("shutil.copy")
|
||||
chown_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.chown")
|
||||
|
||||
@ -71,7 +72,7 @@ def test_database_copy_skip(pacman: Pacman, repository_paths: RepositoryPaths, m
|
||||
path = Path("randomname")
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
# root database exists, local database does not
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: True if p.is_relative_to(path) else False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: p.is_relative_to(path))
|
||||
copy_mock = mocker.patch("shutil.copy")
|
||||
|
||||
pacman.database_copy(pacman.handle, database, path, repository_paths, use_ahriman_cache=False)
|
||||
@ -86,7 +87,7 @@ def test_database_copy_no_directory(pacman: Pacman, repository_paths: Repository
|
||||
path = Path("randomname")
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
# root database exists, local database does not
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: True if p.is_relative_to(path) else False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: p.is_relative_to(path))
|
||||
copy_mock = mocker.patch("shutil.copy")
|
||||
|
||||
pacman.database_copy(pacman.handle, database, path, repository_paths, use_ahriman_cache=True)
|
||||
|
@ -6,6 +6,7 @@ from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
@ -92,7 +93,7 @@ def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, None)
|
||||
Sources.fetch(local, RemoteSource(source=PackageSource.Archive))
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "checkout", "--force", Sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--hard", f"origin/{Sources.DEFAULT_BRANCH}",
|
||||
@ -136,6 +137,7 @@ def test_init(mocker: MockerFixture) -> None:
|
||||
must create empty repository at the specified path
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.local_files", return_value=[Path("local")])
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
|
||||
@ -145,7 +147,21 @@ def test_init(mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_called_once_with("git", "init", "--initial-branch", Sources.DEFAULT_BRANCH,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
add_mock.assert_called_once_with(local, "PKGBUILD", ".SRCINFO", "local")
|
||||
commit_mock.assert_called_once_with(local, author="ahriman <ahriman@localhost>")
|
||||
commit_mock.assert_called_once_with(local)
|
||||
|
||||
|
||||
def test_init_skip(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip git init if it was already
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.local_files", return_value=[Path("local")])
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
Sources.init(Path("local"))
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_load(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
@ -216,19 +232,31 @@ def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
must correctly push files to remote repository
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
|
||||
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
author = "commit author <user@host>"
|
||||
commit_author = ("commit author", "user@host")
|
||||
local = Path("local")
|
||||
Sources.push(Path("local"), package_ahriman.remote, "glob", commit_author=author)
|
||||
Sources.push(local, package_ahriman.remote, "glob", commit_author=commit_author)
|
||||
add_mock.assert_called_once_with(local, "glob")
|
||||
commit_mock.assert_called_once_with(local, author=author)
|
||||
commit_mock.assert_called_once_with(local, commit_author=commit_author)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "push", package_ahriman.remote.git_url, package_ahriman.remote.branch,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_push_skipped(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip push if no changes were committed
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.commit", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
Sources.push(Path("local"), package_ahriman.remote)
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must add files to git
|
||||
@ -274,29 +302,54 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must commit changes
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
message = "Commit message"
|
||||
sources.commit(local, message=message)
|
||||
user, email = sources.DEFAULT_COMMIT_AUTHOR
|
||||
assert sources.commit(local, message=message)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--allow-empty", "--message", message, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
"git", "commit", "--message", message,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int), environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_commit_no_changes(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip commit if there are no changes
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
assert not sources.commit(Path("local"))
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_commit_author(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must commit changes with commit author
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
message = "Commit message"
|
||||
author = "commit author <user@host>"
|
||||
sources.commit(Path("local"), message=message, author=author)
|
||||
user, email = author = ("commit author", "user@host")
|
||||
assert sources.commit(Path("local"), message=message, commit_author=author)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--allow-empty", "--message", message, "--author", author,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
"git", "commit", "--message", message,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int), environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -304,13 +357,20 @@ def test_commit_autogenerated_message(sources: Sources, mocker: MockerFixture) -
|
||||
"""
|
||||
must commit changes with autogenerated commit message
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
sources.commit(Path("local"))
|
||||
assert sources.commit(Path("local"))
|
||||
user, email = sources.DEFAULT_COMMIT_AUTHOR
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--allow-empty", "--message", pytest.helpers.anyvar(str, strict=True),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
"git", "commit", "--message", pytest.helpers.anyvar(str, strict=True),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int), environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -325,6 +385,23 @@ def test_diff(sources: Sources, mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_called_once_with("git", "diff", cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_has_changes(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly identify if there are changes
|
||||
"""
|
||||
local = Path("local")
|
||||
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="M a.txt")
|
||||
assert sources.has_changes(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="")
|
||||
assert not sources.has_changes(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_move(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must move content between directories
|
||||
|
@ -66,18 +66,3 @@ def test_migrate_package_remotes_vcs(package_ahriman: Package, connection: Conne
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_no_remotes(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing in case if no remotes generated (should never happen)
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch("ahriman.models.remote_source.RemoteSource.from_source", return_value=None)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
@ -35,7 +35,7 @@ def test_migrate_package_depends(connection: Connection, configuration: Configur
|
||||
|
||||
migrate_package_depends(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"make_depends": package_ahriman.packages[package_ahriman.base].make_depends,
|
||||
"opt_depends": package_ahriman.packages[package_ahriman.base].opt_depends,
|
||||
|
@ -35,7 +35,7 @@ def test_migrate_package_depends(connection: Connection, configuration: Configur
|
||||
|
||||
migrate_package_check_depends(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"check_depends": package_ahriman.packages[package_ahriman.base].check_depends,
|
||||
"package": package_ahriman.base,
|
||||
|
@ -35,7 +35,7 @@ def test_migrate_package_base_packager(connection: Connection, configuration: Co
|
||||
|
||||
migrate_package_base_packager(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"package_base": package_ahriman.base,
|
||||
"packager": package_ahriman.packager,
|
||||
|
@ -0,0 +1,8 @@
|
||||
from ahriman.core.database.migrations.m009_local_source import steps
|
||||
|
||||
|
||||
def test_migration_packagers() -> None:
|
||||
"""
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
@ -193,7 +193,7 @@ def test_remote_update_update(database: SQLite, package_ahriman: Package) -> Non
|
||||
must perform package remote update for existing package
|
||||
"""
|
||||
database.remote_update(package_ahriman)
|
||||
remote_source = RemoteSource.from_source(PackageSource.Repository, package_ahriman.base, "community")
|
||||
remote_source = RemoteSource(source=PackageSource.Repository)
|
||||
package_ahriman.remote = remote_source
|
||||
|
||||
database.remote_update(package_ahriman)
|
||||
|
@ -11,6 +11,8 @@ from ahriman.core.repository import Repository
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
from ahriman.models.context_key import ContextKey
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
|
||||
|
||||
def test_load(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> None:
|
||||
@ -51,6 +53,9 @@ def test_load_archives(package_ahriman: Package, package_python_schedule: Packag
|
||||
for package, props in package_python_schedule.packages.items()
|
||||
] + [package_ahriman]
|
||||
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=single_packages)
|
||||
mocker.patch("ahriman.core.database.SQLite.remotes_get", return_value={
|
||||
package_ahriman.base: package_ahriman.base
|
||||
})
|
||||
|
||||
packages = repository.load_archives([Path("a.pkg.tar.xz"), Path("b.pkg.tar.xz"), Path("c.pkg.tar.xz")])
|
||||
assert len(packages) == 2
|
||||
|
@ -42,7 +42,7 @@ def test_updates_aur_official(update_handler: UpdateHandler, package_ahriman: Pa
|
||||
"""
|
||||
must provide updates based on repository data
|
||||
"""
|
||||
package_ahriman.remote = RemoteSource.from_source(PackageSource.Repository, package_ahriman.base, "community")
|
||||
package_ahriman.remote = RemoteSource(source=PackageSource.Repository)
|
||||
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.models.package.Package.is_outdated", return_value=True)
|
||||
mocker.patch("ahriman.models.package.Package.from_official", return_value=package_ahriman)
|
||||
@ -65,6 +65,19 @@ def test_updates_aur_failed(update_handler: UpdateHandler, package_ahriman: Pack
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_updates_aur_local(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages with local sources
|
||||
"""
|
||||
package_ahriman.remote = RemoteSource(source=PackageSource.Local)
|
||||
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
|
||||
package_load_mock = mocker.patch("ahriman.models.package.Package.from_aur")
|
||||
|
||||
assert not update_handler.updates_aur([], vcs=True)
|
||||
package_load_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Package, package_python_schedule: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
@ -150,7 +163,7 @@ def test_updates_local(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
package_is_outdated_mock = mocker.patch("ahriman.models.package.Package.is_outdated", return_value=True)
|
||||
|
||||
assert update_handler.updates_local(vcs=True) == [package_ahriman]
|
||||
fetch_mock.assert_called_once_with(Path(package_ahriman.base), remote=None)
|
||||
fetch_mock.assert_called_once_with(Path(package_ahriman.base), pytest.helpers.anyvar(int))
|
||||
package_load_mock.assert_called_once_with(Path(package_ahriman.base), "x86_64", None)
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
package_is_outdated_mock.assert_called_once_with(
|
||||
|
@ -75,7 +75,7 @@ def test_packages_add(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username=None)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username=None)
|
||||
|
||||
|
||||
def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -84,7 +84,7 @@ def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=True)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username=None, now="")
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username=None, now="")
|
||||
|
||||
|
||||
def test_packages_add_with_username(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -93,7 +93,7 @@ def test_packages_add_with_username(spawner: Spawn, mocker: MockerFixture) -> No
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], "username", now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username="username")
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", username="username")
|
||||
|
||||
|
||||
def test_packages_rebuild(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
|
@ -4,6 +4,7 @@ import pytest
|
||||
from unittest.mock import MagicMock, PropertyMock
|
||||
|
||||
from ahriman import __version__
|
||||
from ahriman.core.alpm.remote import AUR
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.counters import Counters
|
||||
@ -70,7 +71,13 @@ def package_tpacpi_bat_git() -> Package:
|
||||
return Package(
|
||||
base="tpacpi-bat-git",
|
||||
version="3.1.r12.g4959b52-1",
|
||||
remote=RemoteSource.from_source(PackageSource.AUR, "tpacpi-bat-git", "aur"),
|
||||
remote=RemoteSource(
|
||||
source=PackageSource.AUR,
|
||||
git_url=AUR.remote_git_url("tpacpi-bat-git", "aur"),
|
||||
web_url=AUR.remote_web_url("tpacpi-bat-git"),
|
||||
path=".",
|
||||
branch="master",
|
||||
),
|
||||
packages={"tpacpi-bat-git": PackageDescription()})
|
||||
|
||||
|
||||
|
@ -158,7 +158,10 @@ def test_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, mocker
|
||||
"""
|
||||
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
||||
return_value=package_ahriman.packages[package_ahriman.base])
|
||||
assert Package.from_archive(Path("path"), pyalpm_handle, package_ahriman.remote) == package_ahriman
|
||||
generated = Package.from_archive(Path("path"), pyalpm_handle)
|
||||
generated.remote = package_ahriman.remote
|
||||
|
||||
assert generated == package_ahriman
|
||||
|
||||
|
||||
def test_from_aur(package_ahriman: Package, aur_package_ahriman: AURPackage, pacman: Pacman,
|
||||
|
@ -4,6 +4,7 @@ from pathlib import Path
|
||||
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def _is_file_mock(is_any_file: bool, is_pkgbuild: bool) -> Callable[[Path], bool]:
|
||||
@ -21,71 +22,86 @@ def _is_file_mock(is_any_file: bool, is_pkgbuild: bool) -> Callable[[Path], bool
|
||||
return side_effect
|
||||
|
||||
|
||||
def test_resolve_non_auto() -> None:
|
||||
def test_resolve_non_auto(repository_paths: RepositoryPaths) -> None:
|
||||
"""
|
||||
must resolve non auto type to itself
|
||||
"""
|
||||
for source in filter(lambda src: src != PackageSource.Auto, PackageSource):
|
||||
assert source.resolve("") == source
|
||||
assert source.resolve("", repository_paths) == source
|
||||
|
||||
|
||||
def test_resolve_archive(package_description_ahriman: PackageDescription, mocker: MockerFixture) -> None:
|
||||
def test_resolve_archive(package_description_ahriman: PackageDescription, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the archive
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, False))
|
||||
assert PackageSource.Auto.resolve(package_description_ahriman.filename) == PackageSource.Archive
|
||||
assert PackageSource.Auto.resolve(package_description_ahriman.filename, repository_paths) == PackageSource.Archive
|
||||
|
||||
|
||||
def test_resolve_aur(mocker: MockerFixture) -> None:
|
||||
def test_resolve_aur(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the AUR package
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
assert PackageSource.Auto.resolve("package", repository_paths) == PackageSource.AUR
|
||||
|
||||
|
||||
def test_resolve_aur_not_package_like(mocker: MockerFixture) -> None:
|
||||
def test_resolve_aur_not_package_like(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the AUR package if it is file, but does not look like a package archive
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, False))
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
assert PackageSource.Auto.resolve("package", repository_paths) == PackageSource.AUR
|
||||
|
||||
|
||||
def test_resolve_aur_no_access(mocker: MockerFixture) -> None:
|
||||
def test_resolve_aur_no_access(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the AUR package in case if we cannot read in suggested path
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", side_effect=PermissionError())
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
assert PackageSource.Auto.resolve("package", repository_paths) == PackageSource.AUR
|
||||
|
||||
|
||||
def test_resolve_directory(mocker: MockerFixture) -> None:
|
||||
def test_resolve_directory(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the directory
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p == Path("path"))
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(False, False))
|
||||
assert PackageSource.Auto.resolve("path") == PackageSource.Directory
|
||||
assert PackageSource.Auto.resolve("path", repository_paths) == PackageSource.Directory
|
||||
|
||||
|
||||
def test_resolve_local(mocker: MockerFixture) -> None:
|
||||
def test_resolve_local(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the local sources
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, True))
|
||||
assert PackageSource.Auto.resolve("path") == PackageSource.Local
|
||||
assert PackageSource.Auto.resolve("path", repository_paths) == PackageSource.Local
|
||||
|
||||
|
||||
def test_resolve_remote(package_description_ahriman: PackageDescription, mocker: MockerFixture) -> None:
|
||||
def test_resolve_local_cache(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the local sources
|
||||
"""
|
||||
cache_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.cache_for", return_value=Path("cache"))
|
||||
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p == Path("cache"))
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(False, False))
|
||||
|
||||
assert PackageSource.Auto.resolve("path", repository_paths) == PackageSource.Local
|
||||
cache_mock.assert_called_once_with("path")
|
||||
|
||||
|
||||
def test_resolve_remote(package_description_ahriman: PackageDescription, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the remote sources
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(False, False))
|
||||
assert PackageSource.Auto.resolve(f"https://host/{package_description_ahriman.filename}") == PackageSource.Remote
|
||||
url = f"https://host/{package_description_ahriman.filename}"
|
||||
assert PackageSource.Auto.resolve(url, repository_paths) == PackageSource.Remote
|
||||
|
@ -1,7 +1,8 @@
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
import pytest
|
||||
|
||||
from ahriman.models.package import Package
|
||||
from pathlib import Path
|
||||
|
||||
from ahriman.core.exceptions import InitializeError
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
|
||||
@ -20,6 +21,14 @@ def test_post_init(remote_source: RemoteSource) -> None:
|
||||
assert remote == remote_source
|
||||
|
||||
|
||||
def test_is_remote() -> None:
|
||||
"""
|
||||
must correctly define if source is remote or not
|
||||
"""
|
||||
for source in PackageSource:
|
||||
assert RemoteSource(source=source).is_remote or source not in (PackageSource.AUR, PackageSource.Repository)
|
||||
|
||||
|
||||
def test_pkgbuild_dir(remote_source: RemoteSource) -> None:
|
||||
"""
|
||||
must return path as is in `path` property
|
||||
@ -35,48 +44,16 @@ def test_from_json(remote_source: RemoteSource) -> None:
|
||||
assert RemoteSource.from_json(remote_source.view()) == remote_source
|
||||
|
||||
|
||||
def test_from_json_empty() -> None:
|
||||
def test_git_source(remote_source: RemoteSource) -> None:
|
||||
"""
|
||||
must return None in case of empty dictionary, which is required by the database wrapper
|
||||
must correctly return git source
|
||||
"""
|
||||
assert RemoteSource.from_json({}) is None
|
||||
assert remote_source.git_source() == (remote_source.git_url, remote_source.branch)
|
||||
|
||||
|
||||
def test_from_source_aur(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
def test_git_source_empty() -> None:
|
||||
"""
|
||||
must construct remote from AUR source
|
||||
must raise exception if path is none
|
||||
"""
|
||||
remote_git_url_mock = mocker.patch("ahriman.core.alpm.remote.AUR.remote_git_url")
|
||||
remote_web_url_mock = mocker.patch("ahriman.core.alpm.remote.AUR.remote_web_url")
|
||||
|
||||
remote = RemoteSource.from_source(PackageSource.AUR, package_ahriman.base, "aur")
|
||||
remote_git_url_mock.assert_called_once_with(package_ahriman.base, "aur")
|
||||
remote_web_url_mock.assert_called_once_with(package_ahriman.base)
|
||||
assert remote.pkgbuild_dir == Path(".")
|
||||
assert remote.branch == "master"
|
||||
assert remote.source == PackageSource.AUR
|
||||
|
||||
|
||||
def test_from_source_official(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct remote from official repository source
|
||||
"""
|
||||
remote_git_url_mock = mocker.patch("ahriman.core.alpm.remote.Official.remote_git_url")
|
||||
remote_web_url_mock = mocker.patch("ahriman.core.alpm.remote.Official.remote_web_url")
|
||||
|
||||
remote = RemoteSource.from_source(PackageSource.Repository, package_ahriman.base, "community")
|
||||
remote_git_url_mock.assert_called_once_with(package_ahriman.base, "community")
|
||||
remote_web_url_mock.assert_called_once_with(package_ahriman.base)
|
||||
assert remote.pkgbuild_dir == Path(".")
|
||||
assert remote.branch == "main"
|
||||
assert remote.source == PackageSource.Repository
|
||||
|
||||
|
||||
def test_from_source_other() -> None:
|
||||
"""
|
||||
must return None in case if source is not one of AUR or Repository
|
||||
"""
|
||||
assert RemoteSource.from_source(PackageSource.Archive, "package", "repository") is None
|
||||
assert RemoteSource.from_source(PackageSource.Directory, "package", "repository") is None
|
||||
assert RemoteSource.from_source(PackageSource.Local, "package", "repository") is None
|
||||
assert RemoteSource.from_source(PackageSource.Remote, "package", "repository") is None
|
||||
with pytest.raises(InitializeError):
|
||||
RemoteSource(source=PackageSource.Remote).git_source()
|
||||
|
@ -48,7 +48,8 @@ target = gitremote
|
||||
target = gitremote
|
||||
|
||||
[gitremote]
|
||||
commit_author = "user <user@host>"
|
||||
commit_user = user
|
||||
commit_email = user@host
|
||||
push_url = https://github.com/arcan1s/repository.git
|
||||
pull_url = https://github.com/arcan1s/repository.git
|
||||
|
||||
|
Reference in New Issue
Block a user