mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
Functions needed to spot and remove installed conflicting packages before installation of apps. - Remove all packages in a single operation as this way apt can search for solutions to conflicts more easily. - Use type hints rather than a lot of type checking. Type hints shall later be enforced using offline checking (with mypy) or at runtime (with enforce, etc.). Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com> [sunil: Run single remove operation on all packages] [sunil: Use type hints instead of extensive type checking] [sunil: Trim down the test case as it would only succeed after install] Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org> package
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Test module for package module.
|
|
"""
|
|
|
|
from unittest.mock import call, patch
|
|
|
|
from plinth.errors import ActionError
|
|
from plinth.package import packages_installed, remove
|
|
|
|
|
|
def test_packages_installed():
|
|
"""Test packages_installed()."""
|
|
# list as input
|
|
assert len(packages_installed([])) == 0
|
|
assert len(packages_installed(['unknown-package'])) == 0
|
|
assert len(packages_installed(['python3'])) == 1
|
|
# tuples as input
|
|
assert len(packages_installed(())) == 0
|
|
assert len(packages_installed(('unknown-package', ))) == 0
|
|
assert len(packages_installed(('python3', ))) == 1
|
|
|
|
|
|
@patch('plinth.actions.superuser_run')
|
|
def test_remove(run):
|
|
"""Test removing packages."""
|
|
remove(['package1', 'package2'])
|
|
run.assert_has_calls(
|
|
[call('packages', ['remove', '--packages', 'package1', 'package2'])])
|
|
|
|
run.reset_mock()
|
|
run.side_effect = ActionError()
|
|
remove(['package1'])
|
|
run.assert_has_calls(
|
|
[call('packages', ['remove', '--packages', 'package1'])])
|