parent
151916a7f7
commit
0d2e282093
|
|
@ -1,6 +1,6 @@
|
||||||
import inspect
|
import inspect
|
||||||
from functools import wraps
|
from collections.abc import Callable
|
||||||
from typing import override
|
from typing import Any, override
|
||||||
|
|
||||||
from archinstall.default_profiles.profile import GreeterType
|
from archinstall.default_profiles.profile import GreeterType
|
||||||
from archinstall.lib.applications.application_menu import ApplicationMenu
|
from archinstall.lib.applications.application_menu import ApplicationMenu
|
||||||
|
|
@ -80,6 +80,7 @@ class GlobalMenu(AbstractMenu[None]):
|
||||||
return '[bold green][✓][/bold green] '
|
return '[bold green][✓][/bold green] '
|
||||||
return '[bold red][!][/bold red] '
|
return '[bold red][!][/bold red] '
|
||||||
|
|
||||||
|
# Standard mandatory or configured item check
|
||||||
if item.has_value():
|
if item.has_value():
|
||||||
return '[bold green][✓][/bold green] '
|
return '[bold green][✓][/bold green] '
|
||||||
elif item.mandatory:
|
elif item.mandatory:
|
||||||
|
|
@ -100,24 +101,22 @@ class GlobalMenu(AbstractMenu[None]):
|
||||||
prefix = self._get_status_prefix(item)
|
prefix = self._get_status_prefix(item)
|
||||||
item.text = f'{prefix}{base_title}'
|
item.text = f'{prefix}{base_title}'
|
||||||
|
|
||||||
def _wrap_action(item_dictionary, update_callback, key, action):
|
def _wrap_action(self, key: str, action: Callable[..., Any]) -> Callable[..., Any]:
|
||||||
@wraps(action)
|
async def wrapper(*args, **kwargs) -> Any:
|
||||||
async def wrapper(*args, **kwargs):
|
if inspect.iscoroutinefunction(action):
|
||||||
try:
|
result = await action(*args, **kwargs)
|
||||||
if inspect.iscoroutinefunction(action):
|
else:
|
||||||
result = await action(*args, **kwargs)
|
result = action(*args, **kwargs)
|
||||||
else:
|
if inspect.isawaitable(result):
|
||||||
result = action(*args, **kwargs)
|
result = await result
|
||||||
if inspect.isawaitable(result):
|
|
||||||
result = await result
|
|
||||||
|
|
||||||
if key in item_dictionary:
|
item = self._item_group.find_by_key(key)
|
||||||
item_dictionary[key].value = result
|
if item:
|
||||||
|
item.value = result
|
||||||
|
|
||||||
return result
|
self._update_item_labels()
|
||||||
|
|
||||||
finally:
|
return result
|
||||||
update_callback()
|
|
||||||
|
|
||||||
return wrapper
|
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