parent
151916a7f7
commit
0d2e282093
|
|
@ -1,6 +1,6 @@
|
|||
import inspect
|
||||
from functools import wraps
|
||||
from typing import override
|
||||
from collections.abc import Callable
|
||||
from typing import Any, override
|
||||
|
||||
from archinstall.default_profiles.profile import GreeterType
|
||||
from archinstall.lib.applications.application_menu import ApplicationMenu
|
||||
|
|
@ -80,6 +80,7 @@ class GlobalMenu(AbstractMenu[None]):
|
|||
return '[bold green][✓][/bold green] '
|
||||
return '[bold red][!][/bold red] '
|
||||
|
||||
# Standard mandatory or configured item check
|
||||
if item.has_value():
|
||||
return '[bold green][✓][/bold green] '
|
||||
elif item.mandatory:
|
||||
|
|
@ -100,24 +101,22 @@ class GlobalMenu(AbstractMenu[None]):
|
|||
prefix = self._get_status_prefix(item)
|
||||
item.text = f'{prefix}{base_title}'
|
||||
|
||||
def _wrap_action(item_dictionary, update_callback, key, action):
|
||||
@wraps(action)
|
||||
async def wrapper(*args, **kwargs):
|
||||
try:
|
||||
if inspect.iscoroutinefunction(action):
|
||||
result = await action(*args, **kwargs)
|
||||
else:
|
||||
result = action(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
def _wrap_action(self, key: str, action: Callable[..., Any]) -> Callable[..., Any]:
|
||||
async def wrapper(*args, **kwargs) -> Any:
|
||||
if inspect.iscoroutinefunction(action):
|
||||
result = await action(*args, **kwargs)
|
||||
else:
|
||||
result = action(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
|
||||
if key in item_dictionary:
|
||||
item_dictionary[key].value = result
|
||||
item = self._item_group.find_by_key(key)
|
||||
if item:
|
||||
item.value = result
|
||||
|
||||
return result
|
||||
self._update_item_labels()
|
||||
|
||||
finally:
|
||||
update_callback()
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from pytest import MonkeyPatch
|
||||
|
||||
from archinstall.lib.args import USER_CONFIG_FILE, USER_CREDS_FILE, ArchConfigHandler
|
||||
|
||||
|
||||
def test_user_config_roundtrip(
|
||||
monkeypatch: MonkeyPatch,
|
||||
config_fixture: Path,
|
||||
) -> None:
|
||||
monkeypatch.setattr('sys.argv', ['archinstall', '--config', str(config_fixture)])
|
||||
|
||||
handler = ArchConfigHandler()
|
||||
arch_config = handler.config
|
||||
|
||||
# the version is retrieved dynamically from an installed archinstall package
|
||||
# as there is no version present in the test environment we'll set it manually
|
||||
arch_config.version = '3.0.2'
|
||||
|
||||
test_out_dir = Path('/tmp/')
|
||||
test_out_file = test_out_dir / USER_CONFIG_FILE
|
||||
|
||||
arch_config.save(test_out_dir)
|
||||
|
||||
result = json.loads(test_out_file.read_text())
|
||||
expected = json.loads(config_fixture.read_text())
|
||||
|
||||
# the parsed config will check if the given device exists otherwise
|
||||
# it will ignore the modification; as this test will run on various local systems
|
||||
# and the CI pipeline there's no good way specify a real device so we'll simply
|
||||
# copy the expected result to the actual result
|
||||
result['disk_config']['config_type'] = expected['disk_config']['config_type']
|
||||
result['disk_config']['device_modifications'] = expected['disk_config']['device_modifications']
|
||||
|
||||
assert json.dumps(
|
||||
result['mirror_config'],
|
||||
sort_keys=True,
|
||||
) == json.dumps(
|
||||
expected['mirror_config'],
|
||||
sort_keys=True,
|
||||
)
|
||||
|
||||
|
||||
def test_creds_roundtrip(
|
||||
monkeypatch: MonkeyPatch,
|
||||
creds_fixture: Path,
|
||||
) -> None:
|
||||
monkeypatch.setattr('sys.argv', ['archinstall', '--creds', str(creds_fixture)])
|
||||
|
||||
handler = ArchConfigHandler()
|
||||
arch_config = handler.config
|
||||
|
||||
test_out_dir = Path('/tmp/')
|
||||
test_out_file = test_out_dir / USER_CREDS_FILE
|
||||
|
||||
arch_config.save(test_out_dir, creds=True)
|
||||
|
||||
result = json.loads(test_out_file.read_text())
|
||||
expected = json.loads(creds_fixture.read_text())
|
||||
|
||||
assert sorted(result.items()) == sorted(expected.items())
|
||||
Loading…
Reference in New Issue