do not use set_defaults for architecture arguments

according to the source code defaults always updates the values
dictionary. This in this specific case it is impossible to override the
value it will be always empty list.

In order to handle it we are adding another property to the Handler
class which allows to run with None architecture list.

This particular set_defaults behaviour is still useful for other cases
when we have to run command without any specific architecture
This commit is contained in:
2021-10-03 00:59:24 +03:00
parent 444da87fdc
commit 1192f12f91
23 changed files with 190 additions and 54 deletions
@@ -71,7 +71,6 @@ def test_extract_architectures(args: argparse.Namespace, configuration: Configur
"""
must generate list of available architectures
"""
args.architecture = []
args.configuration = configuration.path
known_architectures_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures")
@@ -84,7 +83,6 @@ def test_extract_architectures_empty(args: argparse.Namespace, configuration: Co
"""
must raise exception if no available architectures found
"""
args.architecture = []
args.command = "config"
args.configuration = configuration.path
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures", return_value=set())
@@ -93,12 +91,12 @@ def test_extract_architectures_empty(args: argparse.Namespace, configuration: Co
Handler.extract_architectures(args)
def test_extract_architectures_exception(args: argparse.Namespace) -> None:
def test_extract_architectures_exception(args: argparse.Namespace, mocker: MockerFixture) -> None:
"""
must raise exception on missing architectures
"""
args.command = "config"
args.architecture = None
mocker.patch.object(Handler, "ALLOW_AUTO_ARCHITECTURE_RUN", False)
with pytest.raises(MissingArchitecture):
Handler.extract_architectures(args)
@@ -18,3 +18,10 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
Dump.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
print_mock.assert_called()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Dump.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -16,3 +16,10 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
Init.run(args, "x86_64", configuration, True)
create_tree_mock.assert_called_once()
init_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Init.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -27,3 +27,10 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
KeyImport.run(args, "x86_64", configuration, True)
application_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not KeyImport.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -53,3 +53,10 @@ def test_log_fn(args: argparse.Namespace, configuration: Configuration, aur_pack
Search.run(args, "x86_64", configuration, True)
print_mock.assert_called() # we don't really care about call details tbh
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Search.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -149,3 +149,10 @@ def test_create_executable(args: argparse.Namespace, mocker: MockerFixture) -> N
Setup.create_executable(args.build_command, "x86_64")
symlink_text_mock.assert_called_once()
unlink_text_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Setup.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -81,3 +81,10 @@ def test_imply_with_report(args: argparse.Namespace, configuration: Configuratio
Status.run(args, "x86_64", configuration, True)
load_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Status.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -86,3 +86,10 @@ def test_imply_with_report(args: argparse.Namespace, configuration: Configuratio
StatusUpdate.run(args, "x86_64", configuration, True)
load_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not StatusUpdate.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -257,3 +257,10 @@ def test_write_configuration_not_loaded(configuration: Configuration, mocker: Mo
User.write_configuration(configuration, secure=True)
write_mock.assert_not_called()
chmod_mock.assert_not_called()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not User.ALLOW_AUTO_ARCHITECTURE_RUN
@@ -31,6 +31,13 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
run_mock.assert_called_once()
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Web.ALLOW_AUTO_ARCHITECTURE_RUN
def test_disallow_multi_architecture_run() -> None:
"""
must not allow multi architecture run